De-templatize kUseFreeList

This results in smaller code. This is part of the "let the compiler be
in charge of inlining decisions" theme.
This commit is contained in:
2024-03-19 15:12:31 -07:00
parent d78b36821b
commit becfd25139

View File

@@ -998,17 +998,17 @@ Node *nextLogical(Node *node) {
// Invalidates `self`, replacing it with a node of at least capacity. // Invalidates `self`, replacing it with a node of at least capacity.
// Does not return nodes to freelists when kUseFreeList is false. // Does not return nodes to freelists when kUseFreeList is false.
template <bool kUseFreeList>
void freeAndMakeCapacityAtLeast(Node *&self, int capacity, void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
NodeAllocators *allocators, NodeAllocators *allocators,
ConflictSet::Impl *impl) { ConflictSet::Impl *impl,
const bool kUseFreeList) {
switch (self->getType()) { switch (self->getType()) {
case Type_Node0: { case Type_Node0: {
auto *self0 = (Node0 *)self; auto *self0 = (Node0 *)self;
auto *newSelf = allocators->node0.allocate(capacity); auto *newSelf = allocators->node0.allocate(capacity);
newSelf->copyChildrenAndKeyFrom(*self0); newSelf->copyChildrenAndKeyFrom(*self0);
getInTree(self, impl) = newSelf; getInTree(self, impl) = newSelf;
if constexpr (kUseFreeList) { if (kUseFreeList) {
allocators->node0.release(self0); allocators->node0.release(self0);
} else { } else {
removeNode(self0); removeNode(self0);
@@ -1021,7 +1021,7 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
auto *newSelf = allocators->node3.allocate(capacity); auto *newSelf = allocators->node3.allocate(capacity);
newSelf->copyChildrenAndKeyFrom(*self3); newSelf->copyChildrenAndKeyFrom(*self3);
getInTree(self, impl) = newSelf; getInTree(self, impl) = newSelf;
if constexpr (kUseFreeList) { if (kUseFreeList) {
allocators->node3.release(self3); allocators->node3.release(self3);
} else { } else {
removeNode(self3); removeNode(self3);
@@ -1034,7 +1034,7 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
auto *newSelf = allocators->node16.allocate(capacity); auto *newSelf = allocators->node16.allocate(capacity);
newSelf->copyChildrenAndKeyFrom(*self16); newSelf->copyChildrenAndKeyFrom(*self16);
getInTree(self, impl) = newSelf; getInTree(self, impl) = newSelf;
if constexpr (kUseFreeList) { if (kUseFreeList) {
allocators->node16.release(self16); allocators->node16.release(self16);
} else { } else {
removeNode(self16); removeNode(self16);
@@ -1047,7 +1047,7 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
auto *newSelf = allocators->node48.allocate(capacity); auto *newSelf = allocators->node48.allocate(capacity);
newSelf->copyChildrenAndKeyFrom(*self48); newSelf->copyChildrenAndKeyFrom(*self48);
getInTree(self, impl) = newSelf; getInTree(self, impl) = newSelf;
if constexpr (kUseFreeList) { if (kUseFreeList) {
allocators->node48.release(self48); allocators->node48.release(self48);
} else { } else {
removeNode(self48); removeNode(self48);
@@ -1060,7 +1060,7 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
auto *newSelf = allocators->node256.allocate(capacity); auto *newSelf = allocators->node256.allocate(capacity);
newSelf->copyChildrenAndKeyFrom(*self256); newSelf->copyChildrenAndKeyFrom(*self256);
getInTree(self, impl) = newSelf; getInTree(self, impl) = newSelf;
if constexpr (kUseFreeList) { if (kUseFreeList) {
allocators->node256.release(self256); allocators->node256.release(self256);
} else { } else {
removeNode(self256); removeNode(self256);
@@ -1083,8 +1083,7 @@ void maybeDecreaseCapacity(Node *&self, NodeAllocators *allocators,
if (self->getCapacity() <= maxCapacity) { if (self->getCapacity() <= maxCapacity) {
return; return;
} }
freeAndMakeCapacityAtLeast</*kUseFreeList*/ false>(self, maxCapacity, freeAndMakeCapacityAtLeast(self, maxCapacity, allocators, impl, false);
allocators, impl);
} }
void maybeDownsize(Node *self, NodeAllocators *allocators, void maybeDownsize(Node *self, NodeAllocators *allocators,
@@ -1110,8 +1109,7 @@ void maybeDownsize(Node *self, NodeAllocators *allocators,
if (minCapacity > child->getCapacity()) { if (minCapacity > child->getCapacity()) {
const bool update = child == dontInvalidate; const bool update = child == dontInvalidate;
freeAndMakeCapacityAtLeast</*kUseFreeList*/ true>(child, minCapacity, freeAndMakeCapacityAtLeast(child, minCapacity, allocators, impl, true);
allocators, impl);
if (update) { if (update) {
dontInvalidate = child; dontInvalidate = child;
} }