From 0fc6d42ea728babc10c3072aef72c7d723f34783 Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Fri, 9 Feb 2024 23:20:11 +0100 Subject: [PATCH] added finish and clear to benchmark --- CMakeLists.txt | 2 +- benchmarks/bitset.cpp | 3 ++- include/flatmemory/details/types/vector.hpp | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f6ee28..3dd3f23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ else() set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -g3 -ggdb") endif() -# set(CMAKE_BUILD_TYPE "Release") +set(CMAKE_BUILD_TYPE "Release") message(STATUS "Build configuration: ${CMAKE_BUILD_TYPE}") diff --git a/benchmarks/bitset.cpp b/benchmarks/bitset.cpp index 10faa6d..ebde1e0 100644 --- a/benchmarks/bitset.cpp +++ b/benchmarks/bitset.cpp @@ -79,9 +79,10 @@ namespace flatmemory::benchmarks VariableSizedTypeVector> views; auto builder = Builder>(); builder.get_blocks().resize(bitset_size); - builder.finish(); for (size_t i = 0; i < num_bitsets; ++i) { + builder.finish(); views.push_back(builder); + builder.clear(); } return views; } diff --git a/include/flatmemory/details/types/vector.hpp b/include/flatmemory/details/types/vector.hpp index 523226d..19d0d7d 100644 --- a/include/flatmemory/details/types/vector.hpp +++ b/include/flatmemory/details/types/vector.hpp @@ -131,15 +131,17 @@ namespace flatmemory /* clear stl */ void clear_impl() { // Clear all nested builders. - for (auto& builder : m_data) { - builder.clear(); + constexpr bool is_trivial = IsTriviallyCopyable; + if constexpr (!is_trivial) { + for (auto& builder : m_data) { + builder.clear(); + } } // Clear this builder. m_buffer.clear(); m_dynamic_buffer.clear(); } - [[nodiscard]] ByteStream& get_buffer_impl() { return m_buffer; } [[nodiscard]] const ByteStream& get_buffer_impl() const { return m_buffer; }