Skip to content

Commit 3440fc0

Browse files
committed
Improve performance in ImplicitByRefParameter inspection to make the inspections load fast(er)
1 parent 76f2fd4 commit 3440fc0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ public ImplicitByRefParameterInspection(RubberduckParserState state)
2121

2222
public override IEnumerable<InspectionResultBase> GetInspectionResults()
2323
{
24-
var interfaceMembers = UserDeclarations.FindInterfaceImplementationMembers();
24+
var interfaceMembersScope = UserDeclarations.FindInterfaceImplementationMembers().Select(m => m.Scope);
25+
var builtinEventHandlers = State.AllDeclarations.FindBuiltInEventHandlers();
2526

2627
var issues = (from item in UserDeclarations
2728
where
2829
!item.IsInspectionDisabled(AnnotationName)
2930
&& item.DeclarationType == DeclarationType.Parameter
3031
// ParamArray parameters do not allow an explicit "ByRef" parameter mechanism.
3132
&& !((ParameterDeclaration)item).IsParamArray
32-
&& !interfaceMembers.Select(m => m.Scope).Contains(item.ParentScope)
33-
&& !State.AllDeclarations.FindBuiltInEventHandlers().Contains(item.ParentDeclaration)
33+
&& !interfaceMembersScope.Contains(item.ParentScope)
34+
&& !builtinEventHandlers.Contains(item.ParentDeclaration)
3435
let arg = item.Context as VBAParser.ArgContext
3536
where arg != null && arg.BYREF() == null && arg.BYVAL() == null
3637
select new QualifiedContext<VBAParser.ArgContext>(item.QualifiedName, arg))

RetailCoder.VBE/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Diagnostics;
45
using System.Globalization;
56
using System.IO;
67
using System.Linq;
@@ -260,6 +261,7 @@ private void _state_StateChanged(object sender, EventArgs e)
260261

261262
private async void RefreshInspections()
262263
{
264+
var stopwatch = Stopwatch.StartNew();
263265
IsBusy = true;
264266

265267
var results = (await _inspector.FindIssuesAsync(_state, CancellationToken.None)).ToList();
@@ -289,6 +291,9 @@ private async void RefreshInspections()
289291
IsBusy = false;
290292
SelectedItem = null;
291293
});
294+
295+
stopwatch.Stop();
296+
LogManager.GetCurrentClassLogger().Trace("Inspections loaded in {0}ms", stopwatch.ElapsedMilliseconds);
292297
}
293298

294299
private void ExecuteQuickFixes(IEnumerable<CodeInspectionQuickFix> quickFixes)

0 commit comments

Comments
 (0)