diff --git a/ConflictSet.cpp b/ConflictSet.cpp index cf99a81..daebcb3 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -532,7 +532,7 @@ template struct BoundedFreeListAllocator { static_assert(std::derived_from); static_assert(std::is_trivial_v); - 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 struct BoundedFreeListAllocator { return result; } + T *allocate(int partialKeyCapacity) { + T *result = allocate_helper(partialKeyCapacity); + if constexpr (std::is_same_v || std::is_same_v) { + 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(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(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(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;