Save some instructions in getOrCreateChild
All checks were successful
Tests / Release [gcc] total: 471, passed: 471
GNU C Compiler (gcc) |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |0|0|0|0|:clap: Reference build: <a href="https://jenkins.weaselab.dev/job/weaselab/job/conflict-set/job/main/35//gcc">weaselab » conflict-set » main #35</a>
Tests / Coverage total: 469, passed: 469
weaselab/conflict-set/pipeline/head This commit looks good

This commit is contained in:
2024-02-22 22:46:08 -08:00
parent 9a47f2d03a
commit 259f47664a

View File

@@ -384,11 +384,8 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
NodeAllocators *allocators) { NodeAllocators *allocators) {
if (self->type == Type::Node4) { if (self->type == Type::Node4) {
auto *self4 = static_cast<Node4 *>(self); auto *self4 = static_cast<Node4 *>(self);
{ if (int i = getNodeIndex((Node16 *)self4, index); i >= 0) {
int i = getNodeIndex((Node16 *)self4, index); return self4->children[i];
if (i >= 0) {
return self4->children[i];
}
} }
if (self->numChildren == 4) { if (self->numChildren == 4) {
auto *newSelf = allocators->node16.allocate(); auto *newSelf = allocators->node16.allocate();
@@ -419,11 +416,9 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
} else if (self->type == Type::Node16) { } else if (self->type == Type::Node16) {
insert16: insert16:
auto *self16 = static_cast<Node16 *>(self); auto *self16 = static_cast<Node16 *>(self);
{
int i = getNodeIndex(self16, index); if (int i = getNodeIndex(self16, index); i >= 0) {
if (i >= 0) { return self16->children[i];
return self16->children[i];
}
} }
if (self->numChildren == 16) { if (self->numChildren == 16) {
auto *newSelf = allocators->node48.allocate(); auto *newSelf = allocators->node48.allocate();
@@ -461,8 +456,10 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
} else if (self->type == Type::Node48) { } else if (self->type == Type::Node48) {
insert48: insert48:
auto *self48 = static_cast<Node48 *>(self); auto *self48 = static_cast<Node48 *>(self);
if (self48->bitSet.test(index)) { if (int c = self48->index[index];
return self48->children[self48->index[index]];
c >= 0) {
return self48->children[c];
} }
if (self->numChildren == 48) { if (self->numChildren == 48) {
auto *newSelf = allocators->node256.allocate(); auto *newSelf = allocators->node256.allocate();
@@ -488,11 +485,13 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
} else { } else {
insert256: insert256:
auto *self256 = static_cast<Node256 *>(self); auto *self256 = static_cast<Node256 *>(self);
if (!self256->children[index]) { auto *&result = self256->children[index];
++self->numChildren; if (result) {
return result;
} }
++self->numChildren;
self256->bitSet.set(index); self256->bitSet.set(index);
return self256->children[index]; return result;
} }
} }