[libcxx-commits] [libcxx] [libc++] Simplify string::reserve (PR #114869)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 5 04:54:57 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/114869.diff
1 Files Affected:
- (modified) libcxx/include/string (+3-6)
``````````diff
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>
``````````
</details>
https://github.com/llvm/llvm-project/pull/114869
More information about the libcxx-commits
mailing list