Andrew John Hughes wrote:
This adds a feature to CPStringBuilder so that it knows
when its array has been shared with a String object.  Once
this has happened, any future write operations will allocate
a new array and reset the flag.  This fixes the issue in
PR36147.

ChangeLog:

2008-05-11  Andrew John Hughes  <[EMAIL PROTECTED]>

        PR classpath/36147
        * gnu/java/lang/CPStringBuilder.java:
        (allocated): New flag to mark whether or
        not the array has been allocated to a String object.
        (ensureCapacity(int)): Removed.
        (ensureCapacity_unsynchronized(int)): Renamed to
        ensureCapacity, and creates an array when allocated
        is true.
        (allocateArray(int)): Added.
        (trimToSize()): Use allocateArray method.
        (toString()): Set allocated to true;
        (substring(int,int)): Likewise.

Why not just use java.lang.StingBuilder in the cases where the StringBuilder is modified after an initial toString() call?

My understanding of your CPStringBuilder work is that it was for the constrained conditions of single threaded access with a single toString() call after which it would be discarded. If we have to allocate another array, we gain nothing over java.lang.StringBuilder other than making the code more confusing. I am uncomfortable with this change as well as the use of CPStringBuilder that makes it necessary.

Am I missing something here?

David Daney


Reply via email to