perf(sourcegen): cache and compile regex. pass timeout

This commit is contained in:
Oliver Booth 2023-03-28 15:44:27 +01:00
parent e3dcad5690
commit 7b9797648a
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
1 changed files with 2 additions and 1 deletions

View File

@ -17,6 +17,7 @@ internal sealed class EmojiRegexGenerator : ISourceGenerator
public void Initialize(GeneratorInitializationContext context) public void Initialize(GeneratorInitializationContext context)
{ {
string response = HttpClient.GetStringAsync(TwemojiRegexUrl).GetAwaiter().GetResult(); string response = HttpClient.GetStringAsync(TwemojiRegexUrl).GetAwaiter().GetResult();
var regex = new Regex(@"export default /(?<regex>.+)/g;", RegexOptions.Compiled, Regex.InfiniteMatchTimeout);
using var reader = new StringReader(response); using var reader = new StringReader(response);
while (reader.ReadLine() is { } line) while (reader.ReadLine() is { } line)
@ -26,7 +27,7 @@ internal sealed class EmojiRegexGenerator : ISourceGenerator
continue; continue;
} }
Match match = Regex.Match(line, @"export default /(?<regex>.+)/g;"); Match match = regex.Match(line);
if (!match.Success) if (!match.Success)
{ {
continue; continue;