Skip to content

Commit 6579a46

Browse files
Compile regex on build time
1 parent 22ffc80 commit 6579a46

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,8 @@ namespace Flow.Launcher.Plugin.Calculator
1212
{
1313
public class Main : IPlugin, IPluginI18n, ISettingProvider
1414
{
15-
private static readonly Regex RegValidExpressChar = new Regex(
16-
@"^(" +
17-
@"ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|" +
18-
@"sin|cos|tan|arcsin|arccos|arctan|" +
19-
@"eigval|eigvec|eig|sum|polar|plot|round|sort|real|zeta|" +
20-
@"bin2dec|hex2dec|oct2dec|" +
21-
@"factorial|sign|isprime|isinfty|" +
22-
@"==|~=|&&|\|\||(?:\<|\>)=?|" +
23-
@"[ei]|[0-9]|0x[\da-fA-F]+|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
24-
@")+$", RegexOptions.Compiled);
25-
private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
15+
private static readonly Regex RegValidExpressChar = MainRegexHelper.GetRegValidExpressChar();
16+
private static readonly Regex RegBrackets = MainRegexHelper.GetRegBrackets();
2617
private static Engine MagesEngine;
2718
private const string Comma = ",";
2819
private const string Dot = ".";
@@ -155,7 +146,7 @@ private static string ChangeDecimalSeparator(decimal value, string newDecimalSep
155146
return value.ToString(numberFormatInfo);
156147
}
157148

158-
private string GetDecimalSeparator()
149+
private string GetDecimalSeparator()
159150
{
160151
string systemDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
161152
return _settings.DecimalSeparator switch
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace Flow.Launcher.Plugin.Calculator;
4+
5+
internal static partial class MainRegexHelper
6+
{
7+
8+
[GeneratedRegex(@"[\(\)\[\]]", RegexOptions.Compiled)]
9+
public static partial Regex GetRegBrackets();
10+
11+
[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)]
12+
public static partial Regex GetRegValidExpressChar();
13+
}

0 commit comments

Comments
 (0)