Skip to content

Commit efc45c7

Browse files
committed
Use HashSet storing GlobalPlugins
Use HashSet instead of List to avoid duplicate global plugin
1 parent c5167cb commit efc45c7

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public static class PluginManager
2121
private static IEnumerable<PluginPair> _contextMenuPlugins;
2222

2323
public static List<PluginPair> AllPlugins { get; private set; }
24-
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
25-
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
24+
public static readonly HashSet<PluginPair> GlobalPlugins = new();
25+
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new ();
2626

2727
public static IPublicAPI API { private set; get; }
2828

@@ -143,7 +143,7 @@ public static async Task InitializePlugins(IPublicAPI api)
143143
}
144144
}
145145

146-
public static List<PluginPair> ValidPluginsForQuery(Query query)
146+
public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
147147
{
148148
if (NonGlobalPlugins.ContainsKey(query.ActionKeyword))
149149
{
@@ -285,9 +285,7 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
285285
if (oldActionkeyword == Query.GlobalPluginWildcardSign
286286
&& // Plugins may have multiple ActionKeywords that are global, eg. WebSearch
287287
plugin.Metadata.ActionKeywords
288-
.Where(x => x == Query.GlobalPluginWildcardSign)
289-
.ToList()
290-
.Count == 1)
288+
.Count(x => x == Query.GlobalPluginWildcardSign) == 1)
291289
{
292290
GlobalPlugins.Remove(plugin);
293291
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -494,21 +494,16 @@ private void QueryResults()
494494
}
495495
}, currentCancellationToken);
496496

497-
Task[] tasks = new Task[plugins.Count];
498-
try
497+
// plugins is ICollection, meaning LINQ will get the Count and preallocate Array
498+
499+
Task[] tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch
499500
{
500-
for (var i = 0; i < plugins.Count; i++)
501-
{
502-
if (!plugins[i].Metadata.Disabled)
503-
{
504-
tasks[i] = QueryTask(plugins[i]);
505-
}
506-
else
507-
{
508-
tasks[i] = Task.CompletedTask; // Avoid Null
509-
}
510-
}
501+
false => QueryTask(plugin),
502+
true => Task.CompletedTask
503+
}).ToArray();
511504

505+
try
506+
{
512507
// Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
513508
await Task.WhenAll(tasks);
514509
}

0 commit comments

Comments
 (0)