Skip to content

Commit 1bd3826

Browse files
authored
Merge pull request #387 from LogExperts/smalloptimizations
small optimizations
2 parents edb43b7 + 3b97d5d commit 1bd3826

37 files changed

Lines changed: 488 additions & 477 deletions

src/ColumnizerLib/IContextMenuEntry.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace LogExpert
55
{
66
/// <summary>
7-
/// Implement this interface to add a menu entry to the context menu of LogExpert.
7+
/// Implement this interface to add a menu entry to the context menu of LogExpert.
88
/// </summary>
99
/// <remarks>
1010
/// <para>
@@ -17,12 +17,12 @@ public interface IContextMenuEntry
1717
#region Public methods
1818

1919
/// <summary>
20-
/// This function is called from LogExpert if the context menu is about to be displayed.
20+
/// This function is called from LogExpert if the context menu is about to be displayed.
2121
/// Your implementation can control whether LogExpert will show a menu entry by returning
2222
/// an appropriate value.<br></br>
2323
/// </summary>
2424
/// <param name="lines">A list containing all selected line numbers.</param>
25-
/// <param name="columnizer">The currently selected Columnizer. You can use it to split log lines,
25+
/// <param name="columnizer">The currently selected Columnizer. You can use it to split log lines,
2626
/// if necessary.</param>
2727
/// <param name="callback">The callback interface implemented by LogExpert. You can use the functions
2828
/// for retrieving log lines or pass it along to functions of the Columnizer if needed.</param>
@@ -37,18 +37,22 @@ public interface IContextMenuEntry
3737
/// </returns>
3838
string GetMenuText(IList<int> lines, ILogLineColumnizer columnizer, ILogExpertCallback callback);
3939

40+
string GetMenuText(int linesCount, ILogLineColumnizer columnizer, ILogLine line);
41+
4042

4143
/// <summary>
4244
/// This function is called from LogExpert if the menu entry is choosen by the user. <br></br>
4345
/// Note that this function is called from the GUI thread. So try to avoid time consuming operations.
4446
/// </summary>
4547
/// <param name="lines">A list containing all selected line numbers.</param>
46-
/// <param name="columnizer">The currently selected Columnizer. You can use it to split log lines,
48+
/// <param name="columnizer">The currently selected Columnizer. You can use it to split log lines,
4749
/// if necessary.</param>
4850
/// <param name="callback">The callback interface implemented by LogExpert. You can use the functions
4951
/// for retrieving log lines or pass it along to functions of the Columnizer if needed.</param>
5052
void MenuSelected(IList<int> lines, ILogLineColumnizer columnizer, ILogExpertCallback callback);
5153

54+
void MenuSelected(int linesCount, ILogLineColumnizer columnizer, ILogLine line);
55+
5256
#endregion
5357
}
5458
}

src/ColumnizerLib/ILogExpertCallback.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface ILogExpertCallback : ILogLineColumnizerCallback
1717
/// <param name="fileName">Path of the file to be loaded.</param>
1818
/// <param name="title">Title shown on the tab.</param>
1919
/// <remarks>
20-
/// The file tab is internally handled like the temp file tabs which LogExpert uses for
20+
/// The file tab is internally handled like the temp file tabs which LogExpert uses for
2121
/// FilterTabs or clipboard copy tabs.
2222
/// This has some implications:
2323
/// <ul>
@@ -29,24 +29,23 @@ public interface ILogExpertCallback : ILogLineColumnizerCallback
2929
/// </remarks>
3030
void AddTempFileTab(string fileName, string title);
3131

32-
3332
/// <summary>
3433
/// With this function you can create a new tab and add a bunch of text lines to it.
3534
/// </summary>
36-
/// <param name="lineEntryList">A list with LineEntry items containing text and an
35+
/// <param name="lineEntryList">A list with LineEntry items containing text and an
3736
/// optional reference to the original file location.</param>
3837
/// <param name="title">The title for the new tab.</param>
3938
/// <remarks>
4039
/// <para>
4140
/// The lines are given by a list of <see cref="LineEntry"/>. If you set the lineNumber field
42-
/// in each LineEntry to a lineNumber of the original logfile (the logfile for which the context
41+
/// in each LineEntry to a lineNumber of the original logfile (the logfile for which the context
4342
/// menu is called for), you can create a 'link' from the line of your 'target output' to a line
4443
/// in the 'source tab'.
4544
/// </para>
4645
/// <para>
4746
/// The user can then navigate from the line in the new tab to the referenced
4847
/// line in the original file (by using "locate in original file" from the context menu).
49-
/// This is especially useful for plugins that generate output lines which are directly associated
48+
/// This is especially useful for plugins that generate output lines which are directly associated
5049
/// to the selected input lines.
5150
/// </para>
5251
/// <para>
@@ -56,7 +55,6 @@ public interface ILogExpertCallback : ILogLineColumnizerCallback
5655
/// </remarks>
5756
void AddPipedTab(IList<LineEntry> lineEntryList, string title);
5857

59-
6058
/// <summary>
6159
/// Returns the title of the current tab (the tab for which the context menu plugin was called for).
6260
/// </summary>

src/ColumnizerLib/ILogFileInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System.IO;
21
using System;
2+
using System.IO;
33

44
namespace LogExpert
55
{

src/ColumnizerLib/ILogLineColumnizerCallback.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace LogExpert
1+
namespace LogExpert
62
{
73
///<summary>
84
///This is a callback interface. Some of the ILogLineColumnizer functions

src/DefaultPlugins/Eminus.cs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public class Eminus : IContextMenuEntry, ILogExpertPluginConfigurator
1717
#region Fields
1818

1919
private const string CFG_FILE_NAME = "eminus.json";
20-
private const string dot = ".";
21-
private const string doubleDot = ":";
20+
private const string DOT = ".";
21+
private const string DOUBLE_DOT = ":";
22+
private const string DISABLED = "_";
23+
2224
private EminusConfig _config = new();
2325
private EminusConfigDlg dlg;
2426
private EminusConfig tmpConfig = new();
@@ -27,48 +29,50 @@ public class Eminus : IContextMenuEntry, ILogExpertPluginConfigurator
2729

2830
#region Properties
2931

30-
public string Text => "eminus";
32+
public static string Text => "eminus";
3133

3234
#endregion
3335

3436
#region Private Methods
3537

3638
private XmlDocument BuildParam(ILogLine line)
3739
{
38-
string temp = line.FullLine;
40+
string fullLogLine = line.FullLine;
3941
// no Java stacktrace but some special logging of our applications at work:
40-
if (temp.Contains("Exception of type", StringComparison.CurrentCulture) || temp.Contains("Nested:", StringComparison.CurrentCulture))
42+
if (fullLogLine.Contains("Exception of type", StringComparison.CurrentCulture) ||
43+
fullLogLine.Contains("Nested:", StringComparison.CurrentCulture))
4144
{
42-
int pos = temp.IndexOf("created in ");
45+
int pos = fullLogLine.IndexOf("created in ");
46+
4347
if (pos == -1)
4448
{
4549
return null;
4650
}
4751

4852
pos += "created in ".Length;
49-
int endPos = temp.IndexOf(dot, pos);
53+
int endPos = fullLogLine.IndexOf(DOT, pos);
5054

5155
if (endPos == -1)
5256
{
5357
return null;
5458
}
5559

56-
string className = temp[pos..endPos];
57-
pos = temp.IndexOf(doubleDot, pos);
60+
string className = fullLogLine[pos..endPos];
61+
pos = fullLogLine.IndexOf(DOUBLE_DOT, pos);
5862

5963
if (pos == -1)
6064
{
6165
return null;
6266
}
6367

64-
string lineNum = temp[(pos + 1)..];
68+
string lineNum = fullLogLine[(pos + 1)..];
6569
XmlDocument doc = BuildXmlDocument(className, lineNum);
6670
return doc;
6771
}
6872

69-
if (temp.Contains("at ", StringComparison.CurrentCulture))
73+
if (fullLogLine.Contains("at ", StringComparison.CurrentCulture))
7074
{
71-
string str = temp.Trim();
75+
string str = fullLogLine.Trim();
7276
string className = null;
7377
string lineNum = null;
7478
int pos = str.IndexOf("at ") + 3;
@@ -83,15 +87,15 @@ private XmlDocument BuildParam(ILogLine line)
8387
}
8488
else
8589
{
86-
pos = str.LastIndexOf('.', idx);
90+
pos = str.LastIndexOf(DOT, idx);
8791
if (pos == -1)
8892
{
8993
return null;
9094
}
9195
className = str[..pos];
9296
}
9397

94-
idx = str.LastIndexOf(':');
98+
idx = str.LastIndexOf(DOUBLE_DOT);
9599

96100
if (idx == -1)
97101
{
@@ -150,24 +154,36 @@ private XmlDocument BuildXmlDocument(string className, string lineNum)
150154

151155
public string GetMenuText(IList<int> logLines, ILogLineColumnizer columnizer, ILogExpertCallback callback)
152156
{
153-
if (logLines.Count == 1 && BuildParam(callback.GetLogLine(logLines[0])) != null)
157+
//not used
158+
return string.Empty;
159+
}
160+
161+
public string GetMenuText(int logLinesCount, ILogLineColumnizer columnizer, ILogLine logline)
162+
{
163+
if (logLinesCount == 1 && BuildParam(logline) != null)
154164
{
155165
return "Load class in Eclipse";
156166
}
157167
else
158168
{
159-
return "_Load class in Eclipse";
169+
return $"{DISABLED}Load class in Eclipse";
160170
}
161171
}
162172

163173
public void MenuSelected(IList<int> logLines, ILogLineColumnizer columnizer, ILogExpertCallback callback)
164174
{
165-
if (logLines.Count != 1)
175+
//Not used
176+
}
177+
178+
public void MenuSelected(int logLinesCount, ILogLineColumnizer columnizer, ILogLine logline)
179+
{
180+
if (logLinesCount != 1)
166181
{
167182
return;
168183
}
169184

170-
XmlDocument doc = BuildParam(callback.GetLogLine(logLines[0]));
185+
XmlDocument doc = BuildParam(logline);
186+
171187
if (doc == null)
172188
{
173189
MessageBox.Show("Cannot parse Java stack trace line", "LogExpert");

src/LogExpert/Classes/Filter/Filter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private int DoFilter(FilterParams filterParams, int startLine, int maxCount, Lis
7070
try
7171
{
7272
filterParams.Reset();
73-
while ((count++ < maxCount || filterParams.isInRange) && !ShouldCancel)
73+
while ((count++ < maxCount || filterParams.IsInRange) && !ShouldCancel)
7474
{
7575
if (lineNum >= _callback.GetLineCount())
7676
{
@@ -140,14 +140,14 @@ private IList<int> GetAdditionalFilterResults(FilterParams filterParams, int lin
140140
{
141141
IList<int> resultList = [];
142142

143-
if (filterParams.spreadBefore == 0 && filterParams.spreadBehind == 0)
143+
if (filterParams.SpreadBefore == 0 && filterParams.SpreadBehind == 0)
144144
{
145145
resultList.Add(lineNum);
146146
return resultList;
147147
}
148148

149149
// back spread
150-
for (int i = filterParams.spreadBefore; i > 0; --i)
150+
for (int i = filterParams.SpreadBefore; i > 0; --i)
151151
{
152152
if (lineNum - i > 0)
153153
{
@@ -163,7 +163,7 @@ private IList<int> GetAdditionalFilterResults(FilterParams filterParams, int lin
163163
resultList.Add(lineNum);
164164
}
165165
// after spread
166-
for (int i = 1; i <= filterParams.spreadBehind; ++i)
166+
for (int i = 1; i <= filterParams.SpreadBehind; ++i)
167167
{
168168
if (lineNum + i < _callback.GetLineCount())
169169
{

src/LogExpert/Classes/Filter/FilterStarter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private Filter DoWork(FilterParams filterParams, int startLine, int maxCount, Pr
149149
_logger.Info("Started Filter worker [{0}] for line {1}", Environment.CurrentManagedThreadId, startLine);
150150

151151
// Give every thread own copies of ColumnizerCallback and FilterParams, because the state of the objects changes while filtering
152-
FilterParams threadFilterParams = filterParams.CreateCopy2();
152+
FilterParams threadFilterParams = filterParams.CloneWithCurrentColumnizer();
153153
ColumnizerCallback threadColumnizerCallback = _callback.CreateCopy();
154154

155155
Filter filter = new(threadColumnizerCallback);

src/LogExpert/Classes/ILogLineColumnizerCallback/ColumnizerCallback.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ public class ColumnizerCallback : LogExpert.ILogLineColumnizerCallback, IAutoLog
88
{
99
#region Fields
1010

11-
protected LogWindow logWindow;
11+
protected LogWindow _logWindow;
1212

1313
#endregion
1414

1515
#region cTor
1616

1717
public ColumnizerCallback(LogWindow logWindow)
1818
{
19-
this.logWindow = logWindow;
19+
_logWindow = logWindow;
2020
}
2121

2222
private ColumnizerCallback(ColumnizerCallback original)
2323
{
24-
logWindow = original.logWindow;
24+
_logWindow = original._logWindow;
2525
LineNum = original.LineNum;
2626
}
2727

@@ -47,12 +47,12 @@ public int GetLineNum()
4747

4848
public string GetFileName()
4949
{
50-
return logWindow.GetCurrentFileName(LineNum);
50+
return _logWindow.GetCurrentFileName(LineNum);
5151
}
5252

5353
public ILogLine GetLogLine(int lineNum)
5454
{
55-
return logWindow.GetLine(lineNum);
55+
return _logWindow.GetLine(lineNum);
5656
}
5757

5858
public IList<ILogLineColumnizer> GetRegisteredColumnizers()
@@ -62,7 +62,7 @@ public IList<ILogLineColumnizer> GetRegisteredColumnizers()
6262

6363
public int GetLineCount()
6464
{
65-
return logWindow._logFileReader.LineCount;
65+
return _logWindow._logFileReader.LineCount;
6666
}
6767

6868
#endregion

src/LogExpert/Classes/ILogLineColumnizerCallback/LogExpertCallback.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,23 @@
44

55
namespace LogExpert.Classes.ILogLineColumnizerCallback
66
{
7-
internal class LogExpertCallback : ColumnizerCallback, ILogExpertCallback
7+
internal class LogExpertCallback(LogWindow logWindow) : ColumnizerCallback(logWindow), ILogExpertCallback
88
{
9-
#region cTor
10-
11-
public LogExpertCallback(LogWindow logWindow)
12-
: base(logWindow)
13-
{
14-
}
15-
16-
#endregion
17-
189
#region Public methods
1910

2011
public void AddTempFileTab(string fileName, string title)
2112
{
22-
logWindow.AddTempFileTab(fileName, title);
13+
_logWindow.AddTempFileTab(fileName, title);
2314
}
2415

2516
public void AddPipedTab(IList<LineEntry> lineEntryList, string title)
2617
{
27-
logWindow.WritePipeTab(lineEntryList, title);
18+
_logWindow.WritePipeTab(lineEntryList, title);
2819
}
2920

3021
public string GetTabTitle()
3122
{
32-
return logWindow.Text;
23+
return _logWindow.Text;
3324
}
3425

3526
#endregion

src/LogExpert/Classes/Log/LogfileReader.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public class LogfileReader : IAutoLogLineColumnizerCallback
5353

5454
private ReaderWriterLock _lruCacheDictLock;
5555

56-
5756
private bool _shouldStop;
5857
private ILogFileInfo _watchedILogFileInfo;
5958

0 commit comments

Comments
 (0)