diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1528,7 +1528,7 @@ _LIBCPP_INLINE_VISIBILITY size_type __align_it(size_type __s) _NOEXCEPT {return (__s + (__a-1)) & ~(__a-1);} - enum {__alignment = 16, __min_long_capacity = 32 }; + enum {__alignment = 16}; static _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __s) _NOEXCEPT { @@ -1538,12 +1538,6 @@ if (__guess == __min_cap) ++__guess; return __guess; } - static _LIBCPP_INLINE_VISIBILITY size_type - __recommend_cap(size_type __cap) _NOEXCEPT { - return __align_it < sizeof(value_type) < __alignment - ? __alignment / sizeof(value_type) - : 1 > (__cap); - } inline void __init(const value_type* __s, size_type __sz, size_type __reserve); @@ -1668,29 +1662,13 @@ basic_string& __assign_external(const value_type* __s); basic_string& __assign_external(const value_type* __s, size_type __n); - template - value_type* __resize(size_type __n); - - inline value_type* __resize(size_type __n) { - return __is_long() ? __resize(__n) : __resize(__n); - } - - inline value_type* __resize_small(size_type __n) _NOEXCEPT { + // Assigns the value in __s, guaranteed to be __n < __min_cap in length. + inline basic_string& __assign_short(const value_type* __s, size_type __n) { pointer __p = __is_long() ? (__set_long_size(__n), __get_long_pointer()) : (__set_short_size(__n), __get_short_pointer()); + traits_type::move(_VSTD::__to_address(__p), __s, __n); traits_type::assign(__p[__n], value_type()); - return _VSTD::__to_address(__p); - } - - inline basic_string& __assign_small_length(const value_type* __s, - size_type __n) { - value_type* p = (__n < __min_cap) ? __resize_small(__n) : __resize(__n); - if (__builtin_constant_p(*__s)) { - traits_type::copy(p, __s, __n); - } else { - traits_type::move(p, __s, __n); - } return *this; } @@ -2253,39 +2231,6 @@ traits_type::assign(__p[__old_sz], value_type()); } -template -template -_CharT* basic_string<_CharT, _Traits, _Allocator>::__resize(size_type __n) { - size_type __old_cap = __is_short ? __min_cap : __get_long_cap(); - pointer __old_p = __is_short ? __get_short_pointer() : __get_long_pointer(); - if (__n < __old_cap) { - __is_short ? __set_short_size(__n) : __set_long_size(__n); - return _VSTD::__to_address(__old_p); - } - - const size_type __ms = max_size(); - if (__n > __ms) this->__throw_length_error(); - - size_type __new_cap; - if (__is_short) { - __new_cap = __recommend_cap(_VSTD::max( - __n + 1, __min_long_capacity / sizeof(value_type))); - } else { - __new_cap = (__old_cap < __ms / 2 - __alignment) - ? __recommend_cap(_VSTD::max(__n + 1, 2 * __old_cap)) - : __ms; - } - pointer __p = __alloc_traits::allocate(__alloc(), __new_cap); - __invalidate_all_iterators(); - __set_long_pointer(__p); - __is_short ? __set_short_size(__n) : __set_long_size(__n); - __set_long_cap(__new_cap); - if (!__is_short) { - __alloc_traits::deallocate(__alloc(), __old_p, __old_cap); - } - return __p; -} - template void basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, @@ -2358,8 +2303,8 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); - return (__builtin_constant_p(__n) && __n <= 128 / sizeof(value_type)) - ? __assign_small_length(__s, __n) + return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap) + ? __assign_short(__s, __n) : __assign_external(__s, __n); } @@ -2556,8 +2501,8 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) { _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); - return (__builtin_constant_p(*__s) && traits_type::length(__s) <= 128) - ? __assign_small_length(__s, traits_type::length(__s)) + return (_LIBCPP_BUILTIN_CONSTANT_P(*__s) && traits_type::length(__s) <= 128) + ? __assign_short(__s, traits_type::length(__s)) : __assign_external(__s); } // append