Optimize TreeSearch::_filter_tree for performance

This commit is contained in:
Alexander Montag 2024-09-30 19:23:49 +02:00
parent 8d781da1a6
commit e6e1addbcb
No known key found for this signature in database
GPG Key ID: 07FE50B35A2B7524
1 changed files with 7 additions and 1 deletions

View File

@ -68,10 +68,16 @@ void TreeSearch::_filter_tree(const String &p_search_mask) {
} }
TreeItem *first_counting_ancestor = cur_item; TreeItem *first_counting_ancestor = cur_item;
bool parents_visible = true;
while (first_counting_ancestor && !number_matches.has(first_counting_ancestor)) { 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(); 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); cur_item->set_visible(false);
} }
} }