Skip to content

Conversation

@AdamBucior
Copy link
Contributor

@AdamBucior AdamBucior commented Sep 5, 2020

Another small PR to optimize (ranges::)(uninitialized_)fill(_n). I applied the optimization only to the _HAS_IF_CONSTEXPR branch because without if constexpr it becomes very tricky to implement and I don't know how long the !_HAS_IF_CONSTEXPR branch will live. Part of #431.

@AdamBucior AdamBucior requested a review from a team as a code owner September 5, 2020 10:56
@StephanTLavavej
Copy link
Member

I pushed a merge to uninitialized_fill_n() in <memory> - it needed a bit of manual surgery, and I think I got it right, but please double-check.

@AdamBucior
Copy link
Contributor Author

I pushed a merge to uninitialized_fill_n() in <memory> - it needed a bit of manual surgery, and I think I got it right, but please double-check.

Looks good

Co-authored-by: Casey Carter <cartec69@gmail.com>
Copy link
Contributor

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the extra test coverage.

@CaseyCarter CaseyCarter removed their assignment Oct 3, 2020
@StephanTLavavej StephanTLavavej self-assigned this Oct 7, 2020
Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this optimization! I found one bug involving floating-point negative zero, but otherwise this looks very solid.

@StephanTLavavej StephanTLavavej removed their assignment Oct 28, 2020
AdamBucior and others added 2 commits October 28, 2020 09:01
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
@StephanTLavavej StephanTLavavej self-assigned this Oct 28, 2020
`static_cast<_Ty>(0)` emits this warning for object pointers, function
pointers, and `nullptr_t`. We can avoid this warning by using empty
braces to request zero-initialization.
@StephanTLavavej
Copy link
Member

Looks great! I've pushed three small changes (FYI @CaseyCarter) and merged with master (without conflicts), so I can add your PR to today's batch for merging.

  • Avoid Clang's -Wzero-as-null-pointer-constant warning.
    • static_cast<_Ty>(0) emits this warning for object pointers, function pointers, and nullptr_t. We can avoid this warning by using empty braces to request zero-initialization.
  • Portably test for negative zero.
    • We conventionally avoid using internal machinery in tests unless it allows something to be tested that would be difficult otherwise. Instead of _Bit_cast, we can use <cmath>'s signbit() to detect negative zero.
  • Test allocate_shared<int[]>.

@StephanTLavavej StephanTLavavej merged commit a27d894 into microsoft:master Oct 29, 2020
@StephanTLavavej
Copy link
Member

Thanks again for this optimization, automatically making user code faster! This will ship in VS 2019 16.9 Preview 2. 🎉

@AdamBucior AdamBucior deleted the fill_zero_optimization branch October 29, 2020 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants