Avoid instantiating some number objects
This commit is contained in:
parent
c2d51c07f0
commit
cf00dd9b1b
|
@ -606,7 +606,7 @@ public class JSONArray {
|
||||||
* @throws JSONException if the value is not finite.
|
* @throws JSONException if the value is not finite.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final double value) throws JSONException {
|
public JSONArray put(final double value) throws JSONException {
|
||||||
Double d = new Double(value);
|
Double d = Double.valueOf(value);
|
||||||
JSONObject.testValidity(d);
|
JSONObject.testValidity(d);
|
||||||
put(d);
|
put(d);
|
||||||
return this;
|
return this;
|
||||||
|
@ -701,7 +701,7 @@ public class JSONArray {
|
||||||
* not finite.
|
* not finite.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(final int index, final double value) throws JSONException {
|
public JSONArray put(final int index, final double value) throws JSONException {
|
||||||
put(index, new Double(value));
|
put(index, Double.valueOf(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -978,7 +978,7 @@ public class JSONObject {
|
||||||
* @throws JSONException If the key is null or if the number is invalid.
|
* @throws JSONException If the key is null or if the number is invalid.
|
||||||
*/
|
*/
|
||||||
public JSONObject put(final String key, final double value) throws JSONException {
|
public JSONObject put(final String key, final double value) throws JSONException {
|
||||||
put(key, new Double(value));
|
put(key, Double.valueOf(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,42 +120,42 @@ public abstract class ArithmeticExpression extends BinaryExpression {
|
||||||
protected Number plus(Number left, Number right) {
|
protected Number plus(Number left, Number right) {
|
||||||
switch (numberType(left, right)) {
|
switch (numberType(left, right)) {
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
return new Integer(left.intValue() + right.intValue());
|
return left.intValue() + right.intValue();
|
||||||
case LONG:
|
case LONG:
|
||||||
return new Long(left.longValue() + right.longValue());
|
return left.longValue() + right.longValue();
|
||||||
default:
|
default:
|
||||||
return new Double(left.doubleValue() + right.doubleValue());
|
return left.doubleValue() + right.doubleValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Number minus(Number left, Number right) {
|
protected Number minus(Number left, Number right) {
|
||||||
switch (numberType(left, right)) {
|
switch (numberType(left, right)) {
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
return new Integer(left.intValue() - right.intValue());
|
return left.intValue() - right.intValue();
|
||||||
case LONG:
|
case LONG:
|
||||||
return new Long(left.longValue() - right.longValue());
|
return left.longValue() - right.longValue();
|
||||||
default:
|
default:
|
||||||
return new Double(left.doubleValue() - right.doubleValue());
|
return left.doubleValue() - right.doubleValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Number multiply(Number left, Number right) {
|
protected Number multiply(Number left, Number right) {
|
||||||
switch (numberType(left, right)) {
|
switch (numberType(left, right)) {
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
return new Integer(left.intValue() * right.intValue());
|
return left.intValue() * right.intValue();
|
||||||
case LONG:
|
case LONG:
|
||||||
return new Long(left.longValue() * right.longValue());
|
return left.longValue() * right.longValue();
|
||||||
default:
|
default:
|
||||||
return new Double(left.doubleValue() * right.doubleValue());
|
return left.doubleValue() * right.doubleValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Number divide(Number left, Number right) {
|
protected Number divide(Number left, Number right) {
|
||||||
return new Double(left.doubleValue() / right.doubleValue());
|
return left.doubleValue() / right.doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Number mod(Number left, Number right) {
|
protected Number mod(Number left, Number right) {
|
||||||
return new Double(left.doubleValue() % right.doubleValue());
|
return left.doubleValue() % right.doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int numberType(Number left, Number right) {
|
private int numberType(Number left, Number right) {
|
||||||
|
|
Loading…
Reference in New Issue