diff options
-rw-r--r-- | AK/QuickSort.h | 26 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.cpp | 2 | ||||
-rw-r--r-- | Applications/SystemMenu/main.cpp | 4 | ||||
-rw-r--r-- | DevTools/HackStudio/Project.cpp | 2 | ||||
-rw-r--r-- | Kernel/Scheduler.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibELF/ELFLoader.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/FontDatabase.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/SortingProxyModel.cpp | 2 | ||||
-rw-r--r-- | Servers/WindowServer/AppletManager.cpp | 2 | ||||
-rw-r--r-- | Shell/LineEditor.cpp | 2 | ||||
-rw-r--r-- | Userland/cut.cpp | 2 | ||||
-rw-r--r-- | Userland/ls.cpp | 4 | ||||
-rw-r--r-- | Userland/sort.cpp | 2 | ||||
-rw-r--r-- | Userland/top.cpp | 2 |
14 files changed, 35 insertions, 23 deletions
diff --git a/AK/QuickSort.h b/AK/QuickSort.h index 69f5e02e68..a52fb39cdb 100644 --- a/AK/QuickSort.h +++ b/AK/QuickSort.h @@ -30,14 +30,8 @@ namespace AK { -template<typename T> -bool is_less_than(const T& a, const T& b) -{ - return a < b; -} - template<typename Iterator, typename LessThan> -void quick_sort(Iterator start, Iterator end, LessThan less_than = is_less_than) +void quick_sort(Iterator start, Iterator end, LessThan less_than) { int size = end - start; if (size <= 1) @@ -62,6 +56,24 @@ void quick_sort(Iterator start, Iterator end, LessThan less_than = is_less_than) quick_sort(start + i, end, less_than); } +template<typename Iterator> +void quick_sort(Iterator start, Iterator end) +{ + quick_sort(start, end, [](auto& a, auto& b) { return a < b; }); +} + +template<typename Collection, typename LessThan> +void quick_sort(Collection& collection, LessThan less_than) +{ + quick_sort(collection.begin(), collection.end(), move(less_than)); +} + +template<typename Collection> +void quick_sort(Collection& collection) +{ + quick_sort(collection.begin(), collection.end()); +} + } using AK::quick_sort; diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index d117616c62..a857b23821 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -542,7 +542,7 @@ void IRCClient::handle_rpl_namreply(const Message& msg) auto& channel = ensure_channel(channel_name); auto members = msg.arguments[3].split(' '); - quick_sort(members.begin(), members.end(), [](auto& a, auto& b) { + quick_sort(members, [](auto& a, auto& b) { return strcasecmp(a.characters(), b.characters()) < 0; }); diff --git a/Applications/SystemMenu/main.cpp b/Applications/SystemMenu/main.cpp index cc9b0cf265..9d4eae6b81 100644 --- a/Applications/SystemMenu/main.cpp +++ b/Applications/SystemMenu/main.cpp @@ -123,7 +123,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu() Vector<String> sorted_app_categories; for (auto& category : seen_app_categories) sorted_app_categories.append(category); - quick_sort(sorted_app_categories.begin(), sorted_app_categories.end(), [](auto& a, auto& b) { return a < b; }); + quick_sort(sorted_app_categories); u8 system_menu_name[] = { 0xc3, 0xb8, 0 }; auto system_menu = GUI::Menu::construct(String((const char*)system_menu_name)); @@ -175,7 +175,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu() auto theme_path = String::format("/res/themes/%s", theme_name.characters()); g_themes.append({ FileSystemPath(theme_name).title(), theme_path }); } - quick_sort(g_themes.begin(), g_themes.end(), [](auto& a, auto& b) { return a.name < b.name; }); + quick_sort(g_themes, [](auto& a, auto& b) { return a.name < b.name; }); } { diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp index 41466844d8..7fb9ba8881 100644 --- a/DevTools/HackStudio/Project.cpp +++ b/DevTools/HackStudio/Project.cpp @@ -60,7 +60,7 @@ struct Project::ProjectTreeNode : public RefCounted<ProjectTreeNode> { { if (type == Type::File) return; - quick_sort(children.begin(), children.end(), [](auto& a, auto& b) { + quick_sort(children, [](auto& a, auto& b) { return a->name < b->name; }); for (auto& child : children) diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index a5aa46f089..b8743cca7f 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -401,7 +401,7 @@ bool Scheduler::pick_next() sorted_runnables.append(&thread); return IterationDecision::Continue; }); - quick_sort(sorted_runnables.begin(), sorted_runnables.end(), [](auto& a, auto& b) { return a->effective_priority() >= b->effective_priority(); }); + quick_sort(sorted_runnables, [](auto& a, auto& b) { return a->effective_priority() >= b->effective_priority(); }); Thread* thread_to_schedule = nullptr; diff --git a/Libraries/LibELF/ELFLoader.cpp b/Libraries/LibELF/ELFLoader.cpp index 8b92bd6561..8849ac56a7 100644 --- a/Libraries/LibELF/ELFLoader.cpp +++ b/Libraries/LibELF/ELFLoader.cpp @@ -179,7 +179,7 @@ String ELFLoader::symbolicate(u32 address, u32* out_offset) const m_sorted_symbols.append({ symbol.value(), symbol.name() }); return IterationDecision::Continue; }); - quick_sort(m_sorted_symbols.begin(), m_sorted_symbols.end(), [](auto& a, auto& b) { + quick_sort(m_sorted_symbols, [](auto& a, auto& b) { return a.address < b.address; }); } diff --git a/Libraries/LibGUI/FontDatabase.cpp b/Libraries/LibGUI/FontDatabase.cpp index 8c03572bd7..42e25f4491 100644 --- a/Libraries/LibGUI/FontDatabase.cpp +++ b/Libraries/LibGUI/FontDatabase.cpp @@ -71,7 +71,7 @@ void GFontDatabase::for_each_font(Function<void(const StringView&)> callback) names.ensure_capacity(m_name_to_metadata.size()); for (auto& it : m_name_to_metadata) names.append(it.key); - quick_sort(names.begin(), names.end(), AK::is_less_than<String>); + quick_sort(names); for (auto& name : names) callback(name); } @@ -84,7 +84,7 @@ void GFontDatabase::for_each_fixed_width_font(Function<void(const StringView&)> if (it.value.is_fixed_width) names.append(it.key); } - quick_sort(names.begin(), names.end(), AK::is_less_than<String>); + quick_sort(names); for (auto& name : names) callback(name); } diff --git a/Libraries/LibGUI/SortingProxyModel.cpp b/Libraries/LibGUI/SortingProxyModel.cpp index 37f7ff0f0a..82062dcca8 100644 --- a/Libraries/LibGUI/SortingProxyModel.cpp +++ b/Libraries/LibGUI/SortingProxyModel.cpp @@ -121,7 +121,7 @@ void SortingProxyModel::resort() did_update(); return; } - quick_sort(m_row_mappings.begin(), m_row_mappings.end(), [&](auto row1, auto row2) -> bool { + quick_sort(m_row_mappings, [&](auto row1, auto row2) -> bool { auto data1 = target().data(target().index(row1, m_key_column), Model::Role::Sort); auto data2 = target().data(target().index(row2, m_key_column), Model::Role::Sort); if (data1 == data2) diff --git a/Servers/WindowServer/AppletManager.cpp b/Servers/WindowServer/AppletManager.cpp index aeabfae990..382222a1d7 100644 --- a/Servers/WindowServer/AppletManager.cpp +++ b/Servers/WindowServer/AppletManager.cpp @@ -71,7 +71,7 @@ void AppletManager::add_applet(Window& applet) { m_applets.append(applet.make_weak_ptr()); - quick_sort(m_applets.begin(), m_applets.end(), [](auto& a, auto& b) { + quick_sort(m_applets, [](auto& a, auto& b) { auto index_a = order_vector.find_first_index(a->title()); auto index_b = order_vector.find_first_index(b->title()); ASSERT(index_a.has_value()); diff --git a/Shell/LineEditor.cpp b/Shell/LineEditor.cpp index 859e359c0b..fc8fd3f6ae 100644 --- a/Shell/LineEditor.cpp +++ b/Shell/LineEditor.cpp @@ -127,7 +127,7 @@ void LineEditor::cache_path() } } - quick_sort(m_path.begin(), m_path.end(), AK::is_less_than<String>); + quick_sort(m_path); } void LineEditor::cut_mismatching_chars(String& completion, const String& other, size_t start_compare) diff --git a/Userland/cut.cpp b/Userland/cut.cpp index 04e34c7b59..0a0bbf380d 100644 --- a/Userland/cut.cpp +++ b/Userland/cut.cpp @@ -221,7 +221,7 @@ int main(int argc, char** argv) Vector<Index> byte_vector; expand_list(tokens, byte_vector); - quick_sort(byte_vector.begin(), byte_vector.end(), [](auto& a, auto& b) { return a.m_from < b.m_from; }); + quick_sort(byte_vector, [](auto& a, auto& b) { return a.m_from < b.m_from; }); /* Process each file */ for (auto& file : files) { cut_file(file, byte_vector); diff --git a/Userland/ls.cpp b/Userland/ls.cpp index bb22bf7392..596ffd774e 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -326,7 +326,7 @@ int do_file_system_object_long(const char* path) files.append(move(metadata)); } - quick_sort(files.begin(), files.end(), [](auto& a, auto& b) { + quick_sort(files, [](auto& a, auto& b) { if (flag_sort_by_timestamp) { if (flag_reverse_sort) return a.stat.st_mtime > b.stat.st_mtime; @@ -382,7 +382,7 @@ int do_file_system_object_short(const char* path) if (names.last().length() > longest_name) longest_name = name.length(); } - quick_sort(names.begin(), names.end(), [](auto& a, auto& b) { return a < b; }); + quick_sort(names); size_t printed_on_row = 0; size_t nprinted = 0; diff --git a/Userland/sort.cpp b/Userland/sort.cpp index 1521344830..009069dca5 100644 --- a/Userland/sort.cpp +++ b/Userland/sort.cpp @@ -50,7 +50,7 @@ int main(int argc, char** argv) lines.append(buffer); } - quick_sort(lines.begin(), lines.end(), [](auto& a, auto& b) { + quick_sort(lines, [](auto& a, auto& b) { return strcmp(a.characters(), b.characters()) < 0; }); diff --git a/Userland/top.cpp b/Userland/top.cpp index beef373a97..5650fcc73c 100644 --- a/Userland/top.cpp +++ b/Userland/top.cpp @@ -184,7 +184,7 @@ int main(int, char**) threads.append(&it.value); } - quick_sort(threads.begin(), threads.end(), [](auto* p1, auto* p2) { + quick_sort(threads, [](auto* p1, auto* p2) { return p2->times_scheduled_since_prev < p1->times_scheduled_since_prev; }); |