Skip to content

[libc++] Optimize __hash_table copy constructors and assignment #151951

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

philnik777
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented Aug 4, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions ,cpp -- libcxx/include/__hash_table libcxx/include/unordered_map libcxx/include/unordered_set libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy_alloc.pass.cpp
View the diff from clang-format here.
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index e25d113dc..8bce518ca 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -1095,7 +1095,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __oth
     return;
 
   auto& __bucket_list_del = __bucket_list_.get_deleter();
-  auto __bucket_count = __other.bucket_count();
+  auto __bucket_count     = __other.bucket_count();
   __bucket_list_.reset(__pointer_alloc_traits::allocate(__bucket_list_del.__alloc(), __bucket_count));
   __bucket_list_del.size() = __bucket_count;
 
@@ -1207,7 +1207,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __other)
   }
 
   __next_pointer __other_iter = __other.__first_node_.__next_;
-  __next_pointer __own_iter = __first_node_.__ptr();
+  __next_pointer __own_iter   = __first_node_.__ptr();
   {
     __node_pointer __next = __own_iter->__next_->__upcast();
     __assign_value(__next->__get_value(), __other_iter->__upcast()->__get_value());
@@ -1215,8 +1215,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __other)
   }
   size_t __current_chash          = std::__constrain_hash(__own_iter->__next_->__hash(), __bucket_count);
   __bucket_list_[__current_chash] = __own_iter;
-  __other_iter = __other_iter->__next_;
-  __own_iter = __own_iter->__next_;
+  __other_iter                    = __other_iter->__next_;
+  __own_iter                      = __own_iter->__next_;
 
   while (__other_iter && __own_iter->__next_) {
     __node_pointer __next = __own_iter->__next_->__upcast();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant