[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();
+ if (__n <= __cap) {
if (__n > __old_size)
__annotate_increase(__n - __old_size);
- pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
- __is_short ? __set_short_size(__n) : __set_long_size(__n);
+ pointer __p =
+ __is_short ? (__set_short_size(__n), __get_short_pointer()) : (__set_long_size(__n), __get_long_pointer());
----------------
philnik777 wrote:
This is some absolutely horrific code IMO. We should really not use `operator,` like this. It makes the code much harder to understand, since side effects happen in places you don't expect. I'm aware that there is some precedent in `<string>` for this, but IMO it would be much better to remove that precedent than expand it.
https://github.com/llvm/llvm-project/pull/127135
More information about the libcxx-commits
mailing list