diff options
author | Melanie Thielker | 2009-05-08 19:03:01 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-05-08 19:03:01 +0000 |
commit | c8d44971c4aacc3f51d759f5789ef07ee11770cd (patch) | |
tree | 580b57bdb3a3c897f918d8d04af201dba8187c61 /OpenSim | |
parent | The new asset server now actually serves existing assets (diff) | |
download | opensim-SC_OLD-c8d44971c4aacc3f51d759f5789ef07ee11770cd.zip opensim-SC_OLD-c8d44971c4aacc3f51d759f5789ef07ee11770cd.tar.gz opensim-SC_OLD-c8d44971c4aacc3f51d759f5789ef07ee11770cd.tar.bz2 opensim-SC_OLD-c8d44971c4aacc3f51d759f5789ef07ee11770cd.tar.xz |
Implement an ingenious solution to pacekt pool performance suggested by
dlslake.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/PacketPool.cs | 30 |
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 | } |