Skip to content

Commit b8f9063

Browse files
authored
[libc++] Simplify string::reserve (#114869)
We're checking quite a few things that are either trivially true or trivially false. These cases became trivial when we changed `reserve()` to never shrink.
1 parent 877cb9a commit b8f9063

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

libcxx/include/string

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,8 @@ private:
20832083
size_type __guess = __align_it<__boundary>(__s + 1) - 1;
20842084
if (__guess == __min_cap)
20852085
__guess += __endian_factor;
2086+
2087+
_LIBCPP_ASSERT_INTERNAL(__guess >= __s, "recommendation is below the requested size");
20862088
return __guess;
20872089
}
20882090

@@ -3346,12 +3348,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re
33463348
if (__requested_capacity <= capacity())
33473349
return;
33483350

3349-
size_type __target_capacity = std::max(__requested_capacity, size());
3350-
__target_capacity = __recommend(__target_capacity);
3351-
if (__target_capacity == capacity())
3352-
return;
3353-
3354-
__shrink_or_extend(__target_capacity);
3351+
__shrink_or_extend(__recommend(__requested_capacity));
33553352
}
33563353

33573354
template <class _CharT, class _Traits, class _Allocator>

0 commit comments

Comments
 (0)