Minor improvements to checkMaxBetweenExclusive
This commit is contained in:
@@ -532,7 +532,7 @@ template <class T> struct BoundedFreeListAllocator {
|
||||
static_assert(std::derived_from<T, Node>);
|
||||
static_assert(std::is_trivial_v<T>);
|
||||
|
||||
T *allocate(int partialKeyCapacity) {
|
||||
T *allocate_helper(int partialKeyCapacity) {
|
||||
if (freeList != nullptr) {
|
||||
T *n = (T *)freeList;
|
||||
VALGRIND_MAKE_MEM_DEFINED(freeList, sizeof(freeList));
|
||||
@@ -560,6 +560,14 @@ template <class T> struct BoundedFreeListAllocator {
|
||||
return result;
|
||||
}
|
||||
|
||||
T *allocate(int partialKeyCapacity) {
|
||||
T *result = allocate_helper(partialKeyCapacity);
|
||||
if constexpr (std::is_same_v<T, Node3> || std::is_same_v<T, Node16>) {
|
||||
memset(result->children, 0, sizeof(result->children));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void release(T *p) {
|
||||
if (freeListBytes >= kFreeListMaxMemory) {
|
||||
removeNode(p);
|
||||
@@ -1652,37 +1660,31 @@ bool checkMaxBetweenExclusive(Node *n, int begin, int end,
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
case Type_Node3: {
|
||||
auto *self = static_cast<Node3 *>(n);
|
||||
for (int i = 0; i < self->numChildren && self->index[i] < end; ++i) {
|
||||
if (begin <= self->index[i]) {
|
||||
if (self->children[i].childMaxVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool result = true;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
result &= !((self->children[i].childMaxVersion > readVersion) &
|
||||
(begin <= self->index[i]) & (self->index[i] < end));
|
||||
}
|
||||
return result;
|
||||
} break;
|
||||
case Type_Node16: {
|
||||
auto *self = static_cast<Node16 *>(n);
|
||||
for (int i = 0; i < self->numChildren && self->index[i] < end; ++i) {
|
||||
if (begin <= self->index[i]) {
|
||||
if (self->children[i].childMaxVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool result = true;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
result &= !((self->children[i].childMaxVersion > readVersion) &
|
||||
(begin <= self->index[i]) & (self->index[i] < end));
|
||||
}
|
||||
return result;
|
||||
} break;
|
||||
case Type_Node48: {
|
||||
bool conflict[256] = {};
|
||||
auto *self = static_cast<Node48 *>(n);
|
||||
bool result = true;
|
||||
self->bitSet.forEachInRange(
|
||||
[&](int i) {
|
||||
conflict[i] =
|
||||
self->children[self->index[i]].childMaxVersion > readVersion;
|
||||
result &=
|
||||
self->children[self->index[i]].childMaxVersion <= readVersion;
|
||||
},
|
||||
begin, end);
|
||||
bool result = true;
|
||||
for (auto c : conflict) {
|
||||
result &= !c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
case Type_Node256: {
|
||||
@@ -1693,6 +1695,7 @@ bool checkMaxBetweenExclusive(Node *n, int begin, int end,
|
||||
conflict[i] = self->children[i].childMaxVersion > readVersion;
|
||||
},
|
||||
begin, end);
|
||||
// Should be vectorized
|
||||
bool result = true;
|
||||
for (auto c : conflict) {
|
||||
result &= !c;
|
||||
|
Reference in New Issue
Block a user