From 5a227bd1134988aadf56db1a1b23edc966ac1a66 Mon Sep 17 00:00:00 2001 From: rampaa Date: Sat, 5 Oct 2024 20:45:22 +0300 Subject: [PATCH] Minor --- JL.Core.Tests/LookupTests.cs | 2 +- JL.Core/Dicts/DictUpdater.cs | 11 +++++------ JL.Core/Dicts/DictUtils.cs | 14 +++++++++++++- JL.Core/Freqs/FreqUtils.cs | 14 +++++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/JL.Core.Tests/LookupTests.cs b/JL.Core.Tests/LookupTests.cs index bd9ba2e4..97911a5e 100644 --- a/JL.Core.Tests/LookupTests.cs +++ b/JL.Core.Tests/LookupTests.cs @@ -52,7 +52,7 @@ public void LookupText_始まる() // Arrange List expected = [ - new LookupResult + new ( matchedText: "始まる", dict: DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.JMdict), diff --git a/JL.Core/Dicts/DictUpdater.cs b/JL.Core/Dicts/DictUpdater.cs index 645d6d6a..6aca0e4b 100644 --- a/JL.Core/Dicts/DictUpdater.cs +++ b/JL.Core/Dicts/DictUpdater.cs @@ -287,12 +287,11 @@ internal static Task AutoUpdateBuiltInDicts() } Utils.Frontend.Alert(AlertLevel.Information, $"Updating {dict.Type}..."); - return dict.Type switch - { - DictType.JMdict => UpdateJmdict(pathExists, true), - DictType.JMnedict => UpdateJmnedict(pathExists, true), - _ => UpdateKanjidic(pathExists, true) - }; + return dict.Type is DictType.JMdict + ? UpdateJmdict(pathExists, true) + : dict.Type is DictType.JMnedict + ? UpdateJmnedict(pathExists, true) + : UpdateKanjidic(pathExists, true); } return Task.CompletedTask; diff --git a/JL.Core/Dicts/DictUtils.cs b/JL.Core/Dicts/DictUtils.cs index 273990db..1abad60c 100644 --- a/JL.Core/Dicts/DictUtils.cs +++ b/JL.Core/Dicts/DictUtils.cs @@ -1274,7 +1274,19 @@ dict.Type is DictType.CustomNameDictionary if (dictDBPaths.Count > 0) { - DBUtils.DictDBPaths = DBUtils.DictDBPaths.Union(dictDBPaths).ToFrozenDictionary(StringComparer.Ordinal); + Dictionary tempDictDBPathDict = new(DBUtils.DictDBPaths.Count + dictDBPaths.Count, StringComparer.Ordinal); + + foreach ((string key, string value) in DBUtils.DictDBPaths) + { + tempDictDBPathDict[key] = value; + } + + foreach ((string key, string value) in dictDBPaths) + { + tempDictDBPathDict[key] = value; + } + + DBUtils.DictDBPaths = tempDictDBPathDict.ToFrozenDictionary(StringComparer.Ordinal); } if (tasks.Count > 0 || dictCleared) diff --git a/JL.Core/Freqs/FreqUtils.cs b/JL.Core/Freqs/FreqUtils.cs index 58aabb16..66ad5e2c 100644 --- a/JL.Core/Freqs/FreqUtils.cs +++ b/JL.Core/Freqs/FreqUtils.cs @@ -282,7 +282,19 @@ public static async Task LoadFrequencies() if (freqDBPathDict.Count > 0) { - DBUtils.FreqDBPaths = DBUtils.FreqDBPaths.Union(freqDBPathDict).ToFrozenDictionary(StringComparer.Ordinal); + Dictionary tempFreqDBPathDict = new(DBUtils.FreqDBPaths.Count + freqDBPathDict.Count, StringComparer.Ordinal); + + foreach ((string key, string value) in DBUtils.FreqDBPaths) + { + tempFreqDBPathDict[key] = value; + } + + foreach ((string key, string value) in freqDBPathDict) + { + tempFreqDBPathDict[key] = value; + } + + DBUtils.FreqDBPaths = tempFreqDBPathDict.ToFrozenDictionary(StringComparer.Ordinal); } if (tasks.Count > 0 || freqCleared)