From ba33267132e996d3ced36bc6ac6e20e4291eefe3 Mon Sep 17 00:00:00 2001 From: Arda Cinar Date: Tue, 13 Dec 2022 11:16:55 +0300 Subject: [PATCH] SpaceAnalyzer: Add a method to TreeNode to get a child node by name This will make it easier to get to a tree node given a file path --- Userland/Applications/SpaceAnalyzer/Tree.cpp | 10 ++++++++++ Userland/Applications/SpaceAnalyzer/Tree.h | 1 + 2 files changed, 11 insertions(+) diff --git a/Userland/Applications/SpaceAnalyzer/Tree.cpp b/Userland/Applications/SpaceAnalyzer/Tree.cpp index bfc7909a64..eb6258a0c0 100644 --- a/Userland/Applications/SpaceAnalyzer/Tree.cpp +++ b/Userland/Applications/SpaceAnalyzer/Tree.cpp @@ -128,3 +128,13 @@ HashMap TreeNode::populate_filesize_tree(Vector& mounts, Fu update_totals(); return error_accumulator; } + +Optional TreeNode::child_with_name(DeprecatedString name) const +{ + for (auto& child : *m_children) { + if (child.name() == name) + return child; + } + + return {}; +} diff --git a/Userland/Applications/SpaceAnalyzer/Tree.h b/Userland/Applications/SpaceAnalyzer/Tree.h index ee63facaed..377bb4fb1f 100644 --- a/Userland/Applications/SpaceAnalyzer/Tree.h +++ b/Userland/Applications/SpaceAnalyzer/Tree.h @@ -32,6 +32,7 @@ public: return 0; } TreeNode const& child_at(size_t i) const { return m_children->at(i); } + Optional child_with_name(DeprecatedString name) const; void sort_children_by_area() const; HashMap populate_filesize_tree(Vector& mounts, Function on_progress);