From d4f7b4114bdaf5e9889686e77e9bc2d9c0aa588c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Sat, 30 Mar 2024 23:30:06 +0300 Subject: [PATCH] =?UTF-8?q?mdbx++:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20`buffer::clear=5Fand=5Freserve()`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdbx.h++ | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mdbx.h++ b/mdbx.h++ index e8a58bfe..8ef9b44b 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -1907,7 +1907,6 @@ private: const size_t old_capacity = bin_.capacity(); const size_t new_capacity = bin::advise_capacity(old_capacity, wanna_capacity); - assert(new_capacity >= wanna_capacity); if (MDBX_LIKELY(new_capacity == old_capacity)) MDBX_CXX20_LIKELY { assert(bin_.is_inplace() == @@ -2073,7 +2072,13 @@ private: return *this; } - MDBX_CXX20_CONSTEXPR void clear() { reshape(0, 0, nullptr, 0); } + MDBX_CXX20_CONSTEXPR void *clear() { + return reshape(0, 0, nullptr, 0); + } + MDBX_CXX20_CONSTEXPR void *clear_and_reserve(size_t whole_capacity, + size_t headroom) { + return reshape(whole_capacity, headroom, nullptr, 0); + } MDBX_CXX20_CONSTEXPR void resize(size_t capacity, size_t headroom, slice &content) { content.iov_base = @@ -2803,9 +2808,11 @@ public: } /// \brief Clears the contents and storage. - void clear() noexcept { - slice_.clear(); - silo_.clear(); + void clear() noexcept { slice_.assign(silo_.clear(), size_t(0)); } + + /// \brief Clears the contents and reserve storage. + void clear_and_reserve(size_t whole_capacity, size_t headroom = 0) noexcept { + slice_.assign(silo_.clear_and_reserve(whole_capacity, headroom), size_t(0)); } /// \brief Reduces memory usage by freeing unused storage space.