Skip to content

Commit 47b67f9

Browse files
author
BRUNER Patrick
committed
optimisations
1 parent ecc71c1 commit 47b67f9

5 files changed

Lines changed: 47 additions & 53 deletions

File tree

src/LogExpert.Core/Classes/Bookmark/BookmarkDataProvider.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,9 @@ public void RemoveAutoGeneratedBookmarks ()
107107

108108
lock (_bookmarkListLock)
109109
{
110-
List<int> keysToRemove = [];
111-
foreach (var kvp in BookmarkList)
112-
{
113-
if (kvp.Value.IsAutoGenerated)
114-
{
115-
keysToRemove.Add(kvp.Key);
116-
}
117-
}
110+
List<int> keysToRemove = [.. BookmarkList
111+
.Where(kvp => kvp.Value.IsAutoGenerated)
112+
.Select(kvp => kvp.Key)];
118113

119114
foreach (var key in keysToRemove)
120115
{

src/LogExpert.Core/Classes/Bookmark/HighlightBookmarkScanner.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Text;
2+
13
using ColumnizerLib;
24

35
using LogExpert.Core.Classes.Highlight;
@@ -79,26 +81,21 @@ public static class HighlightBookmarkScanner
7981
private static (bool SetBookmark, string BookmarkComment, string SourceHighlightText) GetBookmarkAction (ITextValueMemory line, List<HighlightEntry> bookmarkEntries)
8082
{
8183
var setBookmark = false;
82-
var bookmarkComment = string.Empty;
84+
var bookmarkCommentBuilder = new StringBuilder();
8385
var sourceHighlightText = string.Empty;
8486

85-
foreach (var entry in bookmarkEntries)
87+
foreach (var entry in bookmarkEntries.Where(entry => CheckHighlightEntryMatch(entry, line)))
8688
{
87-
if (CheckHighlightEntryMatch(entry, line))
88-
{
89-
setBookmark = true;
90-
sourceHighlightText = entry.SearchText;
89+
setBookmark = true;
90+
sourceHighlightText = entry.SearchText;
9191

92-
if (!string.IsNullOrEmpty(entry.BookmarkComment))
93-
{
94-
bookmarkComment += entry.BookmarkComment + "\r\n";
95-
}
92+
if (!string.IsNullOrEmpty(entry.BookmarkComment))
93+
{
94+
_ = bookmarkCommentBuilder.Append(entry.BookmarkComment).Append("\r\n");
9695
}
9796
}
9897

99-
bookmarkComment = bookmarkComment.TrimEnd('\r', '\n');
100-
101-
return (setBookmark, bookmarkComment, sourceHighlightText);
98+
return (setBookmark, bookmarkCommentBuilder.ToString().TrimEnd('\r', '\n'), sourceHighlightText);
10299
}
103100

104101
/// <summary>

src/LogExpert.Tests/Bookmark/HighlightBookmarkScannerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ public void Scan_CancellationRequested_ThrowsOperationCanceled ()
213213
{
214214
new() { SearchText = "ERROR", IsSetBookmark = true }
215215
};
216-
var cts = new CancellationTokenSource();
216+
217+
using var cts = new CancellationTokenSource();
217218
cts.Cancel();
218219

219220
// Act & Assert

src/LogExpert.UI/Controls/BufferedDataGridView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected override void OnPaint (PaintEventArgs e)
170170
{
171171
base.OnPaint(e);
172172
}
173-
catch (Exception innerEx)
173+
catch (InvalidOperationException innerEx)
174174
{
175175
_logger.Error($"Base paint also failed. {innerEx}");
176176
}

src/LogExpert.UI/Controls/LogWindow/LogWindow.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7155,47 +7155,48 @@ private void RunHighlightBookmarkScan ()
71557155

71567156
private void ExecuteHighlightBookmarkScan (int lineCount, List<HighlightEntry> entries, string fileName, IProgress<int> progress, CancellationTokenSource cts)
71577157
{
7158-
try
7158+
using (cts)
71597159
{
7160-
var bookmarks = HighlightBookmarkScanner.Scan(lineCount, _logFileReader.GetLogLineMemory, entries, fileName, PROGRESS_BAR_MODULO, progress, cts.Token);
7161-
7162-
// Marshal bookmark additions to UI thread
7163-
if (!cts.Token.IsCancellationRequested && IsHandleCreated && !IsDisposed)
7160+
try
71647161
{
7165-
_ = BeginInvoke(() =>
7162+
var bookmarks = HighlightBookmarkScanner.Scan(lineCount, _logFileReader.GetLogLineMemory, entries, fileName, PROGRESS_BAR_MODULO, progress, cts.Token);
7163+
7164+
// Marshal bookmark additions to UI thread
7165+
if (!cts.Token.IsCancellationRequested && IsHandleCreated && !IsDisposed)
71667166
{
7167-
_ = _bookmarkProvider.AddBookmarks(bookmarks);
7167+
_ = BeginInvoke(() =>
7168+
{
7169+
_ = _bookmarkProvider.AddBookmarks(bookmarks);
71687170

7169-
RefreshAllGrids();
7171+
RefreshAllGrids();
71707172

7171-
_progressEventArgs.Visible = false;
7172-
SendProgressBarUpdate();
7173-
StatusLineText(string.Empty);
7174-
});
7173+
_progressEventArgs.Visible = false;
7174+
SendProgressBarUpdate();
7175+
StatusLineText(string.Empty);
7176+
});
7177+
}
71757178
}
7176-
}
7177-
catch (OperationCanceledException)
7178-
{
7179-
// Scan was cancelled — clean up on UI thread
7180-
if (IsHandleCreated && !IsDisposed)
7179+
catch (OperationCanceledException)
71817180
{
7182-
_ = BeginInvoke(() =>
7181+
// Scan was cancelled — clean up on UI thread
7182+
if (IsHandleCreated && !IsDisposed)
71837183
{
7184-
_progressEventArgs.Visible = false;
7185-
SendProgressBarUpdate();
7186-
StatusLineText(string.Empty);
7187-
});
7184+
_ = BeginInvoke(() =>
7185+
{
7186+
_progressEventArgs.Visible = false;
7187+
SendProgressBarUpdate();
7188+
StatusLineText(string.Empty);
7189+
});
7190+
}
71887191
}
7189-
}
7190-
finally
7191-
{
7192-
// Only dispose if this is still the active CTS
7193-
if (_highlightBookmarkScanCts == cts)
7192+
finally
71947193
{
7195-
_highlightBookmarkScanCts = null;
7194+
// Only dispose if this is still the active CTS
7195+
if (_highlightBookmarkScanCts == cts)
7196+
{
7197+
_highlightBookmarkScanCts = null;
7198+
}
71967199
}
7197-
7198-
cts.Dispose();
71997200
}
72007201
}
72017202

0 commit comments

Comments
 (0)