Avoid allocating strings for known emphasis character fallbacks

This commit is contained in:
Miha Zupan
2023-11-24 02:44:47 +01:00
parent 5cff880c90
commit 4f1cb9da08

View File

@@ -69,7 +69,21 @@ public class EmphasisDelimiterInline : DelimiterInline
public override string ToLiteral()
{
return DelimiterCount > 0 ? new string(DelimiterChar, DelimiterCount) : string.Empty;
if (DelimiterCount == 1)
{
return DelimiterChar switch
{
'*' => "*",
'_' => "_",
'~' => "~",
'^' => "^",
'+' => "+",
'=' => "=",
_ => DelimiterChar.ToString()
};
}
return new string(DelimiterChar, DelimiterCount);
}
public LiteralInline AsLiteralInline()