From 7b9797648ac2bec11a9d03837cd46ff0e44e936a Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 28 Mar 2023 15:44:27 +0100 Subject: [PATCH] perf(sourcegen): cache and compile regex. pass timeout --- X10D.SourceGenerator/EmojiRegexGenerator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/X10D.SourceGenerator/EmojiRegexGenerator.cs b/X10D.SourceGenerator/EmojiRegexGenerator.cs index 9b44b2f..2d67b1d 100644 --- a/X10D.SourceGenerator/EmojiRegexGenerator.cs +++ b/X10D.SourceGenerator/EmojiRegexGenerator.cs @@ -17,6 +17,7 @@ internal sealed class EmojiRegexGenerator : ISourceGenerator public void Initialize(GeneratorInitializationContext context) { string response = HttpClient.GetStringAsync(TwemojiRegexUrl).GetAwaiter().GetResult(); + var regex = new Regex(@"export default /(?.+)/g;", RegexOptions.Compiled, Regex.InfiniteMatchTimeout); using var reader = new StringReader(response); while (reader.ReadLine() is { } line) @@ -26,7 +27,7 @@ internal sealed class EmojiRegexGenerator : ISourceGenerator continue; } - Match match = Regex.Match(line, @"export default /(?.+)/g;"); + Match match = regex.Match(line); if (!match.Success) { continue;