summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/ClassViewWidget.cpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-04-19 16:37:23 +0300
committerAndreas Kling <kling@serenityos.org>2021-04-19 18:13:30 +0200
commite5f84b53d87c1c9931c7e223c71300c27e51d6cb (patch)
treebca77000d012bcb16c39ae1a088c9d73835ad781 /Userland/DevTools/HackStudio/ClassViewWidget.cpp
parent8388e822cbf7f1dc4c026e6accc779f9357309db (diff)
downloadserenity-e5f84b53d87c1c9931c7e223c71300c27e51d6cb.zip
HackStudio: Sort ClassView entries
Diffstat (limited to 'Userland/DevTools/HackStudio/ClassViewWidget.cpp')
-rw-r--r--Userland/DevTools/HackStudio/ClassViewWidget.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/Userland/DevTools/HackStudio/ClassViewWidget.cpp b/Userland/DevTools/HackStudio/ClassViewWidget.cpp
index bfd98ee39a..2ecfb437a5 100644
--- a/Userland/DevTools/HackStudio/ClassViewWidget.cpp
+++ b/Userland/DevTools/HackStudio/ClassViewWidget.cpp
@@ -27,7 +27,10 @@
#include "ClassViewWidget.h"
#include "HackStudio.h"
#include "ProjectDeclarations.h"
+#include <AK/BinarySearch.h>
+#include <AK/StdLibExtras.h>
#include <LibGUI/BoxLayout.h>
+#include <string.h>
namespace HackStudio {
@@ -127,6 +130,22 @@ ClassViewModel::ClassViewModel()
});
}
+static ClassViewNode& add_child_node(NonnullOwnPtrVector<ClassViewNode>& children, NonnullOwnPtr<ClassViewNode>&& node_ptr, ClassViewNode* parent, const GUI::AutocompleteProvider::Declaration* declaration)
+{
+ node_ptr->parent = parent;
+ node_ptr->declaration = declaration;
+
+ size_t inserted_index = 0;
+ ClassViewNode& node = *node_ptr;
+ children.insert_before_matching(
+ move(node_ptr), [&node](auto& other_node) {
+ return strncmp(node.name.characters_without_null_termination(), other_node->name.characters_without_null_termination(), min(node.name.length(), other_node->name.length())) < 0;
+ },
+ 0, &inserted_index);
+
+ return children.at(inserted_index);
+}
+
void ClassViewModel::add_declaration(const GUI::AutocompleteProvider::Declaration& decl)
{
ClassViewNode* parent = nullptr;
@@ -160,9 +179,7 @@ void ClassViewModel::add_declaration(const GUI::AutocompleteProvider::Declaratio
continue;
}
- parent->children.append(make<ClassViewNode>(scope));
- parent->children.last().parent = parent;
- parent = &parent->children.last();
+ parent = &add_child_node(parent->children, make<ClassViewNode>(scope), parent, nullptr);
}
}
@@ -184,9 +201,7 @@ void ClassViewModel::add_declaration(const GUI::AutocompleteProvider::Declaratio
}
}
if (!already_exists) {
- children_of_parent->append(make<ClassViewNode>(decl.name));
- children_of_parent->last().declaration = &decl;
- children_of_parent->last().parent = parent;
+ add_child_node(*children_of_parent, make<ClassViewNode>(decl.name), parent, &decl);
}
}