[libcxx-commits] [libcxx] [libc++][NFC] Simplify string a bit (PR #127135)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 20 08:48:53 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());
----------------
winner245 wrote:
Thanks for the feedback. I followed the existing pattern in `<string>`, assuming it was an acceptable style. However, I appreciate your clarification that this isn’t a good approach for libc++. Thus, I’ve updated the code—both my changes and the existing instances in the codebase—to use a standard if/else statement instead of this pattern.
https://github.com/llvm/llvm-project/pull/127135
More information about the libcxx-commits
mailing list