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:
|
insert3:
|
||||||
auto *self3 = static_cast<Node3 *>(self);
|
auto *self3 = static_cast<Node3 *>(self);
|
||||||
++self->numChildren;
|
int i = self->numChildren - 1;
|
||||||
int i = 0;
|
for (; i >= 0; --i) {
|
||||||
for (; i < self->numChildren - 1; ++i) {
|
if (int(self3->index[i]) < int(index)) {
|
||||||
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]));
|
|
||||||
break;
|
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;
|
self3->index[i + 1] = index;
|
||||||
auto &result = self3->children[i];
|
auto &result = self3->children[i + 1];
|
||||||
result = nullptr;
|
result = nullptr;
|
||||||
|
++self->numChildren;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
case Type_Node16: {
|
case Type_Node16: {
|
||||||
|
Reference in New Issue
Block a user