Avoid memmove when inserting into Node3
This commit is contained in:
@@ -1122,24 +1122,19 @@ Node *&getOrCreateChild(Node *&self, uint8_t index, WriteContext *tls) {
|
||||
|
||||
insert3:
|
||||
auto *self3 = static_cast<Node3 *>(self);
|
||||
++self->numChildren;
|
||||
int i = 0;
|
||||
for (; i < self->numChildren - 1; ++i) {
|
||||
if (int(self3->index[i]) > int(index)) {
|
||||
memmove(self3->index + i + 1, self3->index + i,
|
||||
self->numChildren - (i + 1));
|
||||
memmove(self3->children + i + 1, self3->children + i,
|
||||
(self->numChildren - (i + 1)) *
|
||||
sizeof(self3->children[0])); // NOLINT
|
||||
memmove(self3->childMaxVersion + i + 1, self3->childMaxVersion + i,
|
||||
(self->numChildren - (i + 1)) *
|
||||
sizeof(self3->childMaxVersion[0]));
|
||||
int i = self->numChildren - 1;
|
||||
for (; i >= 0; --i) {
|
||||
if (int(self3->index[i]) < int(index)) {
|
||||
break;
|
||||
}
|
||||
self3->index[i + 1] = self3->index[i];
|
||||
self3->children[i + 1] = self3->children[i];
|
||||
self3->childMaxVersion[i + 1] = self3->childMaxVersion[i];
|
||||
}
|
||||
self3->index[i] = index;
|
||||
auto &result = self3->children[i];
|
||||
self3->index[i + 1] = index;
|
||||
auto &result = self3->children[i + 1];
|
||||
result = nullptr;
|
||||
++self->numChildren;
|
||||
return result;
|
||||
}
|
||||
case Type_Node16: {
|
||||
|
Reference in New Issue
Block a user