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

type_index::operator<=> should not call the comparison function twice #3600

Merged
merged 1 commit into from
Apr 7, 2023

Conversation

frederick-vs-ja
Copy link
Contributor

Currently, when two referenced type_info are not equal, type_index::operator<=> needs to call __std_type_info_compare twice (both in type_info::operator== and type_info::before) to determine the relative order.

I think we can optimize type_index::operator<=> by calling the comparison function at most once. However, it is currently necessary to touch the implementation details of type_info and __std_type_info_compare in VCRuntime. This PR is essentially mirroring the implementation of __std_type_info_compare now.

I've filed DevCom-10326599 to request a stable interface for ordering.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner March 30, 2023 03:27
stl/inc/typeindex Show resolved Hide resolved
@StephanTLavavej StephanTLavavej added the performance Must go faster label Mar 30, 2023
return strong_ordering::equal;
}

return _CSTD strcmp(_Tptr->raw_name() + 1, _Right._Tptr->raw_name() + 1) <=> 0;
Copy link
Member

Choose a reason for hiding this comment

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

No change requested, note to final reviewer: This raw_name() + 1 looks like 5 squirrels out of 5 🐿️ but it's exactly the correct technique.

  • __std_type_info_compare() in std_type_info.cpp (internal link) compares strcmp(lhs->_DecoratedName + 1, rhs->_DecoratedName + 1).
  • type_info::raw_name() in vcruntime_typeinfo.h (internal link) says return _Data._DecoratedName;.
  • The character at index 0 appears to be a dot; I'm not sure why that's stored, or why raw_name() exposes this, but the implementation here is correct.

@StephanTLavavej
Copy link
Member

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

@StephanTLavavej StephanTLavavej merged commit 0461a50 into microsoft:main Apr 7, 2023
@StephanTLavavej
Copy link
Member

🛸 😸 🛸

@frederick-vs-ja frederick-vs-ja deleted the type_index-3way branch April 8, 2023 05:18
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.

3 participants