Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8311009

Long.toUnsignedString(long, int) doesn't have to create a BigInteger

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      In the current implementation, Long.toUnsignedLong(long, int) sometimes creates a BigInteger and calls its toString(int) method. However, we don't have to create the BigInteger. The string can be calculated by the following algorithm:

      long leadingDigits = divideUnsigned(i, radix); // always positive
      int lastDigit = (int)remainderUnsigned(i, radix);
      yield toString(leadingDigits, radix) + Character.forDigit(lastDigit, radix);

      This implementation prevents from creating an additional object and is typically faster than BigInteger.toString(int).


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: