Extract mergeWithChild to function
This commit is contained in:
@@ -1604,6 +1604,48 @@ void rezero(Node *n, InternalVersionT z) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mergeWithChild(Node *&self, WriteContext *tls, ConflictSet::Impl *impl,
|
||||||
|
Node *&dontInvalidate, Node3 *self3) {
|
||||||
|
auto *child = self3->children[0];
|
||||||
|
int minCapacity = self3->partialKeyLen + 1 + child->partialKeyLen;
|
||||||
|
|
||||||
|
if (minCapacity > child->getCapacity()) {
|
||||||
|
const bool update = child == dontInvalidate;
|
||||||
|
freeAndMakeCapacityAtLeast(child, minCapacity, tls, impl, true);
|
||||||
|
if (update) {
|
||||||
|
dontInvalidate = child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge partial key with child
|
||||||
|
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
||||||
|
fprintf(stderr, "Merge %s into %s\n", getSearchPathPrintable(self).c_str(),
|
||||||
|
getSearchPathPrintable(child).c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
InternalVersionT childMaxVersion = maxVersion(child, impl);
|
||||||
|
|
||||||
|
// Construct new partial key for child
|
||||||
|
memmove(child->partialKey() + self3->partialKeyLen + 1, child->partialKey(),
|
||||||
|
child->partialKeyLen);
|
||||||
|
memcpy(child->partialKey(), self3->partialKey(), self->partialKeyLen);
|
||||||
|
child->partialKey()[self3->partialKeyLen] = self3->index[0];
|
||||||
|
child->partialKeyLen += 1 + self3->partialKeyLen;
|
||||||
|
|
||||||
|
child->parent = self->parent;
|
||||||
|
child->parentsIndex = self->parentsIndex;
|
||||||
|
|
||||||
|
// Max versions are stored in the parent, so we need to update it now
|
||||||
|
// that we have a new parent.
|
||||||
|
setMaxVersion(child, impl, childMaxVersion);
|
||||||
|
if (child->parent) {
|
||||||
|
rezero(child->parent, tls->zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
getInTree(self, impl) = child;
|
||||||
|
tls->release(self3);
|
||||||
|
}
|
||||||
|
|
||||||
void maybeDownsize(Node *self, WriteContext *tls, ConflictSet::Impl *impl,
|
void maybeDownsize(Node *self, WriteContext *tls, ConflictSet::Impl *impl,
|
||||||
Node *&dontInvalidate) {
|
Node *&dontInvalidate) {
|
||||||
|
|
||||||
@@ -1623,45 +1665,7 @@ void maybeDownsize(Node *self, WriteContext *tls, ConflictSet::Impl *impl,
|
|||||||
getInTree(self, impl) = newSelf;
|
getInTree(self, impl) = newSelf;
|
||||||
tls->release(self3);
|
tls->release(self3);
|
||||||
} else if (self->numChildren == 1 && !self->entryPresent) {
|
} else if (self->numChildren == 1 && !self->entryPresent) {
|
||||||
auto *child = self3->children[0];
|
mergeWithChild(self, tls, impl, dontInvalidate, self3);
|
||||||
int minCapacity = self3->partialKeyLen + 1 + child->partialKeyLen;
|
|
||||||
|
|
||||||
if (minCapacity > child->getCapacity()) {
|
|
||||||
const bool update = child == dontInvalidate;
|
|
||||||
freeAndMakeCapacityAtLeast(child, minCapacity, tls, impl, true);
|
|
||||||
if (update) {
|
|
||||||
dontInvalidate = child;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge partial key with child
|
|
||||||
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
|
||||||
fprintf(stderr, "Merge %s into %s\n",
|
|
||||||
getSearchPathPrintable(self).c_str(),
|
|
||||||
getSearchPathPrintable(child).c_str());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
InternalVersionT childMaxVersion = maxVersion(child, impl);
|
|
||||||
|
|
||||||
// Construct new partial key for child
|
|
||||||
memmove(child->partialKey() + self3->partialKeyLen + 1,
|
|
||||||
child->partialKey(), child->partialKeyLen);
|
|
||||||
memcpy(child->partialKey(), self3->partialKey(), self->partialKeyLen);
|
|
||||||
child->partialKey()[self3->partialKeyLen] = self3->index[0];
|
|
||||||
child->partialKeyLen += 1 + self3->partialKeyLen;
|
|
||||||
|
|
||||||
child->parent = self->parent;
|
|
||||||
child->parentsIndex = self->parentsIndex;
|
|
||||||
|
|
||||||
// Max versions are stored in the parent, so we need to update it now
|
|
||||||
// that we have a new parent.
|
|
||||||
setMaxVersion(child, impl, childMaxVersion);
|
|
||||||
if (child->parent) {
|
|
||||||
rezero(child->parent, tls->zero);
|
|
||||||
}
|
|
||||||
|
|
||||||
getInTree(self, impl) = child;
|
|
||||||
tls->release(self3);
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case Type_Node16:
|
case Type_Node16:
|
||||||
|
Reference in New Issue
Block a user