mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Merge pull request #348 from johnjaylward/ArrayPerformance
Capacity improvements for internal structures
This commit is contained in:
commit
1add1247fa
3 changed files with 31 additions and 9 deletions
|
@ -184,7 +184,7 @@ public class JSONObject {
|
|||
* An array of strings.
|
||||
*/
|
||||
public JSONObject(JSONObject jo, String[] names) {
|
||||
this();
|
||||
this(names.length);
|
||||
for (int i = 0; i < names.length; i += 1) {
|
||||
try {
|
||||
this.putOnce(names[i], jo.opt(names[i]));
|
||||
|
@ -256,8 +256,10 @@ public class JSONObject {
|
|||
* the JSONObject.
|
||||
*/
|
||||
public JSONObject(Map<?, ?> m) {
|
||||
this.map = new HashMap<String, Object>();
|
||||
if (m != null) {
|
||||
if (m == null) {
|
||||
this.map = new HashMap<String, Object>();
|
||||
} else {
|
||||
this.map = new HashMap<String, Object>(m.size());
|
||||
for (final Entry<?, ?> e : m.entrySet()) {
|
||||
final Object value = e.getValue();
|
||||
if (value != null) {
|
||||
|
@ -308,7 +310,7 @@ public class JSONObject {
|
|||
* from the object.
|
||||
*/
|
||||
public JSONObject(Object object, String names[]) {
|
||||
this();
|
||||
this(names.length);
|
||||
Class<?> c = object.getClass();
|
||||
for (int i = 0; i < names.length; i += 1) {
|
||||
String name = names[i];
|
||||
|
@ -377,6 +379,17 @@ public class JSONObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to specify an initial capacity of the internal map. Useful for library
|
||||
* internal calls where we know, or at least can best guess, how big this JSONObject
|
||||
* will be.
|
||||
*
|
||||
* @param initialCapacity initial capacity of the internal map.
|
||||
*/
|
||||
protected JSONObject(int initialCapacity){
|
||||
this.map = new HashMap<String, Object>(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accumulate values under a key. It is similar to the put method except
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue