Skip to content

Fix unnecessary self-move-assignments on calling deque erase(x,x) - #1148

Merged
Stephan T. Lavavej (StephanTLavavej) merged 7 commits into
microsoft:masterfrom
Arzaghi:master
Aug 9, 2020
Merged

Fix unnecessary self-move-assignments on calling deque erase(x,x)#1148
Stephan T. Lavavej (StephanTLavavej) merged 7 commits into
microsoft:masterfrom
Arzaghi:master

Conversation

@Arzaghi

Copy link
Copy Markdown
Contributor

Fixes issue #1118
I think it's the simplest method to solve the issue. however, it adds a little bit overhead to the library with an additional IF.
Any better idea?

@miscco

Copy link
Copy Markdown
Contributor

I believe the "conventional" solution would be to simply add

if (_First == _Last) {
    return _First;
}

at the beginning of the function.

@Arzaghi
Hamid Reza Arzaghi (Arzaghi) marked this pull request as ready for review August 4, 2020 20:22
@Arzaghi
Hamid Reza Arzaghi (Arzaghi) requested a review from a team as a code owner August 4, 2020 20:22
@miscco

Copy link
Copy Markdown
Contributor

Also note, that formatting seems to be off. You need to use clang-format 10 with the file setting

@Arzaghi

Copy link
Copy Markdown
Contributor Author

I believe the "conventional" solution would be to simply add

if (_First == _Last) {
    return _First;
}

at the beginning of the function.

It adds an additional IF statement to the code as well. This IF statement will be effective in just a rare call.
It would be perfect if the algorithm handles the rare situation naturally.

Comment thread stl/inc/deque Outdated
Comment thread stl/inc/deque Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

I wonder whether we should have test coverage for this, but we can file a separate issue for that.

Comment thread stl/inc/deque Outdated
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for fixing this bug, and congratulations on your first microsoft/STL commit! 🎉 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<deque>: erase with two iterators invokes move / move_backward when the range is empty

5 participants