From 3b2bd16cd183670a22c07d9d9ae8a010bf7d7b8b Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 1 Aug 2024 11:42:55 -0700 Subject: [PATCH] Add overloads of getChild for each type --- ConflictSet.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 0c20680..095e37f 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -891,29 +891,33 @@ void setMaxVersion(Node *n, ConflictSet::Impl *, InternalVersionT maxVersion); Node *&getInTree(Node *n, ConflictSet::Impl *); +Node *getChild(Node0 *, uint8_t) { return nullptr; } +Node *getChild(Node3 *self, uint8_t index) { + int i = getNodeIndex(self, index); + return i < 0 ? nullptr : self->children[i]; +} +Node *getChild(Node16 *self, uint8_t index) { + int i = getNodeIndex(self, index); + return i < 0 ? nullptr : self->children[i]; +} +Node *getChild(Node48 *self, uint8_t index) { + int i = self->index[index]; + return i < 0 ? nullptr : self->children[i]; +} +Node *getChild(Node256 *self, uint8_t index) { return self->children[index]; } + Node *getChild(Node *self, uint8_t index) { switch (self->getType()) { case Type_Node0: - return nullptr; - case Type_Node3: { - auto *self3 = static_cast(self); - int i = getNodeIndex(self3, index); - return i < 0 ? nullptr : self3->children[i]; - } - case Type_Node16: { - auto *self16 = static_cast(self); - int i = getNodeIndex(self16, index); - return i < 0 ? nullptr : self16->children[i]; - } - case Type_Node48: { - auto *self48 = static_cast(self); - int i = self48->index[index]; - return i < 0 ? nullptr : self48->children[i]; - } - case Type_Node256: { - auto *self256 = static_cast(self); - return self256->children[index]; - } + return getChild(static_cast(self), index); + case Type_Node3: + return getChild(static_cast(self), index); + case Type_Node16: + return getChild(static_cast(self), index); + case Type_Node48: + return getChild(static_cast(self), index); + case Type_Node256: + return getChild(static_cast(self), index); default: // GCOVR_EXCL_LINE __builtin_unreachable(); // GCOVR_EXCL_LINE }