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