Add getChars to CharSequence

David Holmes david.holmes at oracle.com
Mon May 20 12:22:30 UTC 2013


Hi Martin,

I took a look at this in relation to the other StringBuffer bugs.

I have a concern. Looking at this:

@@ -453,12 +438,11 @@
      public AbstractStringBuilder append(CharSequence s) {
          if (s == null)
              return appendNull();
-        if (s instanceof String)
-            return this.append((String)s);
-        if (s instanceof AbstractStringBuilder)
-            return this.append((AbstractStringBuilder)s);
-
-        return this.append(s, 0, s.length());
+        int len = s.length();
+        ensureCapacityInternal(count + len);
+        s.getChars(0, len, value, count);
+        count += len;
+        return this;
      }

it seems that you are passing the ABS internal char[] value, directly to 
an external method (s.getChars) which could be overridden to do whatever 
it wants to the passed in array! Am I missing something?

David
-----

On 11/04/2013 10:40 AM, Martin Buchholz wrote:
> I've often wished that CharSequence had getChars methods, as many of the
> concrete implementations already do.
> In jdk8 with default methods, this is possible!
> This will make some of the String code a little nicer and more efficient.
>
> Here's a preliminary patch in this direction, that overlaps with some of
> the work done in
>
> 6206780: (str) Forwarding append methods in String{Buffer,Builder} are
> inconsistent
> Summary: update StringBuilder & StringBuffer to consistently handle
> forwarding to AbstractStringBuilder. Some additional cleanup (removal of
> refs to sub-classes from AbstractStringBuilder)
>
> http://cr.openjdk.java.net/~martin/webrevs/openjdk8/getChars/
>
> If we have consensus that this is a good idea, I can flesh this out.
>



More information about the core-libs-dev mailing list