1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:25:41 +00:00

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

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;