diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs index f4f0fe9fff462..bf171b81c888c 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/XmlCompatibilityReader.cs @@ -1727,7 +1727,7 @@ private sealed class ProcessContentSet private bool _all; private readonly string _namespaceName; private readonly XmlCompatibilityReader _reader; - private Dictionary? _names; + private HashSet? _names; public ProcessContentSet(string namespaceName, XmlCompatibilityReader reader) { @@ -1737,7 +1737,7 @@ public ProcessContentSet(string namespaceName, XmlCompatibilityReader reader) public bool ShouldProcessContent(string elementName) { - return _all || (_names != null && _names.ContainsKey(elementName)); + return _all || (_names != null && _names.Contains(elementName)); } public void Add(string elementName) @@ -1767,8 +1767,8 @@ public void Add(string elementName) } else { - _names ??= new Dictionary(); - _names[elementName] = null; // we don't care about value, just key + _names ??= new HashSet(); + _names.Add(elementName); } } } @@ -1778,7 +1778,7 @@ private sealed class PreserveItemSet private bool _all; private readonly string _namespaceName; private readonly XmlCompatibilityReader _reader; - private Dictionary? _names; + private HashSet? _names; public PreserveItemSet(string namespaceName, XmlCompatibilityReader reader) { @@ -1788,7 +1788,7 @@ public PreserveItemSet(string namespaceName, XmlCompatibilityReader reader) public bool ShouldPreserveItem(string itemName) { - return _all || (_names != null && _names.ContainsKey(itemName)); + return _all || (_names != null && _names.Contains(itemName)); } public void Add(string itemName) @@ -1818,8 +1818,8 @@ public void Add(string itemName) } else { - _names ??= new Dictionary(); - _names.Add(itemName, itemName); + _names ??= new HashSet(); + _names.Add(itemName); } } } diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointListener.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointListener.cs index 29169e0022336..ba31a7cf9af04 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointListener.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointListener.cs @@ -42,7 +42,7 @@ internal sealed class HttpEndPointListener private readonly HttpListener _listener; private readonly IPEndPoint _endpoint; private readonly Socket _socket; - private readonly Dictionary _unregisteredConnections; + private readonly HashSet _unregisteredConnections; private Dictionary _prefixes; private List? _unhandledPrefixes; // host = '*' private List? _allPrefixes; // host = '+' @@ -70,7 +70,7 @@ public HttpEndPointListener(HttpListener listener, IPAddress addr, int port, boo Accept(args); _prefixes = new Dictionary(); - _unregisteredConnections = new Dictionary(); + _unregisteredConnections = new HashSet(); } internal HttpListener Listener @@ -131,7 +131,7 @@ private void ProcessAccept(SocketAsyncEventArgs args) lock (_unregisteredConnections) { - _unregisteredConnections[conn] = conn; + _unregisteredConnections.Add(conn); } conn.BeginReadRequest(); } @@ -309,7 +309,7 @@ public void Close() lock (_unregisteredConnections) { // Clone the list because RemoveConnection can be called from Close - var connections = new List(_unregisteredConnections.Keys); + var connections = new List(_unregisteredConnections); foreach (HttpConnection c in connections) c.Close(true); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs index 14246f4e8b83c..b169310c64c0c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs @@ -260,7 +260,7 @@ private enum InitInputType private long _charactersFromEntities; // All entities that are currently being processed - private Dictionary? _currentEntities; + private HashSet? _currentEntities; // DOM helpers private bool _disableUndeclaredEntityCheck; @@ -8062,7 +8062,7 @@ private void RegisterEntity(IDtdEntityInfo entity) // check entity recursion if (_currentEntities != null) { - if (_currentEntities.ContainsKey(entity)) + if (_currentEntities.Contains(entity)) { Throw(entity.IsParameterEntity ? SR.Xml_RecursiveParEntity : SR.Xml_RecursiveGenEntity, entity.Name, _parsingStatesStack![_parsingStatesStackTop].LineNo, _parsingStatesStack[_parsingStatesStackTop].LinePos); @@ -8076,9 +8076,9 @@ private void RegisterEntity(IDtdEntityInfo entity) // register entity for recursion checkes if (entity != null) { - _currentEntities ??= new Dictionary(); + _currentEntities ??= new HashSet(); - _currentEntities.Add(entity, entity); + _currentEntities.Add(entity); } }