Commit 6ab5b0aa by Vitaly Goldshteyn Committed by Copybara-Service

Move `prepare_insert` out of the line as type erased `PrepareInsertNonSoo`.

This significantly reduces binary size of big binaries and creates a single hot function instead of many cold. That is decreasing cash misses during code execution.

We also avoid size related computations for tables with no deleted slots, when resize is necessary.

PiperOrigin-RevId: 635527119
Change-Id: I763b135f1f6089051e62e348a07b33536af265ab
parent 01283057
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
#include "absl/container/internal/compressed_tuple.h" #include "absl/container/internal/compressed_tuple.h"
#include <memory> #include <memory>
#include <set>
#include <string> #include <string>
#include <type_traits>
#include <utility> #include <utility>
#include <vector>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -55,6 +58,7 @@ namespace { ...@@ -55,6 +58,7 @@ namespace {
using absl::test_internal::CopyableMovableInstance; using absl::test_internal::CopyableMovableInstance;
using absl::test_internal::InstanceTracker; using absl::test_internal::InstanceTracker;
using ::testing::Each;
TEST(CompressedTupleTest, Sizeof) { TEST(CompressedTupleTest, Sizeof) {
EXPECT_EQ(sizeof(int), sizeof(CompressedTuple<int>)); EXPECT_EQ(sizeof(int), sizeof(CompressedTuple<int>));
...@@ -71,6 +75,30 @@ TEST(CompressedTupleTest, Sizeof) { ...@@ -71,6 +75,30 @@ TEST(CompressedTupleTest, Sizeof) {
sizeof(CompressedTuple<int, Empty<0>, NotEmpty<double>, Empty<1>>)); sizeof(CompressedTuple<int, Empty<0>, NotEmpty<double>, Empty<1>>));
} }
TEST(CompressedTupleTest, PointerToEmpty) {
auto to_void_ptrs = [](const auto&... objs) {
return std::vector<const void*>{static_cast<const void*>(&objs)...};
};
{
using Tuple = CompressedTuple<int, Empty<0>>;
EXPECT_EQ(sizeof(int), sizeof(Tuple));
Tuple t;
EXPECT_THAT(to_void_ptrs(t.get<1>()), Each(&t));
}
{
using Tuple = CompressedTuple<int, Empty<0>, Empty<1>>;
EXPECT_EQ(sizeof(int), sizeof(Tuple));
Tuple t;
EXPECT_THAT(to_void_ptrs(t.get<1>(), t.get<2>()), Each(&t));
}
{
using Tuple = CompressedTuple<int, Empty<0>, Empty<1>, Empty<2>>;
EXPECT_EQ(sizeof(int), sizeof(Tuple));
Tuple t;
EXPECT_THAT(to_void_ptrs(t.get<1>(), t.get<2>(), t.get<3>()), Each(&t));
}
}
TEST(CompressedTupleTest, OneMoveOnRValueConstructionTemp) { TEST(CompressedTupleTest, OneMoveOnRValueConstructionTemp) {
InstanceTracker tracker; InstanceTracker tracker;
CompressedTuple<CopyableMovableInstance> x1(CopyableMovableInstance(1)); CompressedTuple<CopyableMovableInstance> x1(CopyableMovableInstance(1));
......
...@@ -126,6 +126,22 @@ TEST(GrowthInfoTest, HasNoDeletedAndGrowthLeft) { ...@@ -126,6 +126,22 @@ TEST(GrowthInfoTest, HasNoDeletedAndGrowthLeft) {
EXPECT_TRUE(gi.HasNoDeletedAndGrowthLeft()); EXPECT_TRUE(gi.HasNoDeletedAndGrowthLeft());
} }
TEST(GrowthInfoTest, HasNoGrowthLeftAndNoDeleted) {
GrowthInfo gi;
gi.InitGrowthLeftNoDeleted(1);
EXPECT_FALSE(gi.HasNoGrowthLeftAndNoDeleted());
gi.OverwriteEmptyAsFull();
EXPECT_TRUE(gi.HasNoGrowthLeftAndNoDeleted());
gi.OverwriteFullAsDeleted();
EXPECT_FALSE(gi.HasNoGrowthLeftAndNoDeleted());
gi.OverwriteFullAsEmpty();
EXPECT_FALSE(gi.HasNoGrowthLeftAndNoDeleted());
gi.InitGrowthLeftNoDeleted(0);
EXPECT_TRUE(gi.HasNoGrowthLeftAndNoDeleted());
gi.OverwriteFullAsEmpty();
EXPECT_FALSE(gi.HasNoGrowthLeftAndNoDeleted());
}
TEST(GrowthInfoTest, OverwriteFullAsEmpty) { TEST(GrowthInfoTest, OverwriteFullAsEmpty) {
GrowthInfo gi; GrowthInfo gi;
gi.InitGrowthLeftNoDeleted(5); gi.InitGrowthLeftNoDeleted(5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment