Skip to content

Commit 24d8cb4

Browse files
perf: avoid array allocation in HighlightService.CreateStyledLine loop
Replaced `SelectMany(x => new int[] { ... })` with `Select(x => ...).Concat(Select(x => ...))` to eliminate per-item array allocations in the highlight processing loop. This reduces GC pressure and improves performance for log lines with many highlights. Co-authored-by: xm-i <6365453+xm-i@users.noreply.github.com>
1 parent 68710e8 commit 24d8cb4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

RemoteLogViewer.Core/Services/Viewer/HighlightService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public string CreateStyledLine(string content) {
140140
var endsLookup = mergedWordStyles.ToLookup(x => x.End + 1);
141141

142142
// スタイルの付け替えが発生する可能性のあるindexを列挙
143-
foreach (var index in mergedWordStyles.SelectMany(x => new int[] { x.Start, x.End + 1 }).OrderBy(x => x).Distinct()) {
143+
foreach (var index in mergedWordStyles.Select(x => x.Start).Concat(mergedWordStyles.Select(x => x.End + 1)).OrderBy(x => x).Distinct()) {
144144
_ = sb.Append(Escape(content[(styledIndex + 1)..index]));
145145
styledIndex = index - 1;
146146

0 commit comments

Comments
 (0)