diff --git a/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp b/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp index 5346cc7f764c..99fdd9f4b0a1 100644 --- a/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp +++ b/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include +#include #include #include @@ -11,6 +12,8 @@ using vespalib::datastore::CompactionStrategy; using vespalib::datastore::EntryRef; using vespalib::datastore::EntryRefFilter; using RefT = vespalib::datastore::EntryRefT<22>; +using vespalib::alloc::test::MemoryAllocatorObserver; +using AllocStats = MemoryAllocatorObserver::Stats; namespace vespalib::datastore { @@ -374,6 +377,13 @@ TEST(EnumStoreTest, address_space_usage_is_reported) EXPECT_EQ(AddressSpace(3, 3, ADDRESS_LIMIT + 2), store.get_values_address_space_usage()); } +TEST(EnumStoreTest, provided_memory_allocator_is_used) +{ + AllocStats stats; + NumericEnumStore ses(false, DictionaryConfig::Type::BTREE, std::make_unique(stats)); + EXPECT_EQ(AllocStats(1, 0), stats); +} + class BatchUpdaterTest : public ::testing::Test { public: NumericEnumStore store; diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.h b/searchlib/src/vespa/searchlib/attribute/enumstore.h index 7fe586b8ccc4..73378311bec8 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumstore.h +++ b/searchlib/src/vespa/searchlib/attribute/enumstore.h @@ -77,6 +77,7 @@ class EnumStoreT : public IEnumStore { std::unique_ptr allocate_optionally_folded_comparator(bool folded) const; ComparatorType make_optionally_folded_comparator(bool folded) const; public: + EnumStoreT(bool has_postings, const search::DictionaryConfig& dict_cfg, std::shared_ptr memory_allocator); EnumStoreT(bool has_postings, const search::DictionaryConfig & dict_cfg); ~EnumStoreT() override; diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp index 5baa7cc9df80..fa0b8977c8a2 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp +++ b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp @@ -72,8 +72,8 @@ EnumStoreT::load_unique_value(const void* src, size_t available, Index& } template -EnumStoreT::EnumStoreT(bool has_postings, const DictionaryConfig & dict_cfg) - : _store({}), +EnumStoreT::EnumStoreT(bool has_postings, const DictionaryConfig& dict_cfg, std::shared_ptr memory_allocator) + : _store(std::move(memory_allocator)), _dict(), _is_folded(dict_cfg.getMatch() == DictionaryConfig::Match::UNCASED), _comparator(_store.get_data_store()), @@ -86,6 +86,12 @@ EnumStoreT::EnumStoreT(bool has_postings, const DictionaryConfig & dict_ _dict = static_cast(&_store.get_dictionary()); } +template +EnumStoreT::EnumStoreT(bool has_postings, const DictionaryConfig& dict_cfg) + : EnumStoreT(has_postings, dict_cfg, {}) +{ +} + template EnumStoreT::~EnumStoreT() = default;