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

Optimization for new BigDecimal(String)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      The current BigDecimal(String) constructor calls String#toCharArray, which has a memory allocation.

      public BigDecimal(String val) {
          this(val.toCharArray(), 0, val.length()); // allocate char[]
      }
      When the length is greater than 18, create a char[]

      boolean isCompact = (len <= MAX_COMPACT_DIGITS); // 18
      if (!isCompact) {
          // ...
      } else {
          char[] coeff = new char[len]; // allocate char[]
          // ...
      }

      We can eliminate these two memory allocations to enhance performance.

            swen Shaojin Wen
            swen Shaojin Wen
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: