8229845: Decrease memory consumption of BigInteger.toString()

Brian Burkhalter brian.burkhalter at oracle.com
Fri Aug 23 20:33:31 UTC 2019

Hi Ivan,

> On Aug 23, 2019, at 12:41 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com> wrote:
> One minor comment.  Here:
> 3990             if (digits > 0) {
> 3991                 padWithZeros(buf, digits);
> 3992             } else {
> 3993                 buf.append('0');
> 3994             }
> I cannot really see how digits may be <= 0, so it seems to me it can be safely replaced by just one line `padWithZeros(buf, digits);`.

Actually I don’t see how digits may be non-positive for signum == 0 either. I’ve reduced the above to one line (L3990) in [1]. That is the only change versus version .04.

> Alternatively, the entire branch `if (signum == 0) {` can be removed from smallToString (so that this method will only work with strictly positive numbers), and done only for results[1] at line 4083 because it is the only possible source of ZERO values in the process.
> It also seems that the arithmetic in the very internal loop at 4005-4017 can be slightly optimized, but this probably can be left for another enhancement.

I think I’ll leave it as is for now.



[1] http://cr.openjdk.java.net/~bpb/8229845/webrev.05/

More information about the core-libs-dev mailing list