Optimization for new BigDecimal(String)

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: None
    • Component/s: 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.

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

              Created:
              Updated: