[libcxx-commits] [libcxx] [libc++][NFC] Use early returns in a few basic_string functions (PR #137299)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 18 03:58:31 PDT 2025
================
@@ -2776,24 +2778,23 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string<_CharT, _Traits, _Al
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 __size = __is_short ? __get_short_size() : __get_long_size();
- if (__n < __cap) {
- if (__n > __size)
- __annotate_increase(__n - __size);
- pointer __p;
- if (__is_short) {
- __p = __get_short_pointer();
- __set_short_size(__n);
- } else {
- __p = __get_long_pointer();
- __set_long_size(__n);
- }
- traits_type::copy(std::__to_address(__p), __s, __n);
- traits_type::assign(__p[__n], value_type());
- if (__size > __n)
- __annotate_shrink(__size);
- } else {
+ if (__n >= __cap) {
__grow_by_and_replace(__cap - 1, __n - __cap + 1, __size, 0, __size, __n, __s);
+ return *this;
}
+
+ __annotate_delete();
+ auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
----------------
philnik777 wrote:
The asm is identical except for a few label differences.
https://github.com/llvm/llvm-project/pull/137299
More information about the libcxx-commits
mailing list