From 56a27c37d3e84495988e423be7b52007cea595cc Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 8 Oct 2009 21:51:53 -0700 Subject: Simplified LLUDPClientCollection from three collections down to one. This will prevent any potential problems from inconsistency between the internal collections --- .../ClientStack/LindenUDP/LLUDPClientCollection.cs | 75 ++++------------------ 1 file changed, 11 insertions(+), 64 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs index 06fa3e2..abf3882 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs @@ -40,14 +40,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP { #region IComparers - private sealed class UUIDComparer : IComparer - { - public int Compare(UUID x, UUID y) - { - return x.Guid.CompareTo(y.Guid); - } - } - private sealed class IPEndPointComparer : IComparer { public int Compare(IPEndPoint x, IPEndPoint y) @@ -60,91 +52,46 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion IComparers - private ImmutableMap m_dict1; - private ImmutableMap m_dict2; - private LLUDPClient[] m_array; + private ImmutableMap m_dict; public UDPClientCollection() { - m_dict1 = new ImmutableMap(new UUIDComparer()); - m_dict2 = new ImmutableMap(new IPEndPointComparer()); - m_array = new LLUDPClient[0]; + m_dict = new ImmutableMap(new IPEndPointComparer()); } - public void Add(UUID key1, IPEndPoint key2, LLUDPClient value) + public void Add(IPEndPoint key, LLUDPClient value) { - m_dict1 = m_dict1.Add(key1, value); - m_dict2 = m_dict2.Add(key2, value); - - // Copy the array by hand - LLUDPClient[] oldArray = m_array; - int oldLength = oldArray.Length; - LLUDPClient[] newArray = new LLUDPClient[oldLength + 1]; - - for (int i = 0; i < oldLength; i++) - newArray[i] = oldArray[i]; - newArray[oldLength] = value; - - m_array = newArray; + m_dict = m_dict.Add(key, value); } - public void Remove(UUID key1, IPEndPoint key2) + public void Remove(IPEndPoint key) { - m_dict1 = m_dict1.Delete(key1); - m_dict2 = m_dict2.Delete(key2); - - LLUDPClient[] oldArray = m_array; - int oldLength = oldArray.Length; - - // Copy the array by hand - - LLUDPClient[] newArray = new LLUDPClient[oldLength - 1]; - int j = 0; - - for (int i = 0; i < oldLength; i++) - { - if (oldArray[i].AgentID != key1) - newArray[j++] = oldArray[i]; - } - - m_array = newArray; + m_dict = m_dict.Delete(key); } public void Clear() { - m_dict1 = new ImmutableMap(new UUIDComparer()); - m_dict2 = new ImmutableMap(new IPEndPointComparer()); - m_array = new LLUDPClient[0]; + m_dict = new ImmutableMap(new IPEndPointComparer()); } public int Count { - get { return m_array.Length; } - } - - public bool ContainsKey(UUID key) - { - return m_dict1.ContainsKey(key); + get { return m_dict.Count; } } public bool ContainsKey(IPEndPoint key) { - return m_dict2.ContainsKey(key); - } - - public bool TryGetValue(UUID key, out LLUDPClient value) - { - return m_dict1.TryGetValue(key, out value); + return m_dict.ContainsKey(key); } public bool TryGetValue(IPEndPoint key, out LLUDPClient value) { - return m_dict2.TryGetValue(key, out value); + return m_dict.TryGetValue(key, out value); } public void ForEach(Action action) { - Parallel.ForEach(m_array, action); + Parallel.ForEach(m_dict.Values, action); } } } -- cgit v1.1