From c8d44971c4aacc3f51d759f5789ef07ee11770cd Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Fri, 8 May 2009 19:03:01 +0000 Subject: Implement an ingenious solution to pacekt pool performance suggested by dlslake. --- OpenSim/Framework/PacketPool.cs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs index 76e48e5..cdde37e 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); } } } -- cgit v1.1