From 6b5fbad2503be27bcc52de1ecdfa6c8e8d7a3eb9 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Thu, 1 Aug 2019 00:32:41 +1000 Subject: [PATCH] LibGUI: Simplify GTreeView ancestor traversal --- Libraries/LibGUI/GTreeView.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Libraries/LibGUI/GTreeView.cpp b/Libraries/LibGUI/GTreeView.cpp index 59e35426ff..08af08e5a1 100644 --- a/Libraries/LibGUI/GTreeView.cpp +++ b/Libraries/LibGUI/GTreeView.cpp @@ -226,19 +226,12 @@ void GTreeView::did_update_selection() if (!index.is_valid()) return; bool opened_any = false; - auto& metadata_for_index = ensure_metadata_for_index(index); - if (!metadata_for_index.open) { - opened_any = true; - metadata_for_index.open = true; - } - auto ancestor = index.parent(); - while (ancestor.is_valid()) { - auto& metadata_for_ancestor = ensure_metadata_for_index(ancestor); + for (auto current = index; current.is_valid(); current = current.parent()) { + auto& metadata_for_ancestor = ensure_metadata_for_index(current); if (!metadata_for_ancestor.open) { metadata_for_ancestor.open = true; opened_any = true; } - ancestor = ancestor.parent(); } if (opened_any) update_content_size();