Avoid instantiating some number objects

This commit is contained in:
Ville Skyttä 2016-04-10 12:46:05 +03:00 committed by Clebert Suconic
parent c2d51c07f0
commit cf00dd9b1b
3 changed files with 14 additions and 14 deletions

View File

@ -606,7 +606,7 @@ public class JSONArray {
* @throws JSONException if the value is not finite.
*/
public JSONArray put(final double value) throws JSONException {
Double d = new Double(value);
Double d = Double.valueOf(value);
JSONObject.testValidity(d);
put(d);
return this;
@ -701,7 +701,7 @@ public class JSONArray {
* not finite.
*/
public JSONArray put(final int index, final double value) throws JSONException {
put(index, new Double(value));
put(index, Double.valueOf(value));
return this;
}

View File

@ -978,7 +978,7 @@ public class JSONObject {
* @throws JSONException If the key is null or if the number is invalid.
*/
public JSONObject put(final String key, final double value) throws JSONException {
put(key, new Double(value));
put(key, Double.valueOf(value));
return this;
}

View File

@ -120,42 +120,42 @@ public abstract class ArithmeticExpression extends BinaryExpression {
protected Number plus(Number left, Number right) {
switch (numberType(left, right)) {
case INTEGER:
return new Integer(left.intValue() + right.intValue());
return left.intValue() + right.intValue();
case LONG:
return new Long(left.longValue() + right.longValue());
return left.longValue() + right.longValue();
default:
return new Double(left.doubleValue() + right.doubleValue());
return left.doubleValue() + right.doubleValue();
}
}
protected Number minus(Number left, Number right) {
switch (numberType(left, right)) {
case INTEGER:
return new Integer(left.intValue() - right.intValue());
return left.intValue() - right.intValue();
case LONG:
return new Long(left.longValue() - right.longValue());
return left.longValue() - right.longValue();
default:
return new Double(left.doubleValue() - right.doubleValue());
return left.doubleValue() - right.doubleValue();
}
}
protected Number multiply(Number left, Number right) {
switch (numberType(left, right)) {
case INTEGER:
return new Integer(left.intValue() * right.intValue());
return left.intValue() * right.intValue();
case LONG:
return new Long(left.longValue() * right.longValue());
return left.longValue() * right.longValue();
default:
return new Double(left.doubleValue() * right.doubleValue());
return left.doubleValue() * right.doubleValue();
}
}
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) {
return new Double(left.doubleValue() % right.doubleValue());
return left.doubleValue() % right.doubleValue();
}
private int numberType(Number left, Number right) {