1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

out of the pool

This commit is contained in:
Douglas Crockford 2013-06-17 17:10:27 -07:00
parent 1f7056edc2
commit 34f327e6d0

View file

@ -90,22 +90,9 @@ import java.util.Set;
* </ul>
*
* @author JSON.org
* @version 2013-04-18
* @version 2013-06-17
*/
public class JSONObject {
/**
* The maximum number of keys in the key pool.
*/
private static final int keyPoolSize = 100;
/**
* Key pooling is like string interning, but without permanently tying up
* memory. To help conserve memory, storage of duplicated key strings in
* JSONObjects will be avoided by using a key pool to manage unique key
* string objects. This is used by JSONObject.put(string, object).
*/
private static HashMap keyPool = new HashMap(keyPoolSize);
/**
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
* whilst Java's null is equivalent to the value that JavaScript calls
@ -1147,21 +1134,11 @@ public class JSONObject {
* If the value is non-finite number or if the key is null.
*/
public JSONObject put(String key, Object value) throws JSONException {
String pooled;
if (key == null) {
throw new NullPointerException("Null key.");
}
if (value != null) {
testValidity(value);
pooled = (String) keyPool.get(key);
if (pooled == null) {
if (keyPool.size() >= keyPoolSize) {
keyPool = new HashMap(keyPoolSize);
}
keyPool.put(key, key);
} else {
key = pooled;
}
this.map.put(key, value);
} else {
this.remove(key);