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

<xmemory>: Unify overloads of _Allocate and _Deallocate with if constexpr #4432

Merged
merged 7 commits into from Mar 8, 2024

Conversation

frederick-vs-ja
Copy link
Contributor

Currently, both _Allocate and _Deallocate have multiple overloads that are dispatched by SFINAE.
It seems that we should dispatch overaligned and normal branches with if constexpr instead (see #189).

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner March 2, 2024 15:32
@github-actions github-actions bot added this to Initial Review in Code Reviews Mar 2, 2024
@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Mar 2, 2024
@StephanTLavavej StephanTLavavej self-assigned this Mar 2, 2024
When `_Bytes == 0`, the branch `_Bytes >= _Big_allocation_threshold` will certainly not be taken, so we can perform this transformation.
This transformation has very minor impact. Sometimes, we'll call `is_constant_evaluated` when we would have returned `_Traits::_Allocate(_Bytes)` anyways. (This happens when we don't take the high-`_Align` branch and we aren't x86/x64.) This is an extremely minor cost, and it completely vanishes in release mode. The code simplicity is well worth it.
stl/inc/xmemory Outdated Show resolved Hide resolved
@StephanTLavavej StephanTLavavej removed their assignment Mar 5, 2024
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in Code Reviews Mar 5, 2024
@StephanTLavavej StephanTLavavej self-assigned this Mar 6, 2024
@StephanTLavavej
Copy link
Member

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

@StephanTLavavej
Copy link
Member

I've pushed a merge with main to resolve a trivial adjacent-delete conflict in <xmemory>.

@StephanTLavavej StephanTLavavej merged commit ddc5a62 into microsoft:main Mar 8, 2024
35 checks passed
Code Reviews automation moved this from Ready To Merge to Done Mar 8, 2024
@StephanTLavavej
Copy link
Member

Thanks for this dramatic simplification! All shall love if constexpr and despair! 🧝‍♀️ 👸 💍

@frederick-vs-ja frederick-vs-ja deleted the aligned-branches branch March 8, 2024 02:42
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
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants