AttributedString.java (AttributedString): Use ArrayList to build array of attribute...
authorTom Tromey <tromey@redhat.com>
Tue, 31 Aug 2004 09:50:40 +0000 (09:50 +0000)
committerAndreas Tobler <andreast@gcc.gnu.org>
Tue, 31 Aug 2004 09:50:40 +0000 (11:50 +0200)
2004-08-31  Tom Tromey  <tromey@redhat.com>

* java/text/AttributedString.java (AttributedString): Use
ArrayList to build array of attribute ranges.  Don't use
`attribs' before it is set.

From-SVN: r86825

libjava/ChangeLog
libjava/java/text/AttributedString.java

index 5cdc6f4783ebb79fe463aa470dace2d287f8b293..9cf9a202c1b5742019690d026bb02a8874784716 100644 (file)
@@ -1,3 +1,9 @@
+2004-08-31  Tom Tromey  <tromey@redhat.com>
+
+       * java/text/AttributedString.java (AttributedString): Use
+       ArrayList to build array of attribute ranges.  Don't use
+       `attribs' before it is set.
+
 2004-08-30  Andreas Tobler  <a.tobler@schweiz.ch>
 
        * HACKING: Remove reference to special automake. No longer needed.
index 8304cedf7bc1a24c4c577caee4911a26fcf0212b..41512dc6c5e62e29ace0464a3ec8c9e1d6784316 100644 (file)
@@ -39,6 +39,7 @@ exception statement from your version. */
 package java.text;
 
 import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -224,6 +225,7 @@ AttributedString(AttributedCharacterIterator aci, int begin_index,
   // Loop through and extract the attributes
   char c = aci.setIndex(begin_index);
 
+  ArrayList accum = new ArrayList();
   do
     { 
       sb.append(c);
@@ -272,17 +274,17 @@ AttributedString(AttributedCharacterIterator aci, int begin_index,
           Map new_map = new Hashtable();
           new_map.put(attrib, attrib_obj);
 
-          // Add it to the attribute list.  Yes this is a bad way to do things.
-          AttributeRange[] new_list = new AttributeRange[attribs.length + 1];
-          System.arraycopy(attribs, 0, new_list, 0, attribs.length);
-          attribs = new_list;
-          attribs[attribs.length - 1] = new AttributeRange(new_map, rs, rl);
+          // Add it to the attribute list.
+         accum.add(new AttributeRange(new_map, rs, rl));
         }
 
       c = aci.next();
     }
   while(c != CharacterIterator.DONE);
 
+  attribs = new AttributeRange[accum.size()];
+  attribs = (AttributeRange[]) accum.toArray(attribs);
+
   sci = new StringCharacterIterator(sb.toString());
 }