From 5f9ab53e0dbcbb92ec6766edb0df8f02c224d618 Mon Sep 17 00:00:00 2001 From: Mister Puma Date: Wed, 12 Feb 2025 17:06:51 -0800 Subject: [PATCH] Optimize Node.get_children by removing redundant cache update checks --- README.md | 3 ++- scene/main/node.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 392a4e969870..674838ec3f74 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ # Based on Godot 4.3 but with changes * [x] Expose Engine.get_frame_ticks to GDScript * [x] Change look_at to have default up of Vector3.INF and find appropriate axis itself if Vector3.INF is argument. -* [x] Change Node.find_children to be faster by using a vector as a stack instead of recursion, and caching values +* [x] Optimize Node.find_children to be faster by using a vector as a stack instead of recursion, and caching values +* [X] Optimize Node.get_children by removing redundant cache update checks # Get code diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5b015d45124b..d50dcdc3ce53 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1699,11 +1699,14 @@ Node *Node::get_child(int p_index, bool p_include_internal) const { TypedArray Node::get_children(bool p_include_internal) const { ERR_THREAD_GUARD_V(TypedArray()); - TypedArray arr; + int cc = get_child_count(p_include_internal); + int offset = p_include_internal ? 0 : data.internal_children_front_count_cache; + + TypedArray arr; arr.resize(cc); for (int i = 0; i < cc; i++) { - arr[i] = get_child(i, p_include_internal); + arr[i] = data.children_cache[i + offset]; } return arr;