Skip to content
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

Using HashSet instead of Dictionary multiple times #96573

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ private sealed class ProcessContentSet
private bool _all;
private readonly string _namespaceName;
private readonly XmlCompatibilityReader _reader;
private Dictionary<string, object?>? _names;
private HashSet<string>? _names;

public ProcessContentSet(string namespaceName, XmlCompatibilityReader reader)
{
Expand All @@ -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)
Expand Down Expand Up @@ -1767,8 +1767,8 @@ public void Add(string elementName)
}
else
{
_names ??= new Dictionary<string, object?>();
_names[elementName] = null; // we don't care about value, just key
_names ??= new HashSet<string>();
_names.Add(elementName);
}
}
}
Expand All @@ -1778,7 +1778,7 @@ private sealed class PreserveItemSet
private bool _all;
private readonly string _namespaceName;
private readonly XmlCompatibilityReader _reader;
private Dictionary<string, string>? _names;
private HashSet<string>? _names;

public PreserveItemSet(string namespaceName, XmlCompatibilityReader reader)
{
Expand All @@ -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)
Expand Down Expand Up @@ -1818,8 +1818,8 @@ public void Add(string itemName)
}
else
{
_names ??= new Dictionary<string, string>();
_names.Add(itemName, itemName);
_names ??= new HashSet<string>();
_names.Add(itemName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal sealed class HttpEndPointListener
private readonly HttpListener _listener;
private readonly IPEndPoint _endpoint;
private readonly Socket _socket;
private readonly Dictionary<HttpConnection, HttpConnection> _unregisteredConnections;
private readonly HashSet<HttpConnection> _unregisteredConnections;
private Dictionary<ListenerPrefix, HttpListener> _prefixes;
private List<ListenerPrefix>? _unhandledPrefixes; // host = '*'
private List<ListenerPrefix>? _allPrefixes; // host = '+'
Expand Down Expand Up @@ -70,7 +70,7 @@ public HttpEndPointListener(HttpListener listener, IPAddress addr, int port, boo
Accept(args);

_prefixes = new Dictionary<ListenerPrefix, HttpListener>();
_unregisteredConnections = new Dictionary<HttpConnection, HttpConnection>();
_unregisteredConnections = new HashSet<HttpConnection>();
}

internal HttpListener Listener
Expand Down Expand Up @@ -131,7 +131,7 @@ private void ProcessAccept(SocketAsyncEventArgs args)

lock (_unregisteredConnections)
{
_unregisteredConnections[conn] = conn;
_unregisteredConnections.Add(conn);
}
conn.BeginReadRequest();
}
Expand Down Expand Up @@ -309,7 +309,7 @@ public void Close()
lock (_unregisteredConnections)
{
// Clone the list because RemoveConnection can be called from Close
var connections = new List<HttpConnection>(_unregisteredConnections.Keys);
var connections = new List<HttpConnection>(_unregisteredConnections);

foreach (HttpConnection c in connections)
c.Close(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private enum InitInputType
private long _charactersFromEntities;

// All entities that are currently being processed
private Dictionary<IDtdEntityInfo, IDtdEntityInfo>? _currentEntities;
private HashSet<IDtdEntityInfo>? _currentEntities;

// DOM helpers
private bool _disableUndeclaredEntityCheck;
Expand Down Expand Up @@ -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);
Expand All @@ -8076,9 +8076,9 @@ private void RegisterEntity(IDtdEntityInfo entity)
// register entity for recursion checkes
if (entity != null)
{
_currentEntities ??= new Dictionary<IDtdEntityInfo, IDtdEntityInfo>();
_currentEntities ??= new HashSet<IDtdEntityInfo>();

_currentEntities.Add(entity, entity);
_currentEntities.Add(entity);
}
}

Expand Down
Loading