From 2989866a6d7907e0eb42eb03ab7b555b8cdadb8d Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 8 Mar 2024 13:29:02 -0800 Subject: [PATCH] Move type field to end of Node --- ConflictSet.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index f26dfdd..b21b307 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -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(); 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;