Move type field to end of Node

This commit is contained in:
2024-03-08 13:29:02 -08:00
parent 60df97847c
commit 2989866a6d

View File

@@ -171,7 +171,6 @@ enum class Type : int8_t {
constexpr static int kPartialKeyMaxLenEntryPresent = 24;
struct Node {
Type type;
/* begin section that's copied to the next node */
bool entryPresent = false;
@@ -187,10 +186,12 @@ struct Node {
};
};
/* end section that's copied to the next node */
Type type;
};
constexpr int kNodeCopyBegin = offsetof(Node, entryPresent);
constexpr int kNodeCopySize = sizeof(Node) - kNodeCopyBegin;
constexpr int kNodeCopySize = offsetof(Node, type) - kNodeCopyBegin;
static_assert(offsetof(Node, entry) ==
offsetof(Node, partialKey) + kPartialKeyMaxLenEntryPresent);
@@ -495,8 +496,11 @@ Node *&getOrCreateChild(Node *&self, uint8_t index) {
auto *newSelf = newNode<Node16>();
memcpy((char *)newSelf + kNodeCopyBegin, (char *)self + kNodeCopyBegin,
kNodeCopySize);
memcpy((void *)newSelf->index, (void *)self4->index,
sizeof(self4->index) + sizeof(self4->children));
// TODO replace with memcpy?
for (int i = 0; i < 4; ++i) {
newSelf->index[i] = self4->index[i];
newSelf->children[i] = self4->children[i];
}
free(self4);
setChildrenParents(newSelf);
self = newSelf;