hopeful regex performance improvement?

This commit is contained in:
SillyStar-Github 2025-10-15 03:08:27 -04:00
parent e9f276289b
commit 204f45b629
2 changed files with 17 additions and 7 deletions

View file

@ -147,10 +147,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore
// Regex-based dynamic translation
foreach (var entry in translationStringRegex)
{
var regex = new Regex(entry.Key);
if (regex.IsMatch(originalText))
if (TestRegex(originalText, entry.Key))
{
// Extract dynamic parts from the original text
var regex = new Regex(entry.Key);
var match = regex.Match(originalText);
int groupCount = match.Groups.Count;
@ -180,6 +180,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore
return originalText;
}
private static bool TestRegex(string originalText, string pattern)
{
return Regex.IsMatch(originalText, pattern);
}
private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor)
{
return anchor switch

View file

@ -145,10 +145,10 @@ namespace PvZ_Fusion_Translator.AssetStore
// Regex-based dynamic translation
foreach (var entry in translationStringRegex)
{
var regex = new Regex(entry.Key);
if (regex.IsMatch(originalText))
if (TestRegex(originalText, entry.Key))
{
// Extract dynamic parts from the original text
var regex = new Regex(entry.Key);
var match = regex.Match(originalText);
int groupCount = match.Groups.Count;
@ -178,6 +178,11 @@ namespace PvZ_Fusion_Translator.AssetStore
return originalText;
}
private static bool TestRegex(string originalText, string pattern)
{
return Regex.IsMatch(originalText, pattern);
}
private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor)
{
return anchor switch