Save a few instructions in addWriteRange
This commit is contained in:
@@ -285,6 +285,27 @@ Node *&getChildExists(Node *self, uint8_t index) {
|
|||||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node *getChild(Node *self, uint8_t index) {
|
||||||
|
if (self->type <= Type::Node16) {
|
||||||
|
auto *self16 = static_cast<Node16 *>(self);
|
||||||
|
int i = getNodeIndex(self16, index);
|
||||||
|
if (i >= 0) {
|
||||||
|
return self16->children[i];
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
} else if (self->type == Type::Node48) {
|
||||||
|
auto *self48 = static_cast<Node48 *>(self);
|
||||||
|
int secondIndex = self48->index[index];
|
||||||
|
if (secondIndex >= 0) {
|
||||||
|
return self48->children[secondIndex];
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
} else {
|
||||||
|
auto *self256 = static_cast<Node256 *>(self);
|
||||||
|
return self256->children[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int getChildGeq(Node *self, int child) {
|
int getChildGeq(Node *self, int child) {
|
||||||
if (child > 255) {
|
if (child > 255) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1466,21 +1487,17 @@ void addWriteRange(Node *&root, int64_t oldestVersion,
|
|||||||
auto *n = root;
|
auto *n = root;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (int(remaining.size()) < n->partialKeyLen + 1) {
|
if (int(remaining.size()) <= n->partialKeyLen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = longestCommonPrefixPartialKey(n->partialKey, remaining.data(),
|
||||||
for (; i < n->partialKeyLen; ++i) {
|
n->partialKeyLen);
|
||||||
if (remaining[i] != n->partialKey[i]) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i != n->partialKeyLen) {
|
if (i != n->partialKeyLen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = getChildGeq(n, remaining[n->partialKeyLen]);
|
auto *child = getChild(n, remaining[n->partialKeyLen]);
|
||||||
if (c != remaining[n->partialKeyLen]) {
|
if (child == nullptr) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1488,7 +1505,7 @@ void addWriteRange(Node *&root, int64_t oldestVersion,
|
|||||||
|
|
||||||
remaining = remaining.subspan(n->partialKeyLen + 1,
|
remaining = remaining.subspan(n->partialKeyLen + 1,
|
||||||
remaining.size() - (n->partialKeyLen + 1));
|
remaining.size() - (n->partialKeyLen + 1));
|
||||||
n = getChildExists(n, c);
|
n = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node **useAsRoot = n->parent == nullptr
|
Node **useAsRoot = n->parent == nullptr
|
||||||
|
Reference in New Issue
Block a user