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