Use **self directly in insert
This commit is contained in:
@@ -1409,27 +1409,26 @@ bool checkRangeRead(Node *n, std::span<const uint8_t> begin,
|
|||||||
// !entryPresent. The search path of the result's parent will have
|
// !entryPresent. The search path of the result's parent will have
|
||||||
// `maxVersion` at least `writeVersion` as a postcondition.
|
// `maxVersion` at least `writeVersion` as a postcondition.
|
||||||
template <bool kBegin>
|
template <bool kBegin>
|
||||||
[[nodiscard]] Node *insert(Node **self_, std::span<const uint8_t> key,
|
[[nodiscard]] Node *insert(Node **self, std::span<const uint8_t> key,
|
||||||
int64_t writeVersion, NodeAllocators *allocators) {
|
int64_t writeVersion, NodeAllocators *allocators) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto &self = *self_;
|
|
||||||
// Handle an existing partial key
|
// Handle an existing partial key
|
||||||
int commonLen = std::min<int>(self->partialKeyLen, key.size());
|
int commonLen = std::min<int>((*self)->partialKeyLen, key.size());
|
||||||
int partialKeyIndex =
|
int partialKeyIndex = longestCommonPrefixPartialKey((*self)->partialKey,
|
||||||
longestCommonPrefixPartialKey(self->partialKey, key.data(), commonLen);
|
key.data(), commonLen);
|
||||||
if (partialKeyIndex < self->partialKeyLen) {
|
if (partialKeyIndex < (*self)->partialKeyLen) {
|
||||||
auto *old = self;
|
auto *old = *self;
|
||||||
|
|
||||||
self = allocators->node4.allocate();
|
*self = allocators->node4.allocate();
|
||||||
|
|
||||||
memcpy((void *)self, old, offsetof(Node, type));
|
memcpy((void *)*self, old, offsetof(Node, type));
|
||||||
self->partialKeyLen = partialKeyIndex;
|
(*self)->partialKeyLen = partialKeyIndex;
|
||||||
self->entryPresent = false;
|
(*self)->entryPresent = false;
|
||||||
self->numChildren = 0;
|
(*self)->numChildren = 0;
|
||||||
|
|
||||||
getOrCreateChild(self, old->partialKey[partialKeyIndex], allocators) =
|
getOrCreateChild(*self, old->partialKey[partialKeyIndex], allocators) =
|
||||||
old;
|
old;
|
||||||
old->parent = self;
|
old->parent = *self;
|
||||||
old->parentsIndex = old->partialKey[partialKeyIndex];
|
old->parentsIndex = old->partialKey[partialKeyIndex];
|
||||||
|
|
||||||
memmove(old->partialKey, old->partialKey + partialKeyIndex + 1,
|
memmove(old->partialKey, old->partialKey + partialKeyIndex + 1,
|
||||||
@@ -1439,34 +1438,36 @@ template <bool kBegin>
|
|||||||
key = key.subspan(partialKeyIndex, key.size() - partialKeyIndex);
|
key = key.subspan(partialKeyIndex, key.size() - partialKeyIndex);
|
||||||
|
|
||||||
// Consider adding a partial key
|
// Consider adding a partial key
|
||||||
if (self->numChildren == 0 && !self->entryPresent) {
|
if ((*self)->numChildren == 0 && !(*self)->entryPresent) {
|
||||||
self->partialKeyLen = std::min<int>(key.size(), self->kPartialKeyMaxLen);
|
(*self)->partialKeyLen =
|
||||||
memcpy(self->partialKey, key.data(), self->partialKeyLen);
|
std::min<int>(key.size(), (*self)->kPartialKeyMaxLen);
|
||||||
key = key.subspan(self->partialKeyLen, key.size() - self->partialKeyLen);
|
memcpy((*self)->partialKey, key.data(), (*self)->partialKeyLen);
|
||||||
|
key = key.subspan((*self)->partialKeyLen,
|
||||||
|
key.size() - (*self)->partialKeyLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (kBegin) {
|
if constexpr (kBegin) {
|
||||||
self->maxVersion = std::max(self->maxVersion, writeVersion);
|
(*self)->maxVersion = std::max((*self)->maxVersion, writeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.size() == 0) {
|
if (key.size() == 0) {
|
||||||
return self;
|
return *self;
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (!kBegin) {
|
if constexpr (!kBegin) {
|
||||||
self->maxVersion = std::max(self->maxVersion, writeVersion);
|
(*self)->maxVersion = std::max((*self)->maxVersion, writeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &child = getOrCreateChild(self, key.front(), allocators);
|
auto &child = getOrCreateChild((*self), key.front(), allocators);
|
||||||
if (!child) {
|
if (!child) {
|
||||||
child = allocators->node4.allocate();
|
child = allocators->node4.allocate();
|
||||||
child->parent = self;
|
child->parent = (*self);
|
||||||
child->parentsIndex = key.front();
|
child->parentsIndex = key.front();
|
||||||
child->maxVersion =
|
child->maxVersion =
|
||||||
kBegin ? writeVersion : std::numeric_limits<int64_t>::lowest();
|
kBegin ? writeVersion : std::numeric_limits<int64_t>::lowest();
|
||||||
}
|
}
|
||||||
|
|
||||||
self_ = &child;
|
self = &child;
|
||||||
key = key.subspan(1, key.size() - 1);
|
key = key.subspan(1, key.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user