From 051acce0f7fdf4e2bd6c570d4953489095439ebd Mon Sep 17 00:00:00 2001 From: Bioblaze Payne Date: Fri, 18 Oct 2024 11:54:49 -0700 Subject: [PATCH] Revert "Optimized Node.find_children:" --- scene/main/node.cpp | 63 +++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 0c88ca170ce9..15dee69fa5c3 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1834,50 +1834,24 @@ Node *Node::find_child(const String &p_pattern, bool p_recursive, bool p_owned) // Can be recursive or not, and limited to owned nodes. TypedArray Node::find_children(const String &p_pattern, const String &p_type, bool p_recursive, bool p_owned) const { ERR_THREAD_GUARD_V(TypedArray()); - TypedArray matches; - ERR_FAIL_COND_V(p_pattern.is_empty() && p_type.is_empty(), matches); - - // Save basic pattern and type info for faster lookup - bool is_pattern_empty = p_pattern.is_empty(); - bool is_type_empty = p_type.is_empty(); - bool is_type_global_class = !is_type_empty && ScriptServer::is_global_class(p_type); - String type_global_path = is_type_global_class ? ScriptServer::get_global_class_path(p_type) : ""; - - TypedArray to_search; - to_search.append(this); - bool is_adding_children = true; - while (!to_search.is_empty()) { - Node *entry = Object::cast_to(to_search.pop_front()); - - // Add all the children to the list to search - entry->_update_children_cache(); - if (is_adding_children) { - Node *const *cptr = entry->data.children_cache.ptr(); - int ccount = entry->data.children_cache.size(); - for (int i = 0; i < ccount; i++) { - if (p_owned && !cptr[i]->data.owner) { - continue; - } - - to_search.append(cptr[i]); - } - - // Stop further child adding if we don't want recursive - if (!p_recursive) { - is_adding_children = false; - } + TypedArray ret; + ERR_FAIL_COND_V(p_pattern.is_empty() && p_type.is_empty(), ret); + _update_children_cache(); + Node *const *cptr = data.children_cache.ptr(); + int ccount = data.children_cache.size(); + for (int i = 0; i < ccount; i++) { + if (p_owned && !cptr[i]->data.owner) { + continue; } - // Check if the entry matches - bool is_pattern_match = is_pattern_empty || entry->data.name.operator String().match(p_pattern); - bool is_type_match = is_type_empty || entry->is_class(p_type); - bool is_script_type_match = false; - if (!is_type_match) { - if (ScriptInstance *script_inst = entry->get_script_instance()) { - Ref