[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


================
@@ -2820,17 +2817,10 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
 template <class _CharT, class _Traits, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) {
-  pointer __p;
   size_type __old_size = size();
   if (__old_size == 0)
     __annotate_increase(1);
-  if (__is_long()) {
-    __p = __get_long_pointer();
-    __set_long_size(1);
-  } else {
-    __p = __get_short_pointer();
-    __set_short_size(1);
-  }
+  pointer __p = __is_long() ? (__set_long_size(1), __get_long_pointer()) : (__set_short_size(1), __get_short_pointer());
----------------
philnik777 wrote:

Same here. IMO this is absolutely horrific code. The previous code was way easier to follow.

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


More information about the libcxx-commits mailing list