Improve codegen in freeAndMakeCapacityAtLeast
Some checks failed
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |1|0|1|0|:zzz:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, failed: 309, passed: 622
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head There was a failure building this commit

This commit is contained in:
2024-03-14 18:49:49 -07:00
parent 9cafef8bbb
commit eb93157ddf

View File

@@ -215,9 +215,6 @@ struct Node {
uint8_t parentsIndex;
/* end section that's copied to the next node */
// These survive the free list round trip unscathed, and are only written by
// BoundedFreeListAllocator
uint8_t *partialKey();
Type getType() const { return type; }
@@ -252,8 +249,17 @@ struct Node3 : Node {
uint8_t index[kMaxNodes];
Child children[kMaxNodes];
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
void copyChildrenAndKeyFrom(const Node3 &other);
};
void Node3::copyChildrenAndKeyFrom(const Node3 &other) {
assert(numChildren == other.numChildren);
assert(partialKeyLen == other.partialKeyLen);
memcpy(index, other.index,
sizeof(*this) - offsetof(Node3, index) + partialKeyLen);
}
struct Node16 : Node {
constexpr static auto kType = Type_Node16;
constexpr static auto kMaxNodes = 16;
@@ -261,8 +267,20 @@ struct Node16 : Node {
uint8_t index[kMaxNodes];
Child children[kMaxNodes];
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
void copyChildrenAndKeyFrom(const Node16 &other);
};
void Node16::copyChildrenAndKeyFrom(const Node16 &other) {
assert(numChildren == other.numChildren);
assert(partialKeyLen == other.partialKeyLen);
memcpy(index, other.index, sizeof(index));
for (int i = 0; i < numChildren; ++i) {
children[i] = other.children[i];
}
memcpy(partialKey(), &other + 1, partialKeyLen);
}
struct Node48 : Node {
constexpr static auto kType = Type_Node48;
BitSet bitSet;
@@ -859,12 +877,7 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
auto *newSelf = allocators->node3.allocate(capacity);
memcpy((char *)newSelf + kNodeCopyBegin, (char *)self + kNodeCopyBegin,
kNodeCopySize);
memcpy(newSelf->partialKey(), self3->partialKey(), self->partialKeyLen);
// TODO replace with memcpy?
for (int i = 0; i < Node3::kMaxNodes; ++i) {
newSelf->index[i] = self3->index[i];
newSelf->children[i] = self3->children[i];
}
newSelf->copyChildrenAndKeyFrom(*self3);
getInTree(self, impl) = newSelf;
setChildrenParents(newSelf);
if constexpr (kUseFreeList) {
@@ -880,12 +893,7 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity,
auto *newSelf = allocators->node16.allocate(capacity);
memcpy((char *)newSelf + kNodeCopyBegin, (char *)self + kNodeCopyBegin,
kNodeCopySize);
memcpy(newSelf->partialKey(), self16->partialKey(), self->partialKeyLen);
// TODO replace with memcpy?
for (int i = 0; i < Node16::kMaxNodes; ++i) {
newSelf->index[i] = self16->index[i];
newSelf->children[i] = self16->children[i];
}
newSelf->copyChildrenAndKeyFrom(*self16);
getInTree(self, impl) = newSelf;
setChildrenParents(newSelf);
if constexpr (kUseFreeList) {