From c4e973c6e914c63d8cff9e66145857795869490e Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 3 Feb 2026 21:21:24 -0600 Subject: [PATCH] while modern compilers *should* already treat template methods as inherently inline, never hurst to spell it out --- Engine/source/core/util/treeObject.h | 73 ++++++++++++++-------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/Engine/source/core/util/treeObject.h b/Engine/source/core/util/treeObject.h index ab721ed60..e2e77c220 100644 --- a/Engine/source/core/util/treeObject.h +++ b/Engine/source/core/util/treeObject.h @@ -40,10 +40,10 @@ public: //------------------------------------------------------------------------- // Constructors / Destructor //------------------------------------------------------------------------- - TreeNode(const T& val = T(), TreeNode* p = NULL) + inline TreeNode(const T& val = T(), TreeNode* p = NULL) : data(val), parent(p) {} - TreeNode(const Vector*>& children, TreeNode* p = NULL) + inline TreeNode(const Vector*>& children, TreeNode* p = NULL) : data(T()), parent(p) { increment(children.size()); @@ -65,7 +65,7 @@ public: // Deep Copy / Cloning //------------------------------------------------------------------------- // Creates a deep copy of this node and its entire subtree. - TreeNode* clone() const { + inline TreeNode* clone() const { auto* copy = new TreeNode(data, NULL); for (U32 i = 0; i < size(); ++i) if ((*this)[i]) @@ -74,7 +74,7 @@ public: } template - TreeNode* cloneIf(Func pred) const { + inline TreeNode* cloneIf(Func pred) const { if (!pred(this)) return NULL; auto* newNode = new TreeNode(data, NULL); for (U32 i = 0; i < size(); ++i) @@ -86,7 +86,7 @@ public: return newNode; } - bool equals(const TreeNode* other) const { + inline bool equals(const TreeNode* other) const { if (!other || data != other->data || size() != other->size()) return false; for (U32 i = 0; i < size(); ++i) { @@ -100,23 +100,23 @@ public: } return true; } - // Stitches 'subtree' as a child of 'atNode' (re-parents, does not clone). - static TreeNode* mergeAt(TreeNode* atNode, TreeNode* subtree) { + + static inline TreeNode* mergeAt(TreeNode* atNode, TreeNode* subtree) { if (!atNode || !subtree) return NULL; atNode->addChild(subtree); return subtree; } - // Clones 'subtree' and attaches the clone as a child of 'atNode'. - static TreeNode* cloneAt(TreeNode* atNode, const TreeNode* subtree) { + static inline TreeNode* cloneAt(TreeNode* atNode, const TreeNode* subtree) { if (!atNode || !subtree) return NULL; TreeNode* newClone = subtree->clone(); atNode->addChild(newClone); return newClone; } - bool isSubtreeOf(const TreeNode* other) const { + + inline bool isSubtreeOf(const TreeNode* other) const { if (!other) return false; if (equals(other)) return true; for (U32 i = 0; i < other->size(); ++i) @@ -126,7 +126,8 @@ public: } // Assignment operator: shallow copy of data and parent pointer only. // Does NOT copy children or subtree. - TreeNode& operator=(const TreeNode& other) { + + inline TreeNode& operator=(const TreeNode& other) { if (this == &other) return *this; data = other.data; @@ -190,14 +191,14 @@ public: } return true; } - bool isVisited(const Vector*>& visited) const { + inline bool isVisited(const Vector*>& visited) const { for (U32 i = 0; i < visited.size(); ++i) if (visited[i] == this) return true; return false; } template - TreeNode* findLeafIf(Func pred) { + inline TreeNode* findLeafIf(Func pred) { if (isLeaf() && pred(this)) return this; for (U32 i = 0; i < size(); ++i) if ((*this)[i]) { @@ -223,7 +224,7 @@ public: current = current->parent; return current; } - bool isAncestorOf(const TreeNode* other) const { + inline bool isAncestorOf(const TreeNode* other) const { const TreeNode* node = other->parent; while (node) { if (node == this) return true; @@ -231,10 +232,10 @@ public: } return false; } - bool isDescendantOf(const TreeNode* other) const { + inline bool isDescendantOf(const TreeNode* other) const { return other->isAncestorOf(this); } - TreeNode* lowestCommonAncestor(TreeNode* other) { + inline TreeNode* lowestCommonAncestor(TreeNode* other) { Vector*> pathA, pathB; getPathToRoot(pathA); other->getPathToRoot(pathB); @@ -246,7 +247,7 @@ public: } return lca; } - void getPathToRoot(Vector*>& out) const { + inline void getPathToRoot(Vector*>& out) const { const TreeNode* node = this; while (node) { out.push_back(node); @@ -264,7 +265,7 @@ public: parent->removeChild(this); parent = NULL; } - static void safeDetachFromParent(TreeNode* node) { + static inline void safeDetachFromParent(TreeNode* node) { if (!node) return; if (node->parent) { for (U32 i = 0; i < node->parent->size(); ++i) { @@ -276,14 +277,14 @@ public: } node->parent = NULL; } - void collectAncestors(Vector*>& outAncestors) const { + inline void collectAncestors(Vector*>& outAncestors) const { TreeNode* node = parent; while (node) { outAncestors.push_back_unique(node); node = node->parent; } } - void collectAncestorsSortedByDepth(const Vector*>& leaves, Vector*>& outAncestors) const { + inline void collectAncestorsSortedByDepth(const Vector*>& leaves, Vector*>& outAncestors) const { Map*, bool> ancestorSet; for (U32 i = 0; i < leaves.size(); ++i) { TreeNode* node = leaves[i]->getParent(); @@ -312,7 +313,7 @@ public: return depth; } template - void forEachAncestor(Func callback) const { + inline void forEachAncestor(Func callback) const { const TreeNode* node = parent; while (node) { callback(node); @@ -603,7 +604,7 @@ public: for (U32 i = 0; i < size(); ++i) if ((*this)[i]) (*this)[i]->collectSubtreeData(dataList); -} + } // callback signature: void(TreeNode*) template inline void forEachChild(Func callback) { @@ -638,7 +639,7 @@ public: } // callback signature: void(TreeNode*) template - void traverseBreadthFirst(Func callback) { + inline void traverseBreadthFirst(Func callback) { Vector*> queue; queue.push_back(this); while (!queue.empty()) { @@ -654,18 +655,16 @@ public: // Typically used for propagating updates up the tree (e.g., refitting bounds). // callback signature: void(TreeNode*) template - void refitPathToRoot(Func refitFunc) - { + inline void refitPathToRoot(Func refitFunc) { TreeNode* node = parent; - while (node) - { + while (node) { refitFunc(node); node = node->parent; } } // callback signature: TreeNode* pred(TreeNode*) template - TreeNode* findIf(Func pred) { + inline TreeNode* findIf(Func pred) { if (pred(this)) return this; for (U32 i = 0; i < size(); ++i) if ((*this)[i]) { @@ -676,7 +675,7 @@ public: } // callback signature: const TreeNode* pred(const TreeNode*) template - void findAllIf(Func pred, Vector*>& out) { + inline void findAllIf(Func pred, Vector*>& out) { if (pred(this)) out.push_back(this); for (U32 i = 0; i < size(); ++i) @@ -685,7 +684,7 @@ public: } // callback signature: const TreeNode* pred(const TreeNode*) template - U32 countIf(Func pred) const { + inline U32 countIf(Func pred) const { U32 count = pred(this) ? 1 : 0; for (U32 i = 0; i < size(); ++i) if ((*this)[i]) @@ -694,7 +693,7 @@ public: } // callback signature: bool pred(TreeNode*) template - void removeIf(Func pred) { + inline void removeIf(Func pred) { for (S32 i = size() - 1; i >= 0; --i) { if ((*this)[i] && pred((*this)[i])) { delete (*this)[i]; @@ -733,7 +732,7 @@ public: //------------------------------------------------------------------------- // Rotation/Balance Utilities //------------------------------------------------------------------------- - static U32 gatherRotationCandidates(TreeNode* parent, Vector*>& outNodes, U32 maxCandidates = 8) { + static inline U32 gatherRotationCandidates(TreeNode* parent, Vector*>& outNodes, U32 maxCandidates = 8) { outNodes.clear(); for (U32 i = 0; i < parent->size() && outNodes.size() < maxCandidates; ++i) { TreeNode* child = (*parent)[i]; @@ -750,7 +749,7 @@ public: } return outNodes.size(); } - static bool findBestRotationPairing( + static inline bool findBestRotationPairing( const Vector*>& nodes, U32 groupSize, F32(*costFunc)(const TreeNode*, const TreeNode*), @@ -811,11 +810,11 @@ public: // Type Conversion Helpers //------------------------------------------------------------------------- template - Derived* getChildAs(U32 i) { return static_cast(getChild(i)); } + inline Derived* getChildAs(U32 i) { return static_cast(getChild(i)); } template - const Derived* getChildAs(U32 i) const { return static_cast(getChild(i)); } + inline const Derived* getChildAs(U32 i) const { return static_cast(getChild(i)); } template - Vector getChildrenAs() { + inline Vector getChildrenAs() { Vector out; for (U32 i = 0; i < size(); ++i) if ((*this)[i]) @@ -823,7 +822,7 @@ public: return out; } template - Vector getChildrenAs() const { + inline Vector getChildrenAs() const { Vector out; for (U32 i = 0; i < size(); ++i) if ((*this)[i])