[libcxx-commits] [libcxx] [libc++][NFC] Simplify string a bit (PR #127135)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sun Feb 16 01:52:46 PST 2025


================
@@ -2758,38 +2758,36 @@ template <class _CharT, class _Traits, class _Allocator>
 template <bool __is_short>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(const value_type* __s, size_type __n) {
-  size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
-  if (__n < __cap) {
-    size_type __old_size = __is_short ? __get_short_size() : __get_long_size();
+  size_type __cap      = capacity();
+  size_type __old_size = size();
----------------
philnik777 wrote:

This looks suspiciously like it's written to make sure the compiler optimizes this properly. I don't think we should change this kind of thing in an NFC patch.

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


More information about the libcxx-commits mailing list