Skip to content

Commit

Permalink
Optimize Node.get_children by removing redundant cache update checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterPuma80 committed Feb 13, 2025
1 parent e0cdaf9 commit 5f9ab53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,11 +1699,14 @@ Node *Node::get_child(int p_index, bool p_include_internal) const {

TypedArray<Node> Node::get_children(bool p_include_internal) const {
ERR_THREAD_GUARD_V(TypedArray<Node>());
TypedArray<Node> arr;

int cc = get_child_count(p_include_internal);
int offset = p_include_internal ? 0 : data.internal_children_front_count_cache;

TypedArray<Node> 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;
Expand Down

0 comments on commit 5f9ab53

Please sign in to comment.