diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 3241ede..3639493 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -744,7 +744,8 @@ Node *nextLogical(Node *node) { } // Invalidates `self`, replacing it with a node of at least capacity. -// Does not return nodes to freelists. +// Does not return nodes to freelists when kUseFreeList is false. +template void makeCapacityAtLeast(Node *&self, int capacity, NodeAllocators *allocators, ConflictSet::Impl *impl) { switch (self->type) { @@ -755,7 +756,11 @@ void makeCapacityAtLeast(Node *&self, int capacity, NodeAllocators *allocators, kNodeCopySize); memcpy(newSelf->partialKey(), self0->partialKey(), self->partialKeyLen); getInTree(self, impl) = newSelf; - free(self0); + if constexpr (kUseFreeList) { + allocators->node0.release(self0); + } else { + free(self0); + } self = newSelf; } break; case Type::Node4: { @@ -771,7 +776,11 @@ void makeCapacityAtLeast(Node *&self, int capacity, NodeAllocators *allocators, } getInTree(self, impl) = newSelf; setChildrenParents(newSelf); - free(self4); + if constexpr (kUseFreeList) { + allocators->node4.release(self4); + } else { + free(self4); + } self = newSelf; } break; case Type::Node16: { @@ -787,7 +796,11 @@ void makeCapacityAtLeast(Node *&self, int capacity, NodeAllocators *allocators, } getInTree(self, impl) = newSelf; setChildrenParents(newSelf); - free(self16); + if constexpr (kUseFreeList) { + allocators->node16.release(self16); + } else { + free(self16); + } self = newSelf; } break; case Type::Node48: { @@ -807,7 +820,11 @@ void makeCapacityAtLeast(Node *&self, int capacity, NodeAllocators *allocators, 0, 256); getInTree(self, impl) = newSelf; setChildrenParents(newSelf); - free(self48); + if constexpr (kUseFreeList) { + allocators->node48.release(self48); + } else { + free(self48); + } self = newSelf; } break; case Type::Node256: { @@ -821,7 +838,11 @@ void makeCapacityAtLeast(Node *&self, int capacity, NodeAllocators *allocators, [&](int c) { newSelf->children[c] = self256->children[c]; }, 0, 256); getInTree(self, impl) = newSelf; setChildrenParents(newSelf); - free(self256); + if constexpr (kUseFreeList) { + allocators->node256.release(self256); + } else { + free(self256); + } self = newSelf; } break; } @@ -837,7 +858,8 @@ void maybeDecreaseCapacity(Node *&self, NodeAllocators *allocators, if (self->partialKeyCapacity <= maxCapacity) { return; } - makeCapacityAtLeast(self, maxCapacity, allocators, impl); + makeCapacityAtLeast(self, maxCapacity, allocators, + impl); } // TODO fuse into erase child so we don't need to repeat branches on type @@ -868,7 +890,8 @@ void maybeDownsize(Node *self, NodeAllocators *allocators, if (minCapacity > child->partialKeyCapacity) { const bool update = child == dontInvalidate; - makeCapacityAtLeast(child, minCapacity, allocators, impl); + makeCapacityAtLeast(child, minCapacity, + allocators, impl); if (update) { dontInvalidate = child; }