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

DateTimeFormatterBuilder.parseOffsetBased unnecessarily calls toString()

    Details

    • Subcomponent:
    • Resolved In Build:
      b13
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      I have a CharSequence implementation which progressively processes some source data and reads the characters as needed when charAt is called. In general, this works fine with the DateTimeFormatter.parse(CharSequence, ParsePosition) API. But the first line of the internal DateTimeFormatterBuilder.parseOffsetBased() method calls toString() on the entire CharSequence and then takes a substring immediately afterwards:

      String prefix = text.toString().substring(prefixPos, position).toUpperCase();

      The toString() method is very expensive in my use case, and is unnecessary here. The same code could use this alternative which I believe is guaranteed to be semantically equivalent:

      String prefix = text.subSequence(prefixPos, position).toString().toUpperCase();

      Which uses the CharSequence's own subSequence method before calling toString(), which avoids converting the entire CharSequence into a String. I can't see any other uses of toString() in the DateTimeFormatterBuilder class, so I think only this line needs changing to avoid CharSequence.toString() being called.


        Attachments

          Activity

            People

            • Assignee:
              rgoel Rachna Goel
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: