JDK-6964528 : Double.toHexString(double d) String manipulation with + in an append of StringBuilder
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2010-06-27
  • Updated: 2014-10-07
  • Resolved: 2013-02-02
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.
JDK 8
8 b77Fixed
Description
A DESCRIPTION OF THE REQUEST :
Just a slight fix for performance when doing Double.toHexString(double d) method :P

Under the method :
public static String toHexString(double d) {

It uses StringBuilder for the output however, at line 306, it's done using + syntax in a StringBuilder.

JUSTIFICATION :
Performance enchantment...

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The String buffer should be done in a new StringBuilder.append() instead of using +.
ACTUAL -
		answer.append("p" + (subnormal ?
			       DoubleConsts.MIN_EXPONENT:
			       FpUtils.getExponent(d) ));

---------- BEGIN SOURCE ----------
		answer.append("p" + (subnormal ?
			       DoubleConsts.MIN_EXPONENT:
			       FpUtils.getExponent(d) ));
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
		answer.append("p");
                answer.append((subnormal ?
			       DoubleConsts.MIN_EXPONENT:
			       FpUtils.getExponent(d) );

Comments
Should swtich to StringBuilder instead of StringBuffer, add a call to append instead of doing string concatenation, and fix whitespace on line 303.
2013-02-01

EVALUATION A reasonable suggestion.
2012-07-23