diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 1f068303f..94ceb242e 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -21,8 +21,8 @@ namespace Flow.Launcher.Core.Plugin private static IEnumerable _contextMenuPlugins; public static List AllPlugins { get; private set; } - public static readonly List GlobalPlugins = new List(); - public static readonly Dictionary NonGlobalPlugins = new Dictionary(); + public static readonly HashSet GlobalPlugins = new(); + public static readonly Dictionary NonGlobalPlugins = new (); public static IPublicAPI API { private set; get; } @@ -143,7 +143,7 @@ namespace Flow.Launcher.Core.Plugin } } - public static List ValidPluginsForQuery(Query query) + public static ICollection ValidPluginsForQuery(Query query) { if (NonGlobalPlugins.ContainsKey(query.ActionKeyword)) { @@ -285,9 +285,7 @@ namespace Flow.Launcher.Core.Plugin if (oldActionkeyword == Query.GlobalPluginWildcardSign && // Plugins may have multiple ActionKeywords that are global, eg. WebSearch plugin.Metadata.ActionKeywords - .Where(x => x == Query.GlobalPluginWildcardSign) - .ToList() - .Count == 1) + .Count(x => x == Query.GlobalPluginWildcardSign) == 1) { GlobalPlugins.Remove(plugin); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 56ab0ff1d..abe8d681b 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -494,21 +494,16 @@ namespace Flow.Launcher.ViewModel } }, currentCancellationToken); - Task[] tasks = new Task[plugins.Count]; + // plugins is ICollection, meaning LINQ will get the Count and preallocate Array + + Task[] tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch + { + false => QueryTask(plugin), + true => Task.CompletedTask + }).ToArray(); + try { - for (var i = 0; i < plugins.Count; i++) - { - if (!plugins[i].Metadata.Disabled) - { - tasks[i] = QueryTask(plugins[i]); - } - else - { - tasks[i] = Task.CompletedTask; // Avoid Null - } - } - // Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first await Task.WhenAll(tasks); }