-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[libc++] Optimize __tree::find and __tree::__erase_unique #152370
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
Merged
Merged
Conversation
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
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) Changes
Full diff: https://github.com/llvm/llvm-project/pull/152370.diff 1 Files Affected:
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 6ca1a623536f2..1a3d4afa2d8fc 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -2062,10 +2062,11 @@ template <class _Tp, class _Compare, class _Allocator>
template <class _Key>
typename __tree<_Tp, _Compare, _Allocator>::size_type
__tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) {
- iterator __i = find(__k);
- if (__i == end())
+ __end_node_pointer __parent;
+ __node_base_pointer __i = __find_equal(__parent, __k);
+ if (__i == nullptr)
return 0;
- erase(__i);
+ erase(iterator(static_cast<__node_pointer>(__i)));
return 1;
}
|
ldionne
reviewed
Aug 11, 2025
03855dd
to
e774294
Compare
ldionne
requested changes
Aug 12, 2025
e774294
to
1995180
Compare
ldionne
approved these changes
Aug 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with small comments
1995180
to
fc6edb7
Compare
fc6edb7
to
34e9a72
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
This patch changes
__tree::find
to return when it has found any equal element instead of the lower bound of the equal elements. Formap
andset
there is no observable difference, since the keys are unique. However for theirmulti
versions this can mean a change in behaviour since it's not longer guaranteed thatfind
will return the first element.