From 78d8dbbc1494c9611578d559cadb8b84c04268ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 12 Apr 2021 18:41:30 +0800 Subject: [PATCH 1/2] Use ConcurrentDictionary instead of List --- Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs index e18985fe7..98dbe3080 100644 --- a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs @@ -1,5 +1,6 @@ using Flow.Launcher.Infrastructure; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -14,14 +15,17 @@ namespace Flow.Launcher.Core.Plugin private readonly AssemblyName assemblyName; - private static readonly List loadedAssembly; + private static readonly ConcurrentDictionary loadedAssembly; static PluginAssemblyLoader() { - loadedAssembly = new List(AppDomain.CurrentDomain.GetAssemblies()); + var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies(); + loadedAssembly = new ConcurrentDictionary( + currentAssemblies.Select(x => new KeyValuePair(x.FullName, null))); + AppDomain.CurrentDomain.AssemblyLoad += (sender, args) => { - loadedAssembly.Add(args.LoadedAssembly); + loadedAssembly[args.LoadedAssembly.FullName] = null; }; } @@ -57,9 +61,7 @@ namespace Flow.Launcher.Core.Plugin internal bool ExistsInReferencedPackage(AssemblyName assemblyName) { - if (loadedAssembly.Any(a => a.FullName == assemblyName.FullName)) - return true; - return false; + return loadedAssembly.ContainsKey(assemblyName.FullName); } } } \ No newline at end of file From bad5504de4ad9bcc70a69c484a5fd71ab2d88eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 12 Apr 2021 19:34:58 +0800 Subject: [PATCH 2/2] Change object to byte to reduce overhead --- Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs index 98dbe3080..515b0bedc 100644 --- a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs @@ -15,17 +15,17 @@ namespace Flow.Launcher.Core.Plugin private readonly AssemblyName assemblyName; - private static readonly ConcurrentDictionary loadedAssembly; + private static readonly ConcurrentDictionary loadedAssembly; static PluginAssemblyLoader() { var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies(); - loadedAssembly = new ConcurrentDictionary( - currentAssemblies.Select(x => new KeyValuePair(x.FullName, null))); + loadedAssembly = new ConcurrentDictionary( + currentAssemblies.Select(x => new KeyValuePair(x.FullName, default))); AppDomain.CurrentDomain.AssemblyLoad += (sender, args) => { - loadedAssembly[args.LoadedAssembly.FullName] = null; + loadedAssembly[args.LoadedAssembly.FullName] = default; }; }