-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Satheesh Bandaram wrote: > Also, would it be better to write the code as: > > value = new BigDecimal(Double.toString(theValue)); > > to avoid creating a Double object? I suspect this code is used a lot > (when there are double values), so could save time.
I agree, whereever possible object creation should be avoided. Imagine a table scan that returns a million rows, with new Double the code is creating an extra one million temporary objects for garbage collection. Even using Double.toString() in itself creates an extra two objects (the String and the char[] within String) per value, so with a million rows, two million extra temporary objects for garbage collection. I assume the correct behaviour justifies the expense. In general I assume applications are not spending much time converting from double to DECIMAL or DOUBLE to DECIMAL/BigDecimal. Another issue with the change is that there are other a handful of other cases in the code where a double is converted directly into a BigDecimal, I think these should be fixed as well, to be consistent. I did a quick search for new.*BigDecimal to find them. Dan. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFCA4M/Iv0S4qsbfuQRAvXgAJoCk1XaPHe2AON8/KfNlUFavrH2+QCfc3qP a8uiAvxQ0HXNmVZTsiuwUII= =Md26 -----END PGP SIGNATURE-----
