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

NumberFormat Performance

XMLWordPrintable

    • beta
    • generic
    • generic



      Name: bb33257 Date: 10/19/98


      NumberFormat is much slower than it needs to be.
      Just the following prototype change to DigitList.set speeds up
      formatting of longs by about 4 times.

      ublic final void set(long source, int maximumDigits)
      {
          // later, make digits relative to 0, not '0'
          if (source <= 0) {
              // FIX put in special check for MIN_VALUE, just copying in pre-made static array
              digits[0] = 0;
              count = 1;
              decimalAt = 0;
          } else {
              int last = MAX_COUNT;
           while (source > 0) {
           digits[--last] = (byte)(0x30L + (source % 10));
           source = source / 10;
           }
           decimalAt = MAX_COUNT-last;
           // Don't copy trailing zeros
           int i;
           // we are guaranteed that there is at least one non-zero digit,
           // so we don't have to check lower bounds
           for (i = MAX_COUNT - 1; digits[i] == 0; --i) {
           }
           count = i - last + 1;
           System.arraycopy(digits, last, digits, 0, count);
      }
          if (maximumDigits > 0) round(maximumDigits);
      }
      ======================================================================

            aliusunw Alan Liu (Inactive)
            bcbeck Brian Beck (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: