Skip to content

Commit 443d4f7

Browse files
Build regex at compile time
1 parent 71e0374 commit 443d4f7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider
1515
{
1616
private static readonly Regex RegValidExpressChar = MainRegexHelper.GetRegValidExpressChar();
1717
private static readonly Regex RegBrackets = MainRegexHelper.GetRegBrackets();
18-
private static readonly Regex ThousandGroupRegex = new Regex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled);
19-
private static readonly Regex NumberRegex = new Regex(@"[\d\.,]+", RegexOptions.Compiled);
20-
18+
private static readonly Regex ThousandGroupRegex = MainRegexHelper.GetThousandGroupRegex();
19+
private static readonly Regex NumberRegex = MainRegexHelper.GetNumberRegex();
2120

2221
private static Engine MagesEngine;
2322
private const string Comma = ",";

Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ internal static partial class MainRegexHelper
1010

1111
[GeneratedRegex(@"^(ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|sin|cos|tan|arcsin|arccos|arctan|eigval|eigvec|eig|sum|polar|plot|round|sort|real|zeta|bin2dec|hex2dec|oct2dec|factorial|sign|isprime|isinfty|==|~=|&&|\|\||(?:\<|\>)=?|[ei]|[0-9]|0x[\da-fA-F]+|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]])+$", RegexOptions.Compiled)]
1212
public static partial Regex GetRegValidExpressChar();
13+
14+
[GeneratedRegex(@"[\d\.,]+", RegexOptions.Compiled)]
15+
public static partial Regex GetNumberRegex();
16+
17+
[GeneratedRegex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled)]
18+
public static partial Regex GetThousandGroupRegex();
1319
}

0 commit comments

Comments
 (0)