================ @@ -428,50 +653,60 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::shrink_to_fi } } -template <class _Tp, class _Allocator> +template <class _Tp, class _Allocator, template <class, class, class> class _Layout> template <class... _Args> -_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::emplace_front(_Args&&... __args) { - if (__begin_ == __first_) { - if (__end_ < __cap_) { - difference_type __d = __cap_ - __end_; +_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator, _Layout>::emplace_front(_Args&&... __args) { + if (__front_spare() == 0) { + pointer __end = end(); + if (__back_spare() > 0) { + // The elements are pressed up against the front of the buffer: we need to move them back a + // little bit to make `emplace_front` have amortised O(1) complexity. + difference_type __d = __back_spare(); __d = (__d + 1) / 2; - __begin_ = std::move_backward(__begin_, __end_, __end_ + __d); - __end_ += __d; + __set_begin(std::move_backward(begin(), __end, __end + __d)); + + // `begin()` was moved further into the buffer, so we need to update the pointer-based + // layout's end with it. We don't need to do anything for the size-based layout here, because + // the number of elements hasn't changed yet. + __set_size_if_pointer_based(__d); ---------------- cjdb wrote:
Done. I'm still trying to understand why this change is a valid alternative, though. https://github.com/llvm/llvm-project/pull/139632 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits