Skip to content

Commit c6584ef

Browse files
Replace Dictionary with HashSet (#7486)
* Replace Dictionary with HashSet * Use UnionWith and EnumerateFiles
1 parent 6a40b33 commit c6584ef

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontSourceCollection.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private void SetFontSources()
137137
{
138138
// fontPaths accumulates font file paths obtained from the registry and the file system
139139
// This collection is a set, i.e. only keys matter, not values.
140-
Dictionary<string, object> fontPaths = new Dictionary<string, object>(512, StringComparer.OrdinalIgnoreCase);
140+
HashSet<string> fontPaths = new HashSet<string>(512, StringComparer.OrdinalIgnoreCase);
141141

142142
using (RegistryKey fontsKey = Registry.LocalMachine.OpenSubKey(InstalledWindowsFontsRegistryKey))
143143
{
@@ -154,16 +154,14 @@ private void SetFontSources()
154154
if (Path.GetFileName(fileName) == fileName)
155155
fileName = Path.Combine(Util.WindowsFontsLocalPath, fileName);
156156

157-
fontPaths[fileName] = null;
157+
fontPaths.Add(fileName);
158158
}
159159
}
160160
}
161161

162-
foreach (string file in Directory.GetFiles(_uri.LocalPath))
163-
{
164-
fontPaths[file] = null;
165-
}
166-
files = fontPaths.Keys;
162+
fontPaths.UnionWith(Directory.EnumerateFiles(_uri.LocalPath));
163+
164+
files = fontPaths;
167165
}
168166
}
169167
else

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlCompatibilityReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ class ProcessContentSet
19171917
bool _all;
19181918
string _namespaceName;
19191919
XmlCompatibilityReader _reader;
1920-
Dictionary<string, object> _names;
1920+
HashSet<string> _names;
19211921

19221922
public ProcessContentSet(string namespaceName, XmlCompatibilityReader reader)
19231923
{
@@ -1927,7 +1927,7 @@ public ProcessContentSet(string namespaceName, XmlCompatibilityReader reader)
19271927

19281928
public bool ShouldProcessContent(string elementName)
19291929
{
1930-
return _all || (_names != null && _names.ContainsKey(elementName));
1930+
return _all || (_names != null && _names.Contains(elementName));
19311931
}
19321932

19331933
public void Add(string elementName)
@@ -1959,10 +1959,10 @@ public void Add(string elementName)
19591959
{
19601960
if (_names == null)
19611961
{
1962-
_names = new Dictionary<string, object>();
1962+
_names = new HashSet<string>();
19631963
}
19641964

1965-
_names[elementName] = null; // we don't care about value, just key
1965+
_names.Add(elementName);
19661966
}
19671967
}
19681968
}

0 commit comments

Comments
 (0)