From 8ced544c2648a10bca50100d6227096452a8971d Mon Sep 17 00:00:00 2001 From: nurhafiz Date: Thu, 2 May 2024 09:00:27 +0800 Subject: [PATCH] Use GeneratedRegex --- src/Toimik.UrlNormalization/UrlNormalizer.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Toimik.UrlNormalization/UrlNormalizer.cs b/src/Toimik.UrlNormalization/UrlNormalizer.cs index a7dc1be..61b4233 100644 --- a/src/Toimik.UrlNormalization/UrlNormalizer.cs +++ b/src/Toimik.UrlNormalization/UrlNormalizer.cs @@ -30,9 +30,9 @@ namespace Toimik.UrlNormalization; /// If true, occurrences of two or more adjacent slashes in a path is collapsed into one. The /// default is true . /// -public class UrlNormalizer(bool isAdjacentSlashesCollapsed = true) +public partial class UrlNormalizer(bool isAdjacentSlashesCollapsed = true) { - private static readonly Regex AdjacentSlashesRegex = new("/{2,}", RegexOptions.Compiled); + private static readonly Regex AdjacentSlashesRegex = AtLeastTwoCharactersRegex(); public bool IsAdjacentSlashesCollapsed { get; } = isAdjacentSlashesCollapsed; @@ -188,4 +188,7 @@ protected virtual string NormalizePercentEncoding(string text) text = builder.ToString(); return text; } + + [GeneratedRegex("/{2,}", RegexOptions.Compiled)] + private static partial Regex AtLeastTwoCharactersRegex(); } \ No newline at end of file