Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,16 @@ private:
return __guess;
}

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend_growing(size_type __required_size) {
size_type __max_size = max_size();
if (__required_size > __max_size)
__throw_length_error();
size_type __current_cap = capacity();
if (__current_cap > __max_size / 2 - __alignment)
return __max_size;
return std::max(__required_size, 2 * __current_cap);
}

inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(const value_type* __s, size_type __sz);
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(size_type __n, value_type __c);

Expand Down Expand Up @@ -2701,15 +2711,10 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
size_type __n_del,
size_type __n_add,
const value_type* __p_new_stuff) {
size_type __ms = max_size();
if (__delta_cap > __ms - __old_cap)
__throw_length_error();
__long __buffer = __allocate_long_buffer(__alloc_, __recommend_growing(__old_cap + __delta_cap));
pointer __old_p = __get_pointer();
size_type __cap =
__old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
__annotate_delete();
auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
__long __buffer = __allocate_long_buffer(__alloc_, __cap);
if (__n_copy != 0)
traits_type::copy(std::__to_address(__buffer.__data_), std::__to_address(__old_p), __n_copy);
if (__n_add != 0)
Expand Down Expand Up @@ -2739,13 +2744,8 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
size_type __n_copy,
size_type __n_del,
size_type __n_add) {
size_type __ms = max_size();
if (__delta_cap > __ms - __old_cap)
this->__throw_length_error();
__long __buffer = __allocate_long_buffer(__alloc_, __recommend_growing(__old_cap + __delta_cap));
pointer __old_p = __get_pointer();
size_type __cap =
__old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
__long __buffer = __allocate_long_buffer(__alloc_, __cap);
if (__n_copy != 0)
traits_type::copy(std::__to_address(__buffer.__data_), std::__to_address(__old_p), __n_copy);
size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
Expand Down
Loading