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

(str) Need String alternative with shared storage

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      Prior to the fix for JDK-6924259 (in JDK 8 and JDK 7u6) the String was allowed to share its storage with its substrings.
      That approach, in particular, could lead to memory leaks, and had some other disadvantages.

      However, it also had its advantages, e.g. ability to search within a limited range of a String: str.substring(n, m).indexOf(xxx).

      We need to investigate, if it is worthwhile to introduce another CharSequence implementation, which would behave analogously to the old implementation of String, i.e. will have a link to the potentially shared buffer, plus offset within this buffer and length.
      This new class can be named in such a way that it would remind about its shared buffer, so that the user will have to take responsibility to avoid memory leaks. One possible name is SharedString.

      The String class will have a methods to create SharedStrings referencing the entire string or it's substrings without expensive copying.

      SharedString will have search/match methods, analogous to the ones of String.

      Primary use case of the new class would be to create local temporary variables for cheap substrings for quick access to sub-ranges.
      This may be useful for applications with extensive text processing, like parsers.

      Need to create a draft implementation and see how using such an alternative to String affects performance of JDK tools: javac, javadoc, etc.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              igerasim Ivan Gerasimov
              Reporter:
              igerasim Ivan Gerasimov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: