[libcxx-commits] [libcxx] [libc++] Optimize vector::erase (PR #213916)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 17 11:51:46 PDT 2026
================
@@ -552,8 +553,32 @@ class _LIBCPP_WARN_UNUSED vector {
}
#endif
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) {
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ __position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator");
+ return erase(__position, __position + 1);
+ }
+
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
+ _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range");
+ pointer __pos = this->__layout_.__begin_ptr() + (__first - begin());
+ auto __hole_size = __last - __first;
+ if (__first != __last) {
+#ifndef _LIBCPP_CXX03_LANG
+ if constexpr (__is_nothrow_relocatable_v<value_type> &&
----------------
philnik777 wrote:
I couldn't salvage too much of the comment unfortunately, since the optimization is somewhat gutted due to the standard being overspecified.
https://github.com/llvm/llvm-project/pull/213916
More information about the libcxx-commits
mailing list