Skip to content

Commit c988201

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

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@
1111

1212
namespace Flow.Launcher.Plugin.Calculator
1313
{
14-
public class Main : IPlugin, IPluginI18n, ISettingProvider
14+
public partial class Main : IPlugin, IPluginI18n, ISettingProvider
1515
{
16-
private static readonly Regex RegValidExpressChar = MainRegexHelper.GetRegValidExpressChar();
17-
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);
16+
private static readonly Regex RegValidExpressChar = GetRegValidExpressChar();
17+
private static readonly Regex RegBrackets = GetRegBrackets();
18+
private static readonly Regex ThousandGroupRegex = GetThousandGroupRegex();
19+
private static readonly Regex NumberRegex = GetNumberRegex();
20+
21+
[GeneratedRegex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled)]
22+
private static partial Regex GetThousandGroupRegex();
23+
24+
[GeneratedRegex(@"[\(\)\[\]]", RegexOptions.Compiled)]
25+
public static partial Regex GetRegBrackets();
26+
27+
[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)]
28+
public static partial Regex GetRegValidExpressChar();
29+
[GeneratedRegex(@"[\d\.,]+", RegexOptions.Compiled)]
30+
private static partial Regex GetNumberRegex();
2031

2132

2233
private static Engine MagesEngine;

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)