JDK-6274390 : BigDecimal.doubleValue() performance improvement
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-05-23
  • Updated: 2011-02-16
  • Resolved: 2005-07-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u5Fixed 6 b45Fixed
Description
A DESCRIPTION OF THE REQUEST :
BigDecimal.doubleValue(), BigDecimal.floatValue(), BigInteger.doubleValue(), and BigInteger.floatValue() all create unneeded objects to return their results.  For example, BigDecimal.doubleValue() could be changed from:
return Double.valueOf(this.toString()).doubleValue();
to
return Double.parseDouble(this.toString());

This avoids creating new Double objects just to call their doubleValue() methods
to get the primitive value.

The implemenation of Double.parseDouble() and Double.valueOf() are nearly identical because they both ultimately call FloatingDecimal.readJavaFormatString().  So, this change should not change the methods' behavior.

JUSTIFICATION :
This change is an easy way to get improved performance out of these methods by not creating and destroying unneeded objects.
###@###.### 2005-05-23 11:08:59 GMT

Comments
SUGGESTED FIX See 6274390 for BigDecimal code changes. src/share/classes/java/math>sccs sccsdiff -r1.70 -r1.71 BigInteger.java ------- BigInteger.java ------- 2772c2772 < return Float.valueOf(this.toString()).floatValue(); --- > return Float.parseFloat(this.toString()); 2793c2793 < return Double.valueOf(this.toString()).doubleValue(); --- > return Double.parseDouble(this.toString()); ###@###.### 2005-07-11 20:01:02 GMT
11-07-2005

EVALUATION The submitter's analysis is correct; there is no need to create an intermediate Float or Double object. The Double.valueOf(string).doubleValue() idiom should be replaced by Double.parseDouble(string). This usage may have been left over from before the existence of the parseDouble method. ###@###.### 2005-05-24 02:04:55 GMT
24-05-2005