commons-math icon indicating copy to clipboard operation
commons-math copied to clipboard

Replace the inefficient Double constructor with static Double.valueOf() method.

Open Kui-Liu opened this issue 6 years ago • 2 comments

Using new Double(double) is guaranteed to always result in a new object whereas Double.valueOf(double) allows caching of values to be done by the compiler, class library, or JVM. Using of cached values avoids object allocation and the code will be faster. http://findbugs.sourceforge.net/bugDescriptions.html#DM_FP_NUMBER_CTOR

Kui-Liu avatar Oct 09 '17 22:10 Kui-Liu

Coverage Status

Coverage remained the same at 89.963% when pulling 470da550681b0a8dbae294392eda557a91ce0345 on BruceKuiLiu:master-pullrequest into eafb16c711d5cd79edad5fbb2055252acdb3825e on apache:master.

coveralls avatar Oct 09 '17 22:10 coveralls

Double.valueOf() is inefficient too. There should be used Double.doubleToLongBits(value1) == Double.doubleToLongBits(value2)

jandam avatar Nov 19 '17 15:11 jandam