diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs index 76e48e5270..cdde37e2f1 100644 --- a/OpenSim/Framework/PacketPool.cs +++ b/OpenSim/Framework/PacketPool.cs @@ -46,8 +46,8 @@ namespace OpenSim.Framework private readonly Dictionary> pool = new Dictionary>(); - private static Dictionary> DataBlocks = - new Dictionary>(); + private static Dictionary> DataBlocks = + new Dictionary>(); static PacketPool() { @@ -212,18 +212,18 @@ namespace OpenSim.Framework { lock (DataBlocks) { - if (DataBlocks.ContainsKey(typeof(T)) && DataBlocks[typeof(T)].Count > 0) + Stack s; + + if (DataBlocks.TryGetValue(typeof(T), out s)) { - T block = (T)DataBlocks[typeof(T)][0]; - DataBlocks[typeof(T)].RemoveAt(0); - if (block == null) - return new T(); - return block; + if (s.Count > 0) + return (T)s.Pop(); } else { - return new T(); + DataBlocks[typeof(T)] = new Stack(); } + return new T(); } } @@ -234,17 +234,7 @@ namespace OpenSim.Framework lock (DataBlocks) { - if (!DataBlocks.ContainsKey(typeof(T))) - { - List l = new List(); - l.Add(block); - DataBlocks.Add(typeof(T), l); - } - else - { - if (DataBlocks[typeof(T)].Count < 500) - DataBlocks[typeof(T)].Add(block); - } + DataBlocks[typeof(T)].Push(block); } } }