Track partialKeyCapacity

If we use partialKeyLen, then the difference between partialKeyCapacity
and partialKeyLen will slowly grow. We have 3 padding bytes in Node now.
This commit is contained in:
2024-03-08 21:10:47 -08:00
parent b79d8f71d3
commit 504a93bb10

View File

@@ -174,18 +174,16 @@ struct Node {
Node *parent = nullptr; Node *parent = nullptr;
Entry entry; Entry entry;
int32_t partialKeyLen = 0; int32_t partialKeyLen = 0;
int16_t numChildren : 15 = 0; int16_t numChildren = 0;
bool entryPresent : 1 = false; bool entryPresent = false;
uint8_t parentsIndex = 0; uint8_t parentsIndex = 0;
/* end section that's copied to the next node */ /* end section that's copied to the next node */
Type type; Type type;
#ifndef NDEBUG
// Leaving this uninitialized is intentional and necessary to expect asserts // Leaving this uninitialized is intentional and necessary for correctness.
// to pass. Basically it needs to be preserved when going to the free list and // Basically it needs to be preserved when going to the free list and back.
// back.
int32_t partialKeyCapacity; int32_t partialKeyCapacity;
#endif
uint8_t *partialKey(); uint8_t *partialKey();
}; };
@@ -274,24 +272,19 @@ struct BoundedFreeListAllocator {
#endif #endif
if (freeList != nullptr) { if (freeList != nullptr) {
T *n = (T *)freeList; T *n = (T *)freeList;
VALGRIND_MAKE_MEM_DEFINED(n, sizeof(T)); VALGRIND_MAKE_MEM_UNDEFINED(n, sizeof(T));
if (n->partialKeyLen >= partialKeyCapacity) { VALGRIND_MAKE_MEM_DEFINED(&n->partialKeyCapacity,
sizeof(n->partialKeyCapacity));
if (n->partialKeyCapacity >= partialKeyCapacity) {
memcpy(&freeList, freeList, sizeof(freeList)); memcpy(&freeList, freeList, sizeof(freeList));
--freeListSize; --freeListSize;
VALGRIND_MAKE_MEM_UNDEFINED(n, sizeof(T));
#ifndef NDEBUG
VALGRIND_MAKE_MEM_DEFINED(&n->partialKeyCapacity,
sizeof(n->partialKeyCapacity));
#endif
return new (n) T; return new (n) T;
} }
VALGRIND_MAKE_MEM_NOACCESS(n, sizeof(T)); VALGRIND_MAKE_MEM_NOACCESS(n, sizeof(T));
} }
auto *result = new (safe_malloc(sizeof(T) + partialKeyCapacity)) T; auto *result = new (safe_malloc(sizeof(T) + partialKeyCapacity)) T;
#ifndef NDEBUG
result->partialKeyCapacity = partialKeyCapacity; result->partialKeyCapacity = partialKeyCapacity;
#endif
return result; return result;
} }