From b963d481c96c8c6b0590339925d9b5714b8c03b4 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 16 Oct 2024 15:54:05 -0700 Subject: [PATCH] Improve codegen for nextLogical --- ConflictSet.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 9726aa6..392e0e9 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -1574,10 +1574,21 @@ Node *nextPhysical(Node *node) { } Node *nextLogical(Node *node) { - for (node = nextPhysical(node); node != nullptr && !node->entryPresent; - node = nextPhysical(node)) - ; - return node; + int index = -1; + for (;;) { + auto nextChild = getChildGeq(node, index + 1); + if (nextChild != nullptr) { + for (node = nextChild; !node->entryPresent; + node = getFirstChildExists(node)) { + } + return node; + } + index = node->parentsIndex; + node = node->parent; + if (node == nullptr) { + return nullptr; + } + } } // Invalidates `self`, replacing it with a node of at least capacity.