Skip to content

Commit 940c3cf

Browse files
committed
Removed GetContenHash from QualifiedModuleName, since it is basically always stale.
1 parent 0a4c479 commit 940c3cf

File tree

4 files changed

+20
-45
lines changed

4 files changed

+20
-45
lines changed

Rubberduck.Parsing/VBA/ParseRunnerBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ private void ProcessComponentParseResults(QualifiedModuleName module, Task<Compo
103103
var result = finishedParseTask.Result;
104104
lock (_state)
105105
{
106-
_state.SetModuleAttributes(module, result.Attributes);
106+
token.ThrowIfCancellationRequested();
107+
_state.SetModuleAttributes(module, result.Attributes); //This has to come first because it creates the module state if not present.
108+
_state.AddTokenStream(module, result.Tokens);
107109
_state.AddParseTree(module, result.ParseTree);
108110
_state.AddParseTree(module, result.AttributesTree, ParsePass.AttributesPass);
109-
_state.AddTokenStream(module, result.Tokens);
110111
_state.SetModuleComments(module, result.Comments);
111112
_state.SetModuleAnnotations(module, result.Annotations);
112113
_state.AddAttributesRewriter(module, result.AttributesRewriter);

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,13 +746,13 @@ private bool RemoveKeysFromCollections(IEnumerable<QualifiedModuleName> keys)
746746
public void AddTokenStream(QualifiedModuleName module, ITokenStream stream)
747747
{
748748
_moduleStates[module].SetTokenStream(ProjectsProvider.CodeModule(module), stream);
749+
_moduleStates[module].SetModuleContentHashCode(GetModuleContentHash(module));
749750
}
750751

751752
public void AddParseTree(QualifiedModuleName module, IParseTree parseTree, ParsePass pass = ParsePass.CodePanePass)
752753
{
753754
var key = module;
754755
_moduleStates[key].SetParseTree(parseTree, pass);
755-
_moduleStates[key].SetModuleContentHashCode(key.ContentHashCode);
756756
}
757757

758758
public IParseTree GetParseTree(QualifiedModuleName module, ParsePass pass = ParsePass.CodePanePass)
@@ -896,13 +896,21 @@ public bool IsNewOrModified(QualifiedModuleName key)
896896
if (_moduleStates.TryGetValue(key, out var moduleState))
897897
{
898898
// existing/modified
899-
return moduleState.IsNew || key.ContentHashCode != moduleState.ModuleContentHashCode;
899+
return moduleState.IsNew || GetModuleContentHash(key) != moduleState.ModuleContentHashCode;
900900
}
901901

902902
// new
903903
return true;
904904
}
905905

906+
private int GetModuleContentHash(QualifiedModuleName module)
907+
{
908+
var codeModule = ProjectsProvider.CodeModule(module);
909+
return codeModule != null && codeModule.CountOfLines > 0
910+
? codeModule.GetLines(1, codeModule.CountOfLines).GetHashCode()
911+
: 0;
912+
}
913+
906914
public Declaration FindSelectedDeclaration(ICodePane activeCodePane)
907915
{
908916
return DeclarationFinder?.FindSelectedDeclaration(activeCodePane);
@@ -936,7 +944,6 @@ public void AddAttributesRewriter(QualifiedModuleName module, IModuleRewriter at
936944
{
937945
var key = module;
938946
_moduleStates[key].SetAttributesRewriter(attributesRewriter);
939-
_moduleStates[key].SetModuleContentHashCode(key.ContentHashCode);
940947
}
941948

942949
private bool _isDisposed;

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,13 @@ public QualifiedModuleName(IVBProject project)
4040
_projectName = project.Name;
4141
ProjectPath = string.Empty;
4242
ProjectId = GetProjectId(project);
43-
ContentHashCode = 0;
4443
}
4544

4645
public QualifiedModuleName(IVBComponent component)
4746
{
4847
ComponentType = component.Type;
4948
_componentName = component.IsWrappingNullReference ? string.Empty : component.Name;
5049

51-
ContentHashCode = 0;
52-
if (!component.IsWrappingNullReference)
53-
{
54-
using (var module = component.CodeModule)
55-
{
56-
ContentHashCode = module.CountOfLines > 0
57-
? module.GetLines(1, module.CountOfLines).GetHashCode()
58-
: 0;
59-
}
60-
}
61-
6250
using (var components = component.Collection)
6351
{
6452
using (var project = components.Parent)
@@ -81,7 +69,6 @@ public QualifiedModuleName(string projectName, string projectPath, string compon
8169
ProjectId = $"{_projectName};{ProjectPath}".GetHashCode().ToString(CultureInfo.InvariantCulture);
8270
_componentName = componentName;
8371
ComponentType = ComponentType.ComComponent;
84-
ContentHashCode = 0;
8572
}
8673

8774
public QualifiedMemberName QualifyMemberName(string member)
@@ -91,8 +78,6 @@ public QualifiedMemberName QualifyMemberName(string member)
9178

9279
public ComponentType ComponentType { get; }
9380

94-
public int ContentHashCode { get; }
95-
9681
public string ProjectId { get; }
9782

9883
private readonly string _componentName;

RubberduckTests/VBEditor/ProjectsRepositoryTests.cs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,11 +1661,9 @@ public void CodeModulesGetDisposedOnDisposal()
16611661
var repository = TestRepository(vbe);
16621662
repository.Dispose();
16631663

1664-
//Generating a qmn from a component disposes the code module returned to get the content hash.
1665-
//Since the mocks always return the same mock, 1 additional disposal is expected for loading the repository.
16661664
foreach (var mock in mockCodeModules.Concat(otherMockCodeModules))
16671665
{
1668-
mock.Verify(m => m.Dispose(), Times.Exactly(2));
1666+
mock.Verify(m => m.Dispose(), Times.Once);
16691667
}
16701668
}
16711669

@@ -1918,12 +1916,9 @@ public void CodeModulesGetDisposedOnRefresh()
19181916
var repository = TestRepository(vbe);
19191917
repository.Refresh();
19201918

1921-
//Generating a qmn from a component disposes the code module returned to get the content hash.
1922-
//Since the mocks always return the same mock, 2 additional disposals are expected
1923-
//for loading the repository twice (initial + refresh).
19241919
foreach (var mock in mockCodeModules.Concat(otherMockCodeModules))
19251920
{
1926-
mock.Verify(m => m.Dispose(), Times.Exactly(3));
1921+
mock.Verify(m => m.Dispose(), Times.Once);
19271922
}
19281923
}
19291924

@@ -1948,12 +1943,9 @@ public void CodeModulesInProjectWithMatchingProjectIdGetDisposedOnRefreshForProj
19481943
var repository = TestRepository(vbe);
19491944
repository.Refresh(project.ProjectId);
19501945

1951-
//Generating a qmn from a component disposes the code module returned to get the content hash.
1952-
//Since the mocks always return the same mock, 2 additional disposals are expected
1953-
//for loading the repository twice (initial + refresh).
19541946
foreach (var mock in mockCodeModules)
19551947
{
1956-
mock.Verify(m => m.Dispose(), Times.Exactly(3));
1948+
mock.Verify(m => m.Dispose(), Times.Once);
19571949
}
19581950
}
19591951

@@ -1978,11 +1970,9 @@ public void CodeModulesInProjectWithOtherProjectIdDoNotGetDisposedOnRefreshForPr
19781970
var repository = TestRepository(vbe);
19791971
repository.Refresh(project.ProjectId);
19801972

1981-
//Generating a qmn from a component disposes the code module returned to get the content hash.
1982-
//Since the mocks always return the same mock, 1 additional disposal is expected for loading the repository.
19831973
foreach (var mock in otherMockCodeModules)
19841974
{
1985-
mock.Verify(m => m.Dispose(), Times.Once);
1975+
mock.Verify(m => m.Dispose(), Times.Never);
19861976
}
19871977
}
19881978

@@ -2010,10 +2000,7 @@ public void RemovedCodeModulesGetDisposedOnRefresh()
20102000
project.VBComponents.Remove(component2);
20112001
repository.Refresh();
20122002

2013-
//Generating a qmn from a component disposes the code module returned to get the content hash.
2014-
//Since the mocks always return the same mock, 2 additional disposals are expected
2015-
//for loading the repository (initial).
2016-
codeModule2Mock.Verify(m => m.Dispose(), Times.Exactly(2));
2003+
codeModule2Mock.Verify(m => m.Dispose(), Times.Once);
20172004
}
20182005

20192006
[Test()]
@@ -2041,10 +2028,7 @@ public void RemovedCodeModulesGetDisposedOnRefreshForProjectIdOfFormerlyContaini
20412028
project.VBComponents.Remove(component2);
20422029
repository.Refresh(project.ProjectId);
20432030

2044-
//Generating a qmn from a component disposes the code module returned to get the content hash.
2045-
//Since the mocks always return the same mock, 2 additional disposals are expected
2046-
//for loading the repository (initial).
2047-
codeModule2Mock.Verify(m => m.Dispose(), Times.Exactly(2));
2031+
codeModule2Mock.Verify(m => m.Dispose(), Times.Once);
20482032
}
20492033

20502034
[Test()]
@@ -2073,9 +2057,7 @@ public void RemovedCodeModulesDoNotGetDisposedOnRefreshForOtherProjectId()
20732057
project.VBComponents.Remove(component2);
20742058
repository.Refresh(otherProject.ProjectId);
20752059

2076-
//Generating a qmn from a component disposes the code module returned to get the content hash.
2077-
//Since the mocks always return the same mock, 1 additional disposal is expected for loading the repository.
2078-
codeModule2Mock.Verify(m => m.Dispose(), Times.Once);
2060+
codeModule2Mock.Verify(m => m.Dispose(), Times.Never);
20792061
}
20802062

20812063
[Test()]

0 commit comments

Comments
 (0)