Commit 37feb1f8 authored by guus's avatar guus

Fixed calculated size for Strings (OF-333), improved calculation of Maps (removed one iteration).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11565 b35dd754-fafc-0310-a699-88a17e54d16e
parent 66265367
...@@ -54,7 +54,7 @@ public class CacheSizes { ...@@ -54,7 +54,7 @@ public class CacheSizes {
if (string == null) { if (string == null) {
return 0; return 0;
} }
return 4 + string.length() * 2; return 4 + string.getBytes().length;
} }
/** /**
...@@ -118,21 +118,17 @@ public class CacheSizes { ...@@ -118,21 +118,17 @@ public class CacheSizes {
* @param map the Map object to determine the size of. * @param map the Map object to determine the size of.
* @return the size of the Map object. * @return the size of the Map object.
*/ */
public static int sizeOfMap(Map map) { public static int sizeOfMap(Map<String, String> map) {
if (map == null) { if (map == null) {
return 0; return 0;
} }
// Base map object -- should be something around this size. // Base map object -- should be something around this size.
int size = 36; int size = 36;
// Add in size of each value // Add in size of each value
Object[] values = map.values().toArray(); for (Map.Entry<String, String> entry : map.entrySet()) {
for (int i = 0; i < values.length; i++) { size += sizeOfString(entry.getKey());
size += sizeOfString((String)values[i]); size += sizeOfString(entry.getValue());
}
Object[] keys = map.keySet().toArray();
// Add in each key
for (int i = 0; i < keys.length; i++) {
size += sizeOfString((String)keys[i]);
} }
return size; return size;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment