This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
The following commit(s) were added to refs/heads/master by this push:
new e29dff1 [NUMBERS-87] Avoid unnecessary allocations in production code
new d6d7b04 Merge branch 'fix_NUMBERS-87__roman'
e29dff1 is described below
commit e29dff1e3adbab30d4041636de9d9e59649ec2b2
Author: Roman Leventov <[email protected]>
AuthorDate: Sun Dec 23 12:21:40 2018 +0100
[NUMBERS-87] Avoid unnecessary allocations in production code
---
.../src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java | 5 +++--
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 +-
.../src/main/java/org/apache/commons/numbers/field/FP64.java | 2 +-
.../src/main/java/org/apache/commons/numbers/field/FP64Field.java | 4 ++--
.../java/org/apache/commons/numbers/gamma/RegularizedGamma.java | 6 ++----
5 files changed, 9 insertions(+), 10 deletions(-)
diff --git
a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
index 7b57be8..eab079f 100644
---
a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
+++
b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
@@ -113,7 +113,8 @@ public class PlaneAngle {
return true;
}
if (other instanceof PlaneAngle){
- return Double.valueOf(value).equals(Double.valueOf(((PlaneAngle)
other).value));
+ return Double.doubleToLongBits(value) ==
+ Double.doubleToLongBits(((PlaneAngle) other).value);
}
return false;
}
@@ -121,6 +122,6 @@ public class PlaneAngle {
/** {@inheritDoc} */
@Override
public int hashCode() {
- return Double.valueOf(value).hashCode();
+ return Double.hashCode(value);
}
}
diff --git
a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index ebc61c8..2321466 100644
---
a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++
b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -1363,7 +1363,7 @@ public final class Complex implements Serializable {
* @return {@code Double.valueof(x).equals(Double.valueOf(y))}
*/
private static boolean equals(double x, double y) {
- return Double.valueOf(x).equals(Double.valueOf(y));
+ return Double.doubleToLongBits(x) == Double.doubleToLongBits(y);
}
/**
diff --git
a/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64.java
b/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64.java
index 9bac221..f0a2c92 100644
---
a/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64.java
+++
b/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64.java
@@ -105,7 +105,7 @@ public class FP64 extends Number
/** {@inheritDoc} */
@Override
public int hashCode() {
- return Double.valueOf(value).hashCode();
+ return Double.hashCode(value);
}
/** {@inheritDoc} */
diff --git
a/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64Field.java
b/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64Field.java
index f63665c..fe7e921 100644
---
a/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64Field.java
+++
b/commons-numbers-field/src/main/java/org/apache/commons/numbers/field/FP64Field.java
@@ -21,9 +21,9 @@ package org.apache.commons.numbers.field;
*/
public class FP64Field extends AbstractField<FP64> {
/** 0d */
- private static final FP64 ZERO = new FP64(Double.valueOf(0));
+ private static final FP64 ZERO = new FP64(0.);
/** 1d */
- private static final FP64 ONE = new FP64(Double.valueOf(1));
+ private static final FP64 ONE = new FP64(1.);
/** {@inheritDoc} */
@Override
diff --git
a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
index cf35665..1aae5f3 100644
---
a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
+++
b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
@@ -85,8 +85,7 @@ public class RegularizedGamma {
return 0;
} else if (x >= a + 1) {
// Q should converge faster in this case.
- final RegularizedGamma.Q q = new RegularizedGamma.Q();
- return 1 - q.value(a, x, epsilon, maxIterations);
+ return 1 - RegularizedGamma.Q.value(a, x, epsilon,
maxIterations);
} else {
// Series.
double n = 0; // current element index
@@ -167,8 +166,7 @@ public class RegularizedGamma {
return 1;
} else if (x < a + 1) {
// P should converge faster in this case.
- final RegularizedGamma.P p = new RegularizedGamma.P();
- return 1 - p.value(a, x, epsilon, maxIterations);
+ return 1 - RegularizedGamma.P.value(a, x, epsilon,
maxIterations);
} else {
final ContinuedFraction cf = new ContinuedFraction() {
/** {@inheritDoc} */