Added optimization

This commit is contained in:
Thorsten Sommer 2026-03-21 19:03:38 +01:00
parent 02896e1ca2
commit 419c5a9d68
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -205,6 +205,7 @@ public partial class ContentBlockComponent : MSGComponentBase
var lines = normalizedWithUnixLineEndings.Split('\n'); var lines = normalizedWithUnixLineEndings.Split('\n');
var markdownBuilder = new StringBuilder(); var markdownBuilder = new StringBuilder();
var mathBuilder = new StringBuilder(); var mathBuilder = new StringBuilder();
var segments = new List<MarkdownRenderSegment>(); var segments = new List<MarkdownRenderSegment>();
string? activeCodeFenceMarker = null; string? activeCodeFenceMarker = null;
var inMathBlock = false; var inMathBlock = false;
@ -215,13 +216,13 @@ public partial class ContentBlockComponent : MSGComponentBase
if (!inMathBlock && TryUpdateCodeFenceState(trimmedLine, ref activeCodeFenceMarker)) if (!inMathBlock && TryUpdateCodeFenceState(trimmedLine, ref activeCodeFenceMarker))
{ {
AppendLine(markdownBuilder, line); markdownBuilder.AppendLine(line);
continue; continue;
} }
if (activeCodeFenceMarker is not null) if (activeCodeFenceMarker is not null)
{ {
AppendLine(markdownBuilder, line); markdownBuilder.AppendLine(line);
continue; continue;
} }
@ -242,7 +243,10 @@ public partial class ContentBlockComponent : MSGComponentBase
continue; continue;
} }
AppendLine(inMathBlock ? mathBuilder : markdownBuilder, line); if (inMathBlock)
mathBuilder.AppendLine(line);
else
markdownBuilder.AppendLine(line);
} }
if (inMathBlock) if (inMathBlock)
@ -309,18 +313,13 @@ public partial class ContentBlockComponent : MSGComponentBase
return true; return true;
} }
private static void AppendLine(StringBuilder builder, string line)
{
builder.AppendLine(line);
}
private enum MarkdownRenderSegmentType private enum MarkdownRenderSegmentType
{ {
MARKDOWN, MARKDOWN,
MATH_BLOCK, MATH_BLOCK,
} }
private readonly record struct MarkdownRenderSegment(MarkdownRenderSegmentType Type, string Content); private sealed record MarkdownRenderSegment(MarkdownRenderSegmentType Type, string Content);
private async Task RemoveBlock() private async Task RemoveBlock()
{ {