[libcxx-commits] [libcxx] [libc++] Optimize __hash_table copy constructors and assignment (PR #151951)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 4 05:28:28 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
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
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/151951
More information about the libcxx-commits
mailing list