aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/PacketPool.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/PacketPool.cs')
-rw-r--r--OpenSim/Framework/PacketPool.cs30
1 files changed, 10 insertions, 20 deletions
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
46 46
47 private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>(); 47 private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>();
48 48
49 private static Dictionary<Type, List<Object>> DataBlocks = 49 private static Dictionary<Type, Stack<Object>> DataBlocks =
50 new Dictionary<Type, List<Object>>(); 50 new Dictionary<Type, Stack<Object>>();
51 51
52 static PacketPool() 52 static PacketPool()
53 { 53 {
@@ -212,18 +212,18 @@ namespace OpenSim.Framework
212 { 212 {
213 lock (DataBlocks) 213 lock (DataBlocks)
214 { 214 {
215 if (DataBlocks.ContainsKey(typeof(T)) && DataBlocks[typeof(T)].Count > 0) 215 Stack<Object> s;
216
217 if (DataBlocks.TryGetValue(typeof(T), out s))
216 { 218 {
217 T block = (T)DataBlocks[typeof(T)][0]; 219 if (s.Count > 0)
218 DataBlocks[typeof(T)].RemoveAt(0); 220 return (T)s.Pop();
219 if (block == null)
220 return new T();
221 return block;
222 } 221 }
223 else 222 else
224 { 223 {
225 return new T(); 224 DataBlocks[typeof(T)] = new Stack<Object>();
226 } 225 }
226 return new T();
227 } 227 }
228 } 228 }
229 229
@@ -234,17 +234,7 @@ namespace OpenSim.Framework
234 234
235 lock (DataBlocks) 235 lock (DataBlocks)
236 { 236 {
237 if (!DataBlocks.ContainsKey(typeof(T))) 237 DataBlocks[typeof(T)].Push(block);
238 {
239 List<Object> l = new List<Object>();
240 l.Add(block);
241 DataBlocks.Add(typeof(T), l);
242 }
243 else
244 {
245 if (DataBlocks[typeof(T)].Count < 500)
246 DataBlocks[typeof(T)].Add(block);
247 }
248 } 238 }
249 } 239 }
250 } 240 }