Micro-optimization: Move compilation of some Regex generation to compile time instead of runtime, make some static ones compiled (#20287)

Move compilation of some Regex generation to compile time instead of runtime, make some static ones compiled
This commit is contained in:
Henrik
2025-09-28 23:40:50 +02:00
committed by GitHub
parent fc60b5b5ff
commit fbbbc45c24
3 changed files with 30 additions and 14 deletions

View File

@@ -225,16 +225,18 @@ public static partial class NPocoDatabaseExtensions
/// <returns></returns>
public static string EscapeAtSymbols(string value)
{
if (value.Contains("@") == false)
if (value.Contains('@') == false)
{
return value;
}
// this fancy regex will only match a single @ not a double, etc...
var regex = new Regex("(?<!@)@(?!@)");
return regex.Replace(value, "@@");
return AtRegex().Replace(value, "@@");
}
[GeneratedRegex("(?<!@)@(?!@)")]
private static partial Regex AtRegex();
/// <summary>
/// Returns the underlying connection as a typed connection - this is used to unwrap the profiled mini profiler stuff
/// </summary>