Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::size over sizeof/sizeof #3090

Merged
merged 3 commits into from
Sep 13, 2022
Merged

Conversation

AreaZR
Copy link
Contributor

@AreaZR AreaZR commented Sep 8, 2022

This is more concise than sizeof/sizeof, and std::size is a constexpr so there shouldn't be any cost.

This is more concise than sizeof/sizeof, and std::size is a constexpr so there shouldn't be any cost.
@AreaZR AreaZR requested a review from a team as a code owner September 8, 2022 14:28
stl/src/xsinh.cpp Show resolved Hide resolved
stl/src/xdateord.cpp Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

Thanks - agreed that this is an improvement, and that there's no cost in release mode. (I'm not worried about minor consequences in debug mode.) I've pushed a pre-emptive fix for the MSVC-internal build, plus additional changes to update occurrences in stl/inc.

@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Sep 9, 2022
@StephanTLavavej StephanTLavavej self-assigned this Sep 12, 2022
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

Copy link
Member

@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.

I'm not concerned with the change since none of these uses are performance-critical, but note that this change can in general pessimize debug codegen. MSVC is quite reluctant to evaluate constant expressions that are not manifestly constant (used in a context that requires a constant expression) at compiletime when not optimizing. See https://godbolt.org/z/74eEe98zP for a demonstration.

Again, I'm happy to apply this, but keep in mind if you submit future similar PRs that we may need to sometimes force constant evaluation to avoid pessimizing codegen when adding calls to constexpr functions.

@StephanTLavavej StephanTLavavej merged commit 731b122 into microsoft:main Sep 13, 2022
@StephanTLavavej
Copy link
Member

Thanks for this code cleanup! 😸 😸 😸 😸 😸 😸

@AreaZR AreaZR deleted the std-size branch September 26, 2022 16:07
CaseyCarter pushed a commit to CaseyCarter/STL that referenced this pull request Oct 6, 2022
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants