[libcxx-commits] [libcxx] [libc++] Optimize basic_string::operator= (PR #224535)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 18 00:08:02 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  -- libcxx/include/string --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/string b/libcxx/include/string
index afb83531a..f9a93e4b1 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -2729,7 +2729,7 @@ template <class _CharT, class _Traits, class _Allocator>
 template <bool __is_short>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE void
 basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(const value_type* __s, size_type __n) {
-  const auto __cap  = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
+  const auto __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
   if (__n >= __cap) {
     return [] [[__gnu__::__noinline__]] (basic_string& __self, const value_type* __ls, size_type __ln) static {
       std::__assume(__self.__is_long() == !__is_short);
@@ -2839,8 +2839,8 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
   __copy_assign_alloc(__str);
 
   if (__is_long()) {
-     __assign_no_alias<false>(__str.data(), __str.size());
-     return *this;
+    __assign_no_alias<false>(__str.data(), __str.size());
+    return *this;
   }
 
   if (__str.__is_long()) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/224535


More information about the libcxx-commits mailing list