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