* Changing List to Dictionary in PacketQueue.Dequeue for great justice (and performance)

0.6.6-post-fixes
Arthur Valadares 2009-06-29 16:55:00 +00:00
parent 715f2f2798
commit 6da88dceb0
1 changed files with 18 additions and 8 deletions

View File

@ -83,7 +83,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
internal LLPacketThrottle TextureThrottle; internal LLPacketThrottle TextureThrottle;
internal LLPacketThrottle TotalThrottle; internal LLPacketThrottle TotalThrottle;
private List<uint> contents = new List<uint>(); private Dictionary<uint,int> contents = new Dictionary<uint, int>();
/// <summary> /// <summary>
/// The number of packets in the OutgoingPacketQueue /// The number of packets in the OutgoingPacketQueue
@ -189,7 +189,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
if (item.Sequence != 0) if (item.Sequence != 0)
lock (contents) contents.Add(item.Sequence); lock (contents)
{
if (contents.ContainsKey(item.Sequence))
contents[item.Sequence] += 1;
else
contents.Add(item.Sequence, 1);
}
lock (this) lock (this)
{ {
@ -243,22 +249,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return item; return item;
lock (contents) lock (contents)
{ {
if (contents.Contains(item.Sequence)) if (contents.ContainsKey(item.Sequence))
if (contents.Remove(item.Sequence)) {
if (contents[item.Sequence] == 1)
contents.Remove(item.Sequence);
else
contents[item.Sequence] -= 1;
return item; return item;
} }
} }
} }
}
public void Cancel(uint sequence) public void Cancel(uint sequence)
{ {
lock (contents) while (contents.Remove(sequence)) lock (contents) contents.Remove(sequence);
;
} }
public bool Contains(uint sequence) public bool Contains(uint sequence)
{ {
lock (contents) return contents.Contains(sequence); lock (contents) return contents.ContainsKey(sequence);
} }
public void Flush() public void Flush()