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

(str) String{Buffer,Builder}.indexOf(Str, int) contains unnecessary allocation

    XMLWordPrintable

Details

    • Enhancement
    • Status: Closed
    • P4
    • Resolution: Fixed
    • 6
    • 8
    • core-libs
    • b68
    • x86
    • windows_2003
    • Not verified

    Description

      A DESCRIPTION OF THE REQUEST :
      java.lang.String.indexOf(String str, int fromIndex) uses str.value and so does not need to call str.toCharArray() and therefore does no allocation.
      java.lang.StringBuffer.indexOf(String str, int fromIndex) uses str.toCharArray() which allocates a new char array just for the purposes of the call ; if the method is called in a loop with the same str, many "same" allocations can be done ; it would be more optimal to be able to use directly the str value member (through adequate qualifiers / getter).
      Same for StringBuilder.

      JUSTIFICATION :
      Reduce "unnecessary" allocation

      Attachments

        Activity

          People

            mduigou Mike Duigou
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: