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