[Modify] Use the LinkedList<T> class instead

This commit is contained in:
sta 2021-04-09 19:42:19 +09:00
parent 5b1f6be258
commit 5aa03ab838

View File

@ -68,7 +68,7 @@ namespace WebSocketSharp.Net
private object _connectionsSync; private object _connectionsSync;
private List<HttpListenerContext> _ctxQueue; private List<HttpListenerContext> _ctxQueue;
private object _ctxQueueSync; private object _ctxQueueSync;
private Dictionary<HttpListenerContext, HttpListenerContext> _contextRegistry; private LinkedList<HttpListenerContext> _contextRegistry;
private object _contextRegistrySync; private object _contextRegistrySync;
private static readonly string _defaultRealm; private static readonly string _defaultRealm;
private bool _disposed; private bool _disposed;
@ -109,7 +109,7 @@ namespace WebSocketSharp.Net
_ctxQueue = new List<HttpListenerContext> (); _ctxQueue = new List<HttpListenerContext> ();
_ctxQueueSync = ((ICollection) _ctxQueue).SyncRoot; _ctxQueueSync = ((ICollection) _ctxQueue).SyncRoot;
_contextRegistry = new Dictionary<HttpListenerContext, HttpListenerContext> (); _contextRegistry = new LinkedList<HttpListenerContext> ();
_contextRegistrySync = ((ICollection) _contextRegistry).SyncRoot; _contextRegistrySync = ((ICollection) _contextRegistry).SyncRoot;
_logger = new Logger (); _logger = new Logger ();
@ -468,9 +468,8 @@ namespace WebSocketSharp.Net
return; return;
// Need to copy this since closing will call the UnregisterContext method. // Need to copy this since closing will call the UnregisterContext method.
var keys = _contextRegistry.Keys; ctxs = new HttpListenerContext[_contextRegistry.Count];
ctxs = new HttpListenerContext[keys.Count]; _contextRegistry.CopyTo (ctxs, 0);
keys.CopyTo (ctxs, 0);
_contextRegistry.Clear (); _contextRegistry.Clear ();
} }
@ -605,7 +604,7 @@ namespace WebSocketSharp.Net
if (!_listening) if (!_listening)
return false; return false;
_contextRegistry[context] = context; _contextRegistry.AddLast (context);
var ares = getAsyncResultFromQueue (); var ares = getAsyncResultFromQueue ();