From 28f63ad83e4337b974ebdd9dec3199118a3afc1a Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Fri, 24 Oct 2025 04:10:07 +0200 Subject: [PATCH] Fix SYSLIB1045: Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time. --- Dalamud/Interface/ImGuiFileDialog/FileDialog.Filters.cs | 7 ++++--- Dalamud/Plugin/Internal/Profiles/ProfileManager.cs | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Filters.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Filters.cs index f52f1d0dd..46f264354 100644 --- a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Filters.cs +++ b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Filters.cs @@ -8,11 +8,12 @@ namespace Dalamud.Interface.ImGuiFileDialog; /// public partial class FileDialog { - private static Regex filterRegex = new(@"[^,{}]+(\{([^{}]*?)\})?", RegexOptions.Compiled); - private List filters = []; private FilterStruct selectedFilter; + [GeneratedRegex(@"[^,{}]+(\{([^{}]*?)\})?", RegexOptions.Compiled)] + private static partial Regex FilterRegex(); + private void ParseFilters(string filters) { // ".*,.cpp,.h,.hpp" @@ -22,7 +23,7 @@ public partial class FileDialog if (filters.Length == 0) return; var currentFilterFound = false; - var matches = filterRegex.Matches(filters); + var matches = FilterRegex().Matches(filters); foreach (Match m in matches) { var match = m.Value; diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs index 460a09207..ee806c590 100644 --- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs +++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs @@ -15,7 +15,7 @@ namespace Dalamud.Plugin.Internal.Profiles; /// Class responsible for managing plugin profiles. /// [ServiceManager.BlockingEarlyLoadedService($"Data provider for {nameof(PluginManager)}.")] -internal class ProfileManager : IServiceType +internal partial class ProfileManager : IServiceType { private static readonly ModuleLog Log = new("PROFMAN"); private readonly DalamudConfiguration config; @@ -334,12 +334,15 @@ internal class ProfileManager : IServiceType } } + [GeneratedRegex(@" \(.* Mix\)")] + private static partial Regex MixRegex(); + private string GenerateUniqueProfileName(string startingWith) { if (this.profiles.All(x => x.Name != startingWith)) return startingWith; - startingWith = Regex.Replace(startingWith, @" \(.* Mix\)", string.Empty); + startingWith = MixRegex().Replace(startingWith, string.Empty); while (true) {