[libcxx-commits] [libcxx] [libc++][NFC] Simplify the implementation of reserve() and shrink_to_fit() (PR #113453)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 23 11:00:20 PDT 2024
================
@@ -3340,7 +3353,16 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re
if (__target_capacity == capacity())
----------------
ldionne wrote:
Above, `size_type __target_capacity = std::max(__requested_capacity, size());` can be simplified to just `size_type __target_capacity = __requested_capacity;` since at that point we know for sure that the requested capacity is greater than our current capacity (that's line 3349 above).
And similarly, the `if (__target_capacity == capacity())` can be removed entirely, since we know that we are requesting more than our current capacity.
To do this refactoring, let's add a `_LIBCPP_ASSERT_INTERNAL` to `__recommend(__n)` that the value we return is always `>= __n`.
https://github.com/llvm/llvm-project/pull/113453
More information about the libcxx-commits
mailing list