summaryrefslogtreecommitdiff
path: root/Shell/Shell.cpp
diff options
context:
space:
mode:
authorMathieu PATUREL <australie.p@gmail.com>2020-08-03 19:06:42 +1000
committerAndreas Kling <kling@serenityos.org>2020-08-04 10:51:16 +0200
commit0622b60fbdf916639239d3603c8774474a2fe1f7 (patch)
tree160eb019d4222d3049ea603f053d44fd7bae46e3 /Shell/Shell.cpp
parentf6d4c4f02c90da131eee6ae762a7ebdd2e80c92e (diff)
downloadserenity-0622b60fbdf916639239d3603c8774474a2fe1f7.zip
Shell: factor out updating the path cache into a function.
Diffstat (limited to 'Shell/Shell.cpp')
-rw-r--r--Shell/Shell.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp
index 2109ccb1a1..25ee4b5fd2 100644
--- a/Shell/Shell.cpp
+++ b/Shell/Shell.cpp
@@ -795,6 +795,24 @@ void Shell::cache_path()
quick_sort(cached_path);
}
+void Shell::add_entry_to_cache(const String& entry)
+{
+ size_t index = 0;
+ auto match = binary_search(
+ cached_path.span(), entry, [](const String& name, const String& program) -> int {
+ return strcmp(name.characters(), program.characters());
+ },
+ &index);
+
+ if (match)
+ return;
+
+ while (strcmp(cached_path[index].characters(), entry.characters()) < 0) {
+ index++;
+ }
+ cached_path.insert(index, entry);
+}
+
void Shell::highlight(Line::Editor& editor) const
{
auto line = editor.line();