From e6e1addbcb719fa1cacfcb593a760fe637ad3823 Mon Sep 17 00:00:00 2001 From: Alexander Montag Date: Mon, 30 Sep 2024 19:23:49 +0200 Subject: [PATCH] Optimize TreeSearch::_filter_tree for performance --- editor/tree_search.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/editor/tree_search.cpp b/editor/tree_search.cpp index 03a11cb..0b3a8f5 100644 --- a/editor/tree_search.cpp +++ b/editor/tree_search.cpp @@ -68,10 +68,16 @@ void TreeSearch::_filter_tree(const String &p_search_mask) { } TreeItem *first_counting_ancestor = cur_item; + bool parents_visible = true; while (first_counting_ancestor && !number_matches.has(first_counting_ancestor)) { + // Performance: we only need to check the first visible ancestor. This is already optimal because of the ordering in ordered_tree_items. + if (!first_counting_ancestor->is_visible()){ + parents_visible = false; + break; + } first_counting_ancestor = first_counting_ancestor->get_parent(); } - if (!first_counting_ancestor || !_vector_has_bsearch(matching_entries, first_counting_ancestor)) { + if (!parents_visible || !first_counting_ancestor || !_vector_has_bsearch(matching_entries, first_counting_ancestor)) { cur_item->set_visible(false); } }