From 7c8acd48a9abe48d62f2552becebe5b3451e0bdc Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Tue, 17 Jan 2023 21:13:44 +0100 Subject: [PATCH] UI: Improved implementation for sorting filters menu Rather than finding the insertion point and iterating the vector for each item, let's sort it afterwards. --- UI/window-basic-filters.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/UI/window-basic-filters.cpp b/UI/window-basic-filters.cpp index b323b99cf..bbff8c23a 100644 --- a/UI/window-basic-filters.cpp +++ b/UI/window-basic-filters.cpp @@ -528,6 +528,11 @@ QMenu *OBSBasicFilters::CreateAddFilterPopupMenu(bool async) : type(type_), name(name_) { } + + bool operator<(const FilterInfo &r) const + { + return name < r.name; + } }; vector types; @@ -542,15 +547,11 @@ QMenu *OBSBasicFilters::CreateAddFilterPopupMenu(bool async) if ((caps & OBS_SOURCE_CAP_OBSOLETE) != 0) continue; - auto it = types.begin(); - for (; it != types.end(); ++it) { - if (it->name >= name) - break; - } - - types.emplace(it, type_str, name); + types.emplace_back(type_str, name); } + sort(types.begin(), types.end()); + QMenu *popup = new QMenu(QTStr("Add"), this); for (FilterInfo &type : types) { uint32_t filterFlags =