hopeful regex performance improvement?
This commit is contained in:
parent
e9f276289b
commit
204f45b629
2 changed files with 17 additions and 7 deletions
|
|
@ -147,11 +147,11 @@ 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 match = regex.Match(originalText);
|
||||
// Extract dynamic parts from the original text
|
||||
var regex = new Regex(entry.Key);
|
||||
var match = regex.Match(originalText);
|
||||
int groupCount = match.Groups.Count;
|
||||
|
||||
if (isLog)
|
||||
|
|
@ -180,7 +180,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore
|
|||
return originalText;
|
||||
}
|
||||
|
||||
private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor)
|
||||
private static bool TestRegex(string originalText, string pattern)
|
||||
{
|
||||
return Regex.IsMatch(originalText, pattern);
|
||||
}
|
||||
|
||||
private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor)
|
||||
{
|
||||
return anchor switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue