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

Optimize LocalDate.toString with StringBuilder.repeat

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • core-libs
    • b08

      class LocalDate {
          public String toString() {
              if (absYear < 1000) {
                  if (yearValue < 0) {
                      buf.append(yearValue - 10000).deleteCharAt(1);
                  } else {
                      buf.append(yearValue + 10000).deleteCharAt(0);
                  }
             // ...
          }
      }
      Currently, LocalDate.toString causes an extra memory copy when processing years < 1000. This can be replaced by using StringBuilder.repeat, which is more concise and has better performance.

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

              Created:
              Updated:
              Resolved: