[libcxx-commits] [libcxx] [libc++] Optimize vector::emplace_back slow path (PR #222016)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 8 07:46:44 PDT 2026
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 origin/main HEAD --extensions h -- libcxx/include/__numeric/saturation_arithmetic.h libcxx/include/__vector/vector.h --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index c6b422e99..6910b5682 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -890,7 +890,7 @@ vector<_Tp, _Allocator>::__recommend(size_type __new_size) const {
if (__new_size > __ms)
this->__throw_length_error();
const size_type __cap = capacity();
- auto __doubled = std::__saturating_add(__cap, __cap);
+ auto __doubled = std::__saturating_add(__cap, __cap);
return std::min(std::max(__new_size, __doubled), __ms);
}
@@ -1076,10 +1076,7 @@ vector<_Tp, _Alloc>::emplace_back(_Args&&... __args) {
__alloc_traits::construct(__alloc, __ptr + __size, std::forward<_Args>(__largs)...);
auto __guard = std::__make_exception_guard([&] { __alloc_traits::destroy(__alloc, __ptr + __size); });
std::__uninitialized_allocator_relocate(
- __alloc,
- std::__to_address(__old_begin),
- std::__to_address(__self.__layout_.__end_ptr()),
- __ptr);
+ __alloc, std::__to_address(__old_begin), std::__to_address(__self.__layout_.__end_ptr()), __ptr);
__guard.__complete();
__self.__layout_.__set_layout(__allocation.ptr, __size + 1, __allocation.count);
if ((__is_std_allocator_v<allocator_type> && !__libcpp_is_constant_evaluated()) || __old_begin)
``````````
</details>
https://github.com/llvm/llvm-project/pull/222016
More information about the libcxx-commits
mailing list