Remove dead store to _Count in _Sort_unchecked and other cleanups#449
Merged
BillyONeal merged 2 commits intomicrosoft:masterfrom Jan 25, 2020
Merged
Conversation
…were forced to initialize in the constexpr algorithms review by eliminating the variable entirely. * Consistently test _ISORT_MAX with <=, and make that an _INLINE_VAR constexpr variable. * Remove _Count guards of 1 in front of _Insertion_sort_unchecked for consistency. I did performance testing and there was no measurable difference in keeping this check, and it's more code to reason about. * Avoid needless casts of _ISORT_MAX given that it is now a constexpr constant.
BillyONeal
commented
Jan 24, 2020
CaseyCarter
suggested changes
Jan 24, 2020
CaseyCarter
approved these changes
Jan 24, 2020
StephanTLavavej
approved these changes
Jan 25, 2020
| return; | ||
| } | ||
|
|
||
| if (_Ideal <= 0) { // heap sort if too many divisions |
Member
There was a problem hiding this comment.
I observe that _Ideal should never be negative. It's initially _ULast - _UFirst (non-negative) and then decreases via _Ideal = (_Ideal >> 1) + (_Ideal >> 2). Perhaps an _STL_INTERNAL_CHECK for negative, and an exact == 0 test otherwise? However, there's probably no codegen difference in practice, so I don't really care.
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

In GH-425 I was forced to add a dead initialization for the _Count variable in _Sort_unchecked in order to comply with constexpr rules. Also, _Sort_unchecked had somewhat complex assignment-in-conditional-expressions going on. This change moves the code around such that the _Count variable is assigned once.
Also:
Checklist
Be sure you've read README.md and understand the scope of this repo.
If you're unsure about a box, leave it unchecked. A maintainer will help you.
_Uglyas perhttps://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
verified by an STL maintainer before automated testing is enabled on GitHub,
leave this unchecked for initial submission).
members, adding virtual functions, changing whether a type is an aggregate
or trivially copyable, etc.).
the C++ Working Draft (including any cited standards), other WG21 papers
(excluding reference implementations outside of proposed standard wording),
and LWG issues as reference material. If they were derived from a project
that's already listed in NOTICE.txt, that's fine, but please mention it.
If they were derived from any other project (including Boost and libc++,
which are not yet listed in NOTICE.txt), you must mention it here,
so we can determine whether the license is compatible and what else needs
to be done.