瀏覽代碼

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.
Richard Stanway 2 年之前
父節點
當前提交
7c8acd48a9
共有 1 個文件被更改,包括 8 次插入7 次删除
  1. 8 7
      UI/window-basic-filters.cpp

+ 8 - 7
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<FilterInfo> 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 =