-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Switch off of mutlidictionary #78851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,11 @@ | |
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.ComponentModel.Composition; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using ICSharpCode.Decompiler.Util; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.Collections; | ||
| using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
|
|
@@ -44,7 +44,7 @@ internal sealed partial class RootSymbolTreeItemSourceProvider : AttachedCollect | |
| /// of that file through that project. | ||
| /// </summary> | ||
| /// <remarks>Lock this instance when reading/writing as it is used over different threads.</remarks> | ||
| private readonly MultiDictionary<string, RootSymbolTreeItemCollectionSource> _filePathToCollectionSources = new( | ||
| private readonly Dictionary<string, List<RootSymbolTreeItemCollectionSource>> _filePathToCollectionSources = new( | ||
| StringComparer.OrdinalIgnoreCase); | ||
|
|
||
| /// <summary> | ||
|
|
@@ -166,7 +166,9 @@ await source.UpdateIfEverExpandedAsync(cancellationToken) | |
|
|
||
| var source = new RootSymbolTreeItemCollectionSource(this, item); | ||
| lock (_filePathToCollectionSources) | ||
| _filePathToCollectionSources.Add(currentFilePath, source); | ||
| { | ||
| AddToDictionary(currentFilePath, source); | ||
| } | ||
|
|
||
| // Register to hear about if this hierarchy is disposed. We'll stop watching it if so. | ||
| item.PropertyChanged += OnItemPropertyChanged; | ||
|
|
@@ -181,7 +183,7 @@ void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e) | |
| // event for the IsDisposed property. When this fires, we remove the filePath->sourcce mapping we're holding. | ||
| lock (_filePathToCollectionSources) | ||
| { | ||
| _filePathToCollectionSources.Remove(currentFilePath, source); | ||
| RemoveFromDictionary(currentFilePath, source); | ||
| } | ||
|
|
||
| item.PropertyChanged -= OnItemPropertyChanged; | ||
|
|
@@ -195,8 +197,8 @@ void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e) | |
| { | ||
|
|
||
| // Unlink the oldPath->source mapping, and add a new line for the newPath->source. | ||
| _filePathToCollectionSources.Remove(currentFilePath, source); | ||
| _filePathToCollectionSources.Add(newPath, source); | ||
| RemoveFromDictionary(currentFilePath, source); | ||
| AddToDictionary(newPath, source); | ||
|
|
||
| // Keep track of the 'newPath'. | ||
| currentFilePath = newPath; | ||
|
|
@@ -211,5 +213,29 @@ void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e) | |
| } | ||
| } | ||
| } | ||
|
|
||
| void AddToDictionary(string currentFilePath, RootSymbolTreeItemCollectionSource source) | ||
| { | ||
| if (!_filePathToCollectionSources.TryGetValue(currentFilePath, out var sources)) | ||
| { | ||
| sources = []; | ||
| _filePathToCollectionSources[currentFilePath] = sources; | ||
| } | ||
|
|
||
| sources.Add(source); | ||
| } | ||
|
|
||
| void RemoveFromDictionary(string currentFilePath, RootSymbolTreeItemCollectionSource source) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (feel free to ignore since this is impacting RPS) ...and MultiRemove from the same file as above. |
||
| { | ||
| if (_filePathToCollectionSources.TryGetValue(currentFilePath, out var sources)) | ||
| { | ||
| sources.Remove(source); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should probably remove the key as well if there are no more sources. Otherwise on renames we're going to be leaving old file paths around in the dictionary. Looks like the multidictionary previously removed the key as well - https://github.com/icsharpcode/ILSpy/blob/master/ICSharpCode.Decompiler/Util/MultiDictionary.cs#L59 |
||
|
|
||
| if (sources.Count == 0) | ||
| { | ||
| _filePathToCollectionSources.Remove(currentFilePath); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(feel free to ignore since this is impacting RPS)
You can use
https://github.com/jasonmalinowski/roslyn/blob/ef33d325804d8743dfed9c9a1a4eec249a8a6ab9/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IDictionaryExtensions.cs?plain=1#L63C1-L74C6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know for the future, thanks.