Skip to content

Commit

Permalink
Merge pull request #25686 from vespa-engine/balder/less-code
Browse files Browse the repository at this point in the history
Use const ref to reduce code bloat.
  • Loading branch information
baldersheim authored Jan 23, 2023
2 parents 41a99bc + 581b904 commit 0137c3f
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <vespa/vespalib/test/datastore/buffer_stats.h>
#include <vespa/vespalib/test/insertion_operators.h>
#include <vespa/vespalib/test/memory_allocator_observer.h>
#include <vespa/vespalib/util/traits.h>
#include <vector>

using namespace vespalib::datastore;
Expand All @@ -29,12 +28,12 @@ template <typename RefT = EntryRefT<22>>
struct TestBase : public ::testing::Test {
using EntryRefType = RefT;

AllocStats stats;
AllocStats allocStats;
UniqueStoreStringAllocator<EntryRefType> allocator;
generation_t generation;
TestBase()
: stats(),
allocator(std::make_unique<MemoryAllocatorObserver>(stats)),
: allocStats(),
allocator(std::make_unique<MemoryAllocatorObserver>(allocStats)),
generation(1)
{}
void assert_add(const char *input) {
Expand All @@ -61,11 +60,12 @@ struct TestBase : public ::testing::Test {
return allocator.get_data_store().getBufferState(get_buffer_id(ref));
}
void assert_buffer_state(EntryRef ref, const TestBufferStats expStats) const {
const auto & stats = buffer_state(ref).stats();
EXPECT_EQ(expStats._used, buffer_state(ref).size());
EXPECT_EQ(expStats._hold, buffer_state(ref).stats().hold_elems());
EXPECT_EQ(expStats._dead, buffer_state(ref).stats().dead_elems());
EXPECT_EQ(expStats._extra_used, buffer_state(ref).stats().extra_used_bytes());
EXPECT_EQ(expStats._extra_hold, buffer_state(ref).stats().extra_hold_bytes());
EXPECT_EQ(expStats._hold, stats.hold_elems());
EXPECT_EQ(expStats._dead, stats.dead_elems());
EXPECT_EQ(expStats._extra_used, stats.extra_used_bytes());
EXPECT_EQ(expStats._extra_hold, stats.extra_hold_bytes());
}
void reclaim_memory() {
allocator.get_data_store().assign_generation(generation++);
Expand Down Expand Up @@ -179,7 +179,7 @@ TEST_F(StringTest, free_list_is_never_used_for_move_on_compact)

TEST_F(StringTest, provided_memory_allocator_is_used)
{
EXPECT_EQ(AllocStats(18, 0), stats);
EXPECT_EQ(AllocStats(18, 0), allocStats);
}

TEST_F(SmallOffsetStringTest, new_underlying_buffer_is_allocated_when_current_is_full)
Expand All @@ -196,7 +196,7 @@ TEST_F(SmallOffsetStringTest, new_underlying_buffer_is_allocated_when_current_is
uint32_t buffer_id = get_buffer_id(add(small.c_str()));
EXPECT_EQ(second_buffer_id, buffer_id);
}
EXPECT_LT(18, stats.alloc_cnt);
EXPECT_LT(18, allocStats.alloc_cnt);
}

GTEST_MAIN_RUN_ALL_TESTS()

0 comments on commit 0137c3f

Please sign in to comment.