Skip to content

Commit d4525c9

Browse files
committed
Revert to ConcurrentDictionary
1 parent d2dffd3 commit d4525c9

File tree

3 files changed

+20
-143
lines changed

3 files changed

+20
-143
lines changed

Rubberduck.Parsing/Rubberduck.Parsing.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
<Compile Include="Symbols\MsFormsLib.cs" />
9191
<Compile Include="Symbols\ValuedDeclaration.cs" />
9292
<Compile Include="Symbols\VbaStandardLib.cs" />
93-
<Compile Include="VBA\ConcurrentHashSet.cs" />
9493
<Compile Include="VBA\Nodes\INode.cs" />
9594
<Compile Include="VBA\Nodes\Node.cs" />
9695
<Compile Include="VBA\Nodes\ProcedureNode.cs" />

Rubberduck.Parsing/VBA/ConcurrentHashSet.cs

Lines changed: 0 additions & 117 deletions
This file was deleted.

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111

1212
namespace Rubberduck.Parsing.VBA
1313
{
14+
public enum ResolutionState
15+
{
16+
Unresolved
17+
}
18+
1419
public class RubberduckParserState
1520
{
1621
// keys are the declarations; values indicate whether a declaration is resolved.
17-
private readonly ConcurrentHashSet<Declaration> _declarations =
18-
new ConcurrentHashSet<Declaration>();
22+
private readonly ConcurrentDictionary<Declaration, ResolutionState> _declarations =
23+
new ConcurrentDictionary<Declaration, ResolutionState>();
1924

2025
private readonly ConcurrentDictionary<VBComponent, ITokenStream> _tokenStreams =
2126
new ConcurrentDictionary<VBComponent, ITokenStream>();
@@ -61,7 +66,7 @@ public ParserState GetModuleState(VBComponent component)
6166
}
6267

6368
private ParserState _status;
64-
public ParserState Status { get { return _status; } private set { if(_status != value) {_status = value; OnStateChanged();} } }
69+
public ParserState Status { get { return _status; } private set { if (_status != value) { _status = value; OnStateChanged(); } } }
6570

6671
private IEnumerable<QualifiedContext> _obsoleteCallContexts = new List<QualifiedContext>();
6772

@@ -90,7 +95,7 @@ public IEnumerable<QualifiedContext> ObsoleteLetContexts
9095

9196
public IEnumerable<CommentNode> Comments
9297
{
93-
get
98+
get
9499
{
95100
return _comments.Values.SelectMany(comments => comments);
96101
}
@@ -104,45 +109,34 @@ public void SetModuleComments(VBComponent component, IEnumerable<CommentNode> co
104109
/// <summary>
105110
/// Gets a copy of the collected declarations.
106111
/// </summary>
107-
public IEnumerable<Declaration> AllDeclarations { get { return _declarations; } }
112+
public IEnumerable<Declaration> AllDeclarations { get { return _declarations.Keys.ToList(); } }
108113

109114
/// <summary>
110115
/// Adds the specified <see cref="Declaration"/> to the collection (replaces existing).
111116
/// </summary>
112117
public void AddDeclaration(Declaration declaration)
113118
{
114-
if (_declarations.Add(declaration))
119+
if (_declarations.TryAdd(declaration, ResolutionState.Unresolved))
115120
{
116121
return;
117122
}
118123

119124
if (RemoveDeclaration(declaration))
120125
{
121-
_declarations.Add(declaration);
126+
_declarations.TryAdd(declaration, ResolutionState.Unresolved);
122127
}
123128
}
124129

125130
public void ClearDeclarations(VBComponent component)
126131
{
127-
var declarations = _declarations.Where(k =>
132+
var declarations = _declarations.Keys.Where(k =>
128133
k.QualifiedName.QualifiedModuleName.Project == component.Collection.Parent
129134
&& k.ComponentName == component.Name);
130135

131-
while (true)
136+
foreach (var declaration in declarations)
132137
{
133-
try
134-
{
135-
foreach (var declaration in declarations)
136-
{
137-
_declarations.Remove(declaration);
138-
}
139-
140-
return;
141-
}
142-
catch (InvalidOperationException)
143-
{
144-
145-
}
138+
ResolutionState state;
139+
_declarations.TryRemove(declaration, out state);
146140
}
147141
}
148142

@@ -170,7 +164,8 @@ public TokenStreamRewriter GetRewriter(VBComponent component)
170164
/// <returns>Returns true when successful.</returns>
171165
private bool RemoveDeclaration(Declaration declaration)
172166
{
173-
return _declarations.Remove(declaration);
167+
ResolutionState state;
168+
return _declarations.TryRemove(declaration, out state);
174169
}
175170

176171
/// <summary>
@@ -179,15 +174,15 @@ private bool RemoveDeclaration(Declaration declaration)
179174
/// </summary>
180175
public void AddBuiltInDeclarations(IHostApplication hostApplication)
181176
{
182-
if (_declarations.Any(declaration => declaration.IsBuiltIn))
177+
if (_declarations.Any(declaration => declaration.Key.IsBuiltIn))
183178
{
184179
return;
185180
}
186181

187182
var builtInDeclarations = VbaStandardLib.Declarations;
188183

189184
// cannot be strongly-typed here because of constraints on COM interop and generics in the inheritance hierarchy. </rant>
190-
if (hostApplication /*is ExcelApp*/ .ApplicationName == "Excel")
185+
if (hostApplication /*is ExcelApp*/ .ApplicationName == "Excel")
191186
{
192187
builtInDeclarations = builtInDeclarations.Concat(ExcelObjectModel.Declarations);
193188
}

0 commit comments

Comments
 (0)