[libcxx-commits] [libcxx] b8f9063 - [libc++] Simplify string::reserve (#114869)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 5 07:05:13 PST 2024
Author: Nikolas Klauser
Date: 2024-11-05T16:05:08+01:00
New Revision: b8f9063ae9ca82a93fc9ea1365362926c92cc0ca
URL: https://github.com/llvm/llvm-project/commit/b8f9063ae9ca82a93fc9ea1365362926c92cc0ca
DIFF: https://github.com/llvm/llvm-project/commit/b8f9063ae9ca82a93fc9ea1365362926c92cc0ca.diff
LOG: [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.
Added:
Modified:
libcxx/include/string
Removed:
################################################################################
diff --git a/libcxx/include/string b/libcxx/include/string
index 20e44eaca2ac7a..e4b2d7a8d964c1 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -2083,6 +2083,8 @@ private:
size_type __guess = __align_it<__boundary>(__s + 1) - 1;
if (__guess == __min_cap)
__guess += __endian_factor;
+
+ _LIBCPP_ASSERT_INTERNAL(__guess >= __s, "recommendation is below the requested size");
return __guess;
}
@@ -3346,12 +3348,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re
if (__requested_capacity <= capacity())
return;
- size_type __target_capacity = std::max(__requested_capacity, size());
- __target_capacity = __recommend(__target_capacity);
- if (__target_capacity == capacity())
- return;
-
- __shrink_or_extend(__target_capacity);
+ __shrink_or_extend(__recommend(__requested_capacity));
}
template <class _CharT, class _Traits, class _Allocator>
More information about the libcxx-commits
mailing list