harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r678386 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200: ./ bytecode/
Date Mon, 21 Jul 2008 10:33:33 GMT
Author: sjanuary
Date: Mon Jul 21 03:33:32 2008
New Revision: 678386

URL: http://svn.apache.org/viewvc?rev=678386&view=rev
Log:
Apply patch for HARMONY-5920 ([classlib][pack200][performance] ArrayList usage optimization)

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CPMember.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CodeAttribute.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/InnerClassesAttribute.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
Mon Jul 21 03:33:32 2008
@@ -20,7 +20,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.Codec;
@@ -430,9 +429,8 @@
                     ArrayList methodAttributesList = methodAttributes[c][m];
                     // Make sure we add the code attribute in the right place
                     int indexForCodeAttr = 0;
-                    for (Iterator iterator = methodAttributesList.iterator(); iterator
-                            .hasNext();) {
-                        Attribute attribute = (Attribute) iterator.next();
+                    for (int index = 0; index < methodAttributesList.size(); index++)
{
+                        Attribute attribute = (Attribute) methodAttributesList.get(index);
                         if((attribute instanceof NewAttribute && ((NewAttribute)attribute).getLayoutIndex()
< 15)) {
                             indexForCodeAttr ++;
                         } else {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
Mon Jul 21 03:33:32 2008
@@ -19,7 +19,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.Codec;
@@ -983,15 +982,17 @@
         }
         MetadataBandGroup[] mb = parseMetadata(in, RxA, RxACount,
                 backwardsCalls, "field");
-        Iterator rvaAttributesIterator = mb[0].getAttributes().iterator();
-        Iterator riaAttributesIterator = mb[1].getAttributes().iterator();
+        List rvaAttributes = mb[0].getAttributes();
+        List riaAttributes = mb[1].getAttributes();
+        int rvaAttributesIndex = 0;
+        int riaAttributesIndex = 0;
         for (int i = 0; i < fieldFlags.length; i++) {
             for (int j = 0; j < fieldFlags[i].length; j++) {
                 if (rvaLayout.matches(fieldFlags[i][j])) {
-                    fieldAttributes[i][j].add(rvaAttributesIterator.next());
+                    fieldAttributes[i][j].add(rvaAttributes.get(rvaAttributesIndex++));
                 }
                 if (riaLayout.matches(fieldFlags[i][j])) {
-                    fieldAttributes[i][j].add(riaAttributesIterator.next());
+                    fieldAttributes[i][j].add(riaAttributes.get(riaAttributesIndex++));
                 }
             }
         }
@@ -1143,16 +1144,18 @@
         }
         MetadataBandGroup[] mbgs = parseMetadata(in, RxA, rxaCounts,
                 backwardsCalls, "method");
-        Iterator[] attributeIterators = new Iterator[RxA.length];
+        List[] attributeLists = new List[RxA.length];
+        int[] attributeListIndexes = new int[RxA.length];
         for (int i = 0; i < mbgs.length; i++) {
-            attributeIterators[i] = mbgs[i].getAttributes().iterator();
+            attributeLists[i] = mbgs[i].getAttributes();
+            attributeListIndexes[i] = 0;
         }
         for (int i = 0; i < methodFlags.length; i++) {
             for (int j = 0; j < methodFlags[i].length; j++) {
                 for (int k = 0; k < rxaLayouts.length; k++) {
                     if (rxaLayouts[k].matches(methodFlags[i][j])) {
                         methodAttributes[i][j]
-                                .add(attributeIterators[k].next());
+                                .add(attributeLists[k].get(attributeListIndexes[k]++));
                     }
                 }
             }
@@ -1198,14 +1201,16 @@
         }
         MetadataBandGroup[] mbgs = parseMetadata(in, RxA, RxACount,
                 backwardsCalls, "class");
-        Iterator rvaAttributesIterator = mbgs[0].getAttributes().iterator();
-        Iterator riaAttributesIterator = mbgs[1].getAttributes().iterator();
+        List rvaAttributes = mbgs[0].getAttributes();
+        List riaAttributes = mbgs[1].getAttributes();
+        int rvaAttributesIndex = 0;
+        int riaAttributesIndex = 0;
         for (int i = 0; i < classFlags.length; i++) {
             if (rvaLayout.matches(classFlags[i])) {
-                classAttributes[i].add(rvaAttributesIterator.next());
+                classAttributes[i].add(rvaAttributes.get(rvaAttributesIndex++));
             }
             if (riaLayout.matches(classFlags[i])) {
-                classAttributes[i].add(riaAttributesIterator.next());
+                classAttributes[i].add(riaAttributes.get(riaAttributesIndex++));
             }
         }
         return numBackwardsCalls;
@@ -1308,9 +1313,9 @@
      * @return ArrayList
      */
     public ArrayList getOrderedCodeAttributes() {
-        ArrayList orderedAttributeList = new ArrayList();
+        ArrayList orderedAttributeList = new ArrayList(codeAttributes.length);
         for (int classIndex = 0; classIndex < codeAttributes.length; classIndex++) {
-            ArrayList currentAttributes = new ArrayList();
+            ArrayList currentAttributes = new ArrayList(codeAttributes[classIndex].size());
             for (int attributeIndex = 0; attributeIndex < codeAttributes[classIndex]
                     .size(); attributeIndex++) {
                 Attribute attribute = (Attribute) codeAttributes[classIndex]

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java
Mon Jul 21 03:33:32 2008
@@ -19,7 +19,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.Codec;
@@ -137,9 +136,8 @@
         while (changed) {
             changed = false;
             for (int allTupleIndex = 0; allTupleIndex < allTuplesSize; allTupleIndex++)
{
-                Iterator it = classPoolClasses.iterator();
-                while (it.hasNext()) {
-                    CPClass classInPool = (CPClass) it.next();
+                for(int cpcIndex = 0; cpcIndex < classPoolClasses.size(); cpcIndex++)
{
+                    CPClass classInPool = (CPClass) classPoolClasses.get(cpcIndex);
                     String poolClassName = classInPool.name;
                     if (poolClassName.equals(allTuples[allTupleIndex]
                             .thisClassString())) {
@@ -175,9 +173,8 @@
                 }
             }
             if (tuplesToAdd.size() > 0) {
-                Iterator it = tuplesToAdd.iterator();
-                while (it.hasNext()) {
-                    IcTuple tuple = (IcTuple) it.next();
+                for(int index = 0; index < tuplesToAdd.size(); index++) {
+                    IcTuple tuple = (IcTuple) tuplesToAdd.get(index);
                     if (!relevantTuples.contains(tuple)) {
                         changedFixup = true;
                         relevantTuples.add(tuple);

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java
Mon Jul 21 03:33:32 2008
@@ -75,59 +75,58 @@
     public int[] nestpair_N;
     public CPUTF8[] nestname_RU;
 
-    private Iterator caseI_Iterator;
+    private int caseI_KI_Index;
 
-    private Iterator caseD_Iterator;
+    private int caseD_KD_Index;
 
-    private Iterator caseF_Iterator;
+    private int caseF_KF_Index;
 
-    private Iterator caseJ_Iterator;
+    private int caseJ_KJ_Index;
 
-    private Iterator casec_Iterator;
+    private int casec_RS_Index;
 
-    private Iterator caseet_Iterator;
+    private int caseet_RS_Index;
 
-    private Iterator caseec_Iterator;
+    private int caseec_RU_Index;
 
-    private Iterator cases_Iterator;
+    private int cases_RU_Index;
 
-    private Iterator casearray_Iterator;
+    private int casearray_N_Index;
 
-    private Iterator T_iterator;
+    private int T_index;
 
-    private Iterator nesttype_RS_Iterator;
+    private int nesttype_RS_Index;
 
-    private Iterator nestpair_N_Iterator;
+    private int nestpair_N_Index;
 
     private Iterator nestname_RU_Iterator;
 
-    private Iterator anno_N_Iterator;
+    private int anno_N_Index;
 
     private Iterator type_RS_Iterator;
 
-    private Iterator pair_N_Iterator;
+    private int pair_N_Index;
 
     public List getAttributes() {
+        // TODO: Optimize iterators!
         if (attributes == null) {
             attributes = new ArrayList();
             if (name_RU != null) {
                 Iterator name_RU_Iterator = Arrays.asList(name_RU).iterator();
                 if (!type.equals("AD")) {
-                    T_iterator = Arrays.asList(boxArray(T)).iterator();
+                    T_index = 0;
                 }
-                caseI_Iterator = Arrays.asList(caseI_KI).iterator();
-                caseD_Iterator = Arrays.asList(caseD_KD).iterator();
-                caseF_Iterator = Arrays.asList(caseF_KF).iterator();
-                caseJ_Iterator = Arrays.asList(caseJ_KJ).iterator();
-                casec_Iterator = Arrays.asList(casec_RS).iterator();
-                caseet_Iterator = Arrays.asList(caseet_RS).iterator();
-                caseec_Iterator = Arrays.asList(caseec_RU).iterator();
-                cases_Iterator = Arrays.asList(cases_RU).iterator();
-                casearray_Iterator = Arrays.asList(boxArray(casearray_N))
-                        .iterator();
-                nesttype_RS_Iterator = Arrays.asList(nesttype_RS).iterator();
-                nestpair_N_Iterator = Arrays.asList(boxArray(nestpair_N))
-                        .iterator();
+                caseI_KI_Index = 0;
+                caseD_KD_Index = 0;
+                caseF_KF_Index = 0;
+                caseJ_KJ_Index = 0;
+                casec_RS_Index = 0;
+                caseet_RS_Index = 0;
+                caseec_RU_Index = 0;
+                cases_RU_Index = 0;
+                casearray_N_Index = 0;
+                nesttype_RS_Index = 0;
+                nestpair_N_Index = 0;
                 nestname_RU_Iterator = Arrays.asList(nestname_RU).iterator();
                 if (type.equals("RVA") || type.equals("RIA")) {
                     for (int i = 0; i < anno_N.length; i++) {
@@ -135,10 +134,9 @@
                                 pair_N[i], name_RU_Iterator));
                     }
                 } else if (type.equals("RVPA") || type.equals("RIPA")) {
-                    anno_N_Iterator = Arrays.asList(boxArray(anno_N))
-                            .iterator();
+                    anno_N_Index = 0;
                     type_RS_Iterator = Arrays.asList(type_RS).iterator();
-                    pair_N_Iterator = Arrays.asList(pair_N).iterator();
+                    pair_N_Index = 0;
                     for (int i = 0; i < param_NB.length; i++) {
                         attributes.add(getParameterAttribute(param_NB[i],
                                 name_RU_Iterator));
@@ -169,8 +167,8 @@
             Iterator namesIterator) {
         ParameterAnnotation[] parameter_annotations = new ParameterAnnotation[numParameters];
         for (int i = 0; i < numParameters; i++) {
-            int numAnnotations = ((Integer) anno_N_Iterator.next()).intValue();
-            int[] pairCounts = (int[]) pair_N_Iterator.next();
+            int numAnnotations = anno_N[anno_N_Index++];
+            int[] pairCounts = pair_N[pair_N_Index++];
             Annotation[] annotations = new Annotation[numAnnotations];
             for (int j = 0; j < annotations.length; j++) {
                 annotations[j] = getAnnotation(
@@ -190,7 +188,7 @@
         ElementValue[] elementValues = new ElementValue[pairCount];
         for (int j = 0; j < elementNames.length; j++) {
             elementNames[j] = (CPUTF8) namesIterator.next();
-            int t = ((Integer) T_iterator.next()).intValue();
+            int t = T[T_index++];
             elementValues[j] = new ElementValue(t, getNextValue(t));
         }
         return new Annotation(pairCount, type, elementNames, elementValues);
@@ -203,46 +201,38 @@
         case 'I':
         case 'S':
         case 'Z':
-            return caseI_Iterator.next();
+            return caseI_KI[caseI_KI_Index++];
         case 'D':
-            return caseD_Iterator.next();
+            return caseD_KD[caseD_KD_Index++];
         case 'F':
-            return caseF_Iterator.next();
+            return caseF_KF[caseF_KF_Index++];
         case 'J':
-            return caseJ_Iterator.next();
+            return caseJ_KJ[caseJ_KJ_Index++];
         case 'c':
-            return casec_Iterator.next();
+            return casec_RS[casec_RS_Index++];
         case 'e':
             // TODO: check this - it may not work if the first string already
             // has a colon in it
-            String enumString = caseet_Iterator.next() + ":"
-                    + caseec_Iterator.next();
+            String enumString = caseet_RS[caseet_RS_Index++] + ":"
+                    + caseec_RU[caseec_RU_Index++];
             return cpBands.cpNameAndTypeValue(enumString);
         case 's':
-            return cases_Iterator.next();
+            return cases_RU[cases_RU_Index++];
         case '[':
-            int arraySize = ((Integer) casearray_Iterator.next()).intValue();
+            int arraySize = casearray_N[casearray_N_Index++];
             ElementValue[] nestedArray = new ElementValue[arraySize];
             for (int i = 0; i < arraySize; i++) {
-                int nextT = ((Integer) T_iterator.next()).intValue();
+                int nextT = T[T_index++];
                 nestedArray[i] = new ElementValue(nextT, getNextValue(nextT));
             }
             return nestedArray;
         case '@':
-            CPUTF8 type = (CPUTF8) nesttype_RS_Iterator.next();
-            int numPairs = ((Integer) nestpair_N_Iterator.next()).intValue();
+            CPUTF8 type = (CPUTF8) nesttype_RS[nesttype_RS_Index++];
+            int numPairs = nestpair_N[nestpair_N_Index++];
 
             return getAnnotation(type, numPairs, nestname_RU_Iterator);
         }
         return null;
     }
 
-    private Integer[] boxArray(int[] unboxed) {
-        Integer[] boxed = new Integer[unboxed.length];
-        for (int i = 0; i < boxed.length; i++) {
-            boxed[i] = new Integer(unboxed[i]);
-        }
-        return boxed;
-    }
-
 }
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
Mon Jul 21 03:33:32 2008
@@ -20,7 +20,6 @@
 import java.io.InputStream;
 import java.io.StringReader;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.BHSDCodec;
@@ -76,13 +75,12 @@
      */
     public List parseAttributes(InputStream in, int occurrenceCount)
             throws IOException, Pack200Exception {
-        for (Iterator iter = attributeLayoutElements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter
-                    .next();
+        for(int i = 0; i < attributeLayoutElements.size(); i++) {
+            AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElements.get(i);
             element.readBands(in, occurrenceCount);
         }
 
-        List attributes = new ArrayList();
+        List attributes = new ArrayList(occurrenceCount);
         for (int i = 0; i < occurrenceCount; i++) {
             attributes.add(getOneAttribute(i, attributeLayoutElements));
         }
@@ -101,9 +99,8 @@
         NewAttribute attribute = new NewAttribute(segment.getCpBands()
                 .cpUTF8Value(attributeLayout.getName()),
                 attributeLayout.getIndex());
-        for (Iterator iter = elements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter
-                    .next();
+        for(int i = 0; i < elements.size(); i++) {
+            AttributeLayoutElement element = (AttributeLayoutElement) elements.get(i);
             element.addToAttribute(index, attribute);
         }
         return attribute;
@@ -141,8 +138,8 @@
             if (element instanceof Callable) {
                 Callable callable = (Callable) element;
                 List body = callable.body; // Look for calls in the body
-                for (Iterator iter = body.iterator(); iter.hasNext();) {
-                    LayoutElement layoutElement = (LayoutElement) iter.next();
+                for(int iIndex = 0; iIndex < body.size(); iIndex++) {
+                    LayoutElement layoutElement = (LayoutElement) body.get(iIndex);
                     if (layoutElement instanceof Call) {
                         // Set the callable for each call
                         Call call = (Call) layoutElement;
@@ -453,8 +450,8 @@
             for (int i = 0; i < count; i++) {
                 arrayCount += countElement.getValue(i);
             }
-            for (Iterator iter = layoutElements.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < layoutElements.size(); i++) {
+                LayoutElement element = (LayoutElement) layoutElements.get(i);
                 element.readBands(in, arrayCount);
             }
         }
@@ -470,8 +467,8 @@
             }
             long numElements = countElement.getValue(index);
             for (int i = offset; i < offset + numElements; i++) {
-                for (Iterator iter = layoutElements.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for (int it = 0; it < layoutElements.size(); it++) {
+                    LayoutElement element = (LayoutElement) layoutElements.get(it);
                     element.addToAttribute(i, attribute);
                 }
             }
@@ -514,8 +511,8 @@
             // Count number of default cases then read the default bands
             for (int i = 0; i < values.length; i++) {
                 boolean found = false;
-                for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
-                    UnionCase unionCase = (UnionCase) iter.next();
+                for(int it = 0; it < unionCases.size(); it++) {
+                    UnionCase unionCase = (UnionCase) unionCases.get(it);
                     if (unionCase.hasTag(values[i])) {
                         found = true;
                     }
@@ -525,8 +522,8 @@
                 }
             }
             if (defaultCaseBody != null) {
-                for (Iterator iter = defaultCaseBody.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for(int i = 0; i < defaultCaseBody.size(); i++) {
+                    LayoutElement element = (LayoutElement) defaultCaseBody.get(i);
                     element.readBands(in, defaultCount);
                 }
             }
@@ -538,8 +535,8 @@
             long[] tagBand = unionTag.band;
             long tag = unionTag.getValue(n);
             boolean defaultCase = true;
-            for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
-                UnionCase element = (UnionCase) iter.next();
+            for(int i = 0; i < unionCases.size(); i++) {
+                UnionCase element = (UnionCase) unionCases.get(i);
                 if (element.hasTag(tag)) {
                     defaultCase = false;
                     for (int j = 0; j < n; j++) {
@@ -555,8 +552,8 @@
                 int defaultOffset = 0;
                 for (int j = 0; j < n; j++) {
                     boolean found = false;
-                    for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
-                        UnionCase element = (UnionCase) iter.next();
+                    for(int i = 0; i < unionCases.size(); i++) {
+                        UnionCase element = (UnionCase) unionCases.get(i);
                         if (element.hasTag(tagBand[j])) {
                             found = true;
                         }
@@ -566,9 +563,8 @@
                     }
                 }
                 if (defaultCaseBody != null) {
-                    for (Iterator iter = defaultCaseBody.iterator(); iter
-                            .hasNext();) {
-                        LayoutElement element = (LayoutElement) iter.next();
+                    for(int i = 0; i < defaultCaseBody.size(); i++) {
+                        LayoutElement element = (LayoutElement) defaultCaseBody.get(i);
                         element.addToAttribute(defaultOffset, attribute);
                     }
                 }
@@ -718,8 +714,8 @@
          * @param attribute
          */
         public void addNextToAttribute(NewAttribute attribute) {
-            for (Iterator iter = body.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < body.size(); i++) {
+                LayoutElement element = (LayoutElement) body.get(i);
                 element.addToAttribute(index, attribute);
             }
             index++;
@@ -737,16 +733,16 @@
         public void readBands(InputStream in, int count) throws IOException,
                 Pack200Exception {
             count += this.count;
-            for (Iterator iter = body.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < body.size(); i++) {
+                LayoutElement element = (LayoutElement) body.get(i);
                 element.readBands(in, count);
             }
         }
 
         public void addToAttribute(int n, NewAttribute attribute) {
             // Ignore n because bands also contain element parts from calls
-            for (Iterator iter = body.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < body.size(); i++) {
+                LayoutElement element = (LayoutElement) body.get(i);
                 element.addToAttribute(index, attribute);
             }
             index++;
@@ -789,8 +785,8 @@
         public void readBands(InputStream in, int count) throws IOException,
                 Pack200Exception {
             if (body != null) {
-                for (Iterator iter = body.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for(int i = 0; i < body.size(); i++) {
+                    LayoutElement element = (LayoutElement) body.get(i);
                     element.readBands(in, count);
                 }
             }
@@ -798,8 +794,8 @@
 
         public void addToAttribute(int index, NewAttribute attribute) {
             if (body != null) {
-                for (Iterator iter = body.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for(int i = 0; i < body.size(); i++) {
+                    LayoutElement element = (LayoutElement) body.get(i);
                     element.addToAttribute(index, attribute);
                 }
             }
@@ -943,9 +939,8 @@
     public void setBackwardsCalls(int[] backwardsCalls) throws IOException {
         int index = 0;
         parseLayout();
-        for (Iterator iter = attributeLayoutElements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter
-                    .next();
+        for(int i = 0; i < attributeLayoutElements.size(); i++) {
+            AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElements.get(i);
             if (element instanceof Callable
                     && ((Callable) element).isBackwardsCallable()) {
                 ((Callable) element).addCount(backwardsCalls[index]);

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
Mon Jul 21 03:33:32 2008
@@ -24,7 +24,6 @@
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
@@ -157,7 +156,7 @@
         // that will
         // be written out. Keep SourceFileAttributes out since we just
         // did them above.
-        ArrayList classAttributesWithoutSourceFileAttribute = new ArrayList();
+        ArrayList classAttributesWithoutSourceFileAttribute = new ArrayList(classAttributes.size());
         for (int index = 0; index < classAttributes.size(); index++) {
             Attribute attrib = (Attribute) classAttributes.get(index);
             if (!attrib.isSourceFileAttribute()) {
@@ -313,10 +312,10 @@
      *         have to determine if this is the case.
      */
     private IcTuple[] computeIcStored(IcTuple[] ic_local, IcTuple[] ic_relevant) {
-        List result = new ArrayList();
-        List resultCopy = new ArrayList();
-        List localList = new ArrayList();
-        List relevantList = new ArrayList();
+        List result = new ArrayList(ic_relevant.length);
+        List resultCopy = new ArrayList(ic_relevant.length);
+        List localList = new ArrayList(ic_relevant.length);
+        List relevantList = new ArrayList(ic_relevant.length);
         if (ic_local != null) {
             // If ic_local is null, this code doesn't get
             // executed - which means the list ends up being
@@ -335,14 +334,10 @@
 
         // Since we're removing while iterating, iterate over
         // a copy.
-        Iterator it = resultCopy.iterator();
-
-        while (it.hasNext()) {
-            IcTuple tuple = (IcTuple) it.next();
+        for(int i = 0; i < resultCopy.size(); i++) {
+            IcTuple tuple = (IcTuple) resultCopy.get(i);
             if (localList.contains(tuple) && relevantList.contains(tuple)) {
-                while (result.remove(tuple)) {
-                }
-                ;
+                while (result.remove(tuple));
             }
         }
         IcTuple[] resultArray = new IcTuple[result.size()];

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CPMember.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CPMember.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CPMember.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CPMember.java
Mon Jul 21 03:33:32 2008
@@ -19,7 +19,6 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -70,8 +69,8 @@
         super.resolve(pool);
         nameIndex = pool.indexOf(name);
         descriptorIndex = pool.indexOf(descriptor);
-        for (Iterator it = attributes.iterator(); it.hasNext();) {
-            Attribute attribute = (Attribute) it.next();
+        for(int it = 0; it < attributes.size(); it++) {
+            Attribute attribute = (Attribute) attributes.get(it);
             attribute.resolve(pool);
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java
Mon Jul 21 03:33:32 2008
@@ -20,7 +20,6 @@
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeSet;
@@ -66,8 +65,8 @@
         boolean added = true;
 
         // initial assignment
-        ArrayList parents = new ArrayList();
-        ArrayList children = new ArrayList();
+        ArrayList parents = new ArrayList(512);
+        ArrayList children = new ArrayList(512);
 
         // adding old entries
         parents.addAll(entries);
@@ -84,9 +83,8 @@
 
             // get the parents' children and add them to buffer
             // concurrently add parents to target storage
-            Iterator i = parents.iterator();
-            while(i.hasNext()) {
-                ClassFileEntry entry = (ClassFileEntry)i.next();
+            for(int indexParents = 0; indexParents < parents.size(); indexParents++) {
+                ClassFileEntry entry = (ClassFileEntry) parents.get(indexParents);
 
                 // traverse children
                 ClassFileEntry[] entryChildren = entry.getNestedClassFileEntries();
@@ -150,18 +148,16 @@
 
         resolved = true;
 
-        Iterator it = entries.iterator();
-        while (it.hasNext()) {
-            ClassFileEntry entry = (ClassFileEntry) it.next();
+        for(int it = 0; it < entries.size(); it++) {
+            ClassFileEntry entry = (ClassFileEntry) entries.get(it);
             entry.resolve(this);
         }
-        it = others.iterator();
-        while (it.hasNext()) {
-            ClassFileEntry entry = (ClassFileEntry) it.next();
+
+        for(int it = 0; it < others.size(); it++) {
+            ClassFileEntry entry = (ClassFileEntry) others.get(it);
             entry.resolve(this);
         }
 
-
     }
 
     private void initialSort() {
@@ -184,8 +180,10 @@
             }
 
         });
-        for (Iterator iterator = entries.iterator(); iterator.hasNext();) {
-            ConstantPoolEntry entry = (ConstantPoolEntry) iterator.next();
+
+
+        for(int index = 0; index < entries.size(); index++) {
+            ConstantPoolEntry entry = (ConstantPoolEntry) entries.get(index);
             if(entry.getGlobalIndex() == -1) {
                 if (entry instanceof CPUTF8) {
                     cpUtf8sNotInCpAll.add(entry);
@@ -214,10 +212,9 @@
      * NOTE: when this list is answered, the classes may not yet be resolved.
      */
     public List allClasses() {
-        List classesList = new ArrayList();
-        Iterator it = entries.iterator();
-        while (it.hasNext()) {
-            ConstantPoolEntry entry = (ConstantPoolEntry) it.next();
+        List classesList = new ArrayList(entries.size());
+        for(int i = 0; i < entries.size(); i++) {
+            ConstantPoolEntry entry = (ConstantPoolEntry) entries.get(i);
             if (entry instanceof CPClass) {
                 classesList.add(entry);
             }
@@ -231,11 +228,12 @@
         // references to objects which need to be at the
         // start of the class pool
 
-        Iterator it = entries.iterator();
-        ArrayList startOfPool = new ArrayList();
-        ArrayList finalSort = new ArrayList();
-        while (it.hasNext()) {
-            ClassFileEntry nextEntry = (ClassFileEntry) it.next();
+
+        ArrayList startOfPool = new ArrayList(entries.size());
+        ArrayList finalSort = new ArrayList(entries.size());
+
+        for(int i = 0; i < entries.size(); i++) {
+            ClassFileEntry nextEntry = (ClassFileEntry) entries.get(i);
             if (mustStartClassPool.contains(nextEntry)) {
                 startOfPool.add(nextEntry);
             } else {
@@ -249,9 +247,9 @@
         int index = 0;
 
         entries.clear();
-        Iterator itStart = startOfPool.iterator();
-        while (itStart.hasNext()) {
-            ClassFileEntry entry = (ClassFileEntry) itStart.next();
+
+        for(int itIndex = 0; itIndex < startOfPool.size(); itIndex++) {
+            ClassFileEntry entry = (ClassFileEntry) startOfPool.get(itIndex);
             indexCache.put(entry, new Integer(index));
 
             if (entry instanceof CPLong || entry instanceof CPDouble) {
@@ -264,9 +262,8 @@
             }
         }
 
-        it = finalSort.iterator();
-        while (it.hasNext()) {
-            ClassFileEntry entry = (ClassFileEntry) it.next();
+        for(int itFinal = 0; itFinal < finalSort.size(); itFinal++) {
+            ClassFileEntry entry = (ClassFileEntry) finalSort.get(itFinal);
             indexCache.put(entry, new Integer(index));
 
             if (entry instanceof CPLong || entry instanceof CPDouble) {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CodeAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CodeAttribute.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CodeAttribute.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/CodeAttribute.java
Mon Jul 21 03:33:32 2008
@@ -19,7 +19,6 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.unpack200.Segment;
@@ -89,9 +88,8 @@
 
     protected int getLength() {
         int attributesSize = 0;
-        Iterator it = attributes.iterator();
-        while (it.hasNext()) {
-            Attribute attribute = (Attribute) it.next();
+        for(int it = 0; it < attributes.size(); it++) {
+            Attribute attribute = (Attribute) attributes.get(it);
             attributesSize += attribute.getLengthIncludingHeader();
         }
         return 2 + 2 + 4 + codeLength + 2 + exceptionTable.size()
@@ -99,13 +97,13 @@
     }
 
     protected ClassFileEntry[] getNestedClassFileEntries() {
-        ArrayList nestedEntries = new ArrayList();
+        ArrayList nestedEntries = new ArrayList(attributes.size() + byteCodes.size() + 10);
         nestedEntries.add(getAttributeName());
         nestedEntries.addAll(byteCodes);
         nestedEntries.addAll(attributes);
         // Don't forget to add the ExceptionTable catch_types
-        for (Iterator iter = exceptionTable.iterator(); iter.hasNext();) {
-            ExceptionTableEntry entry = (ExceptionTableEntry) iter.next();
+        for(int iter = 0; iter < exceptionTable.size(); iter++) {
+            ExceptionTableEntry entry = (ExceptionTableEntry) exceptionTable.get(iter);
             CPClass catchType = entry.getCatchType();
             // If the catch type is null, this is a finally
             // block. If it's not null, we need to add the
@@ -122,18 +120,18 @@
 
     protected void resolve(ClassConstantPool pool) {
         super.resolve(pool);
-        Iterator it = attributes.iterator();
-        while (it.hasNext()) {
-            Attribute attribute = (Attribute) it.next();
+        for(int it = 0; it < attributes.size(); it++) {
+            Attribute attribute = (Attribute) attributes.get(it);
             attribute.resolve(pool);
         }
-        it = byteCodes.iterator();
-        while (it.hasNext()) {
-            ByteCode byteCode = (ByteCode) it.next();
+
+        for(int it = 0; it < byteCodes.size(); it++) {
+            ByteCode byteCode = (ByteCode) byteCodes.get(it);
             byteCode.resolve(pool);
         }
-        for (Iterator iter = exceptionTable.iterator(); iter.hasNext();) {
-            ExceptionTableEntry entry = (ExceptionTableEntry) iter.next();
+
+        for(int it = 0; it < exceptionTable.size(); it++) {
+            ExceptionTableEntry entry = (ExceptionTableEntry) exceptionTable.get(it);
             entry.resolve(pool);
         }
     }
@@ -145,23 +143,22 @@
     protected void writeBody(DataOutputStream dos) throws IOException {
         dos.writeShort(maxStack);
         dos.writeShort(maxLocals);
+
         dos.writeInt(codeLength);
-        Iterator it = byteCodes.iterator();
-        while (it.hasNext()) {
-            ByteCode byteCode = (ByteCode) it.next();
+        for(int it = 0; it < byteCodes.size(); it++) {
+            ByteCode byteCode = (ByteCode) byteCodes.get(it);
             byteCode.write(dos);
         }
+
         dos.writeShort(exceptionTable.size());
-        Iterator exceptionTableEntries = exceptionTable.iterator();
-        while (exceptionTableEntries.hasNext()) {
-            ExceptionTableEntry entry = (ExceptionTableEntry) exceptionTableEntries
-                    .next();
+        for(int it = 0; it < exceptionTable.size(); it++) {
+            ExceptionTableEntry entry = (ExceptionTableEntry) exceptionTable.get(it);
             entry.write(dos);
         }
+
         dos.writeShort(attributes.size());
-        it = attributes.iterator();
-        while (it.hasNext()) {
-            Attribute attribute = (Attribute) it.next();
+        for(int it = 0; it < attributes.size(); it++) {
+            Attribute attribute = (Attribute) attributes.get(it);
             attribute.write(dos);
         }
     }
@@ -190,8 +187,8 @@
     }
 
     public void renumber(List byteCodeOffsets) {
-        for (Iterator iter = exceptionTable.iterator(); iter.hasNext();) {
-            ExceptionTableEntry entry = (ExceptionTableEntry) iter.next();
+        for(int iter = 0; iter < exceptionTable.size(); iter++) {
+            ExceptionTableEntry entry = (ExceptionTableEntry) exceptionTable.get(iter);
             entry.renumber(byteCodeOffsets);
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/InnerClassesAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/InnerClassesAttribute.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/InnerClassesAttribute.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/InnerClassesAttribute.java
Mon Jul 21 03:33:32 2008
@@ -19,7 +19,6 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -138,9 +137,8 @@
 
     protected void resolve(ClassConstantPool pool) {
         super.resolve(pool);
-        Iterator it = innerClasses.iterator();
-        while (it.hasNext()) {
-            InnerClassesEntry entry = (InnerClassesEntry) it.next();
+        for(int it = 0; it < innerClasses.size(); it++) {
+            InnerClassesEntry entry = (InnerClassesEntry) innerClasses.get(it);
             entry.resolve(pool);
         }
     }
@@ -156,9 +154,9 @@
 
     protected void writeBody(DataOutputStream dos) throws IOException {
         dos.writeShort(innerClasses.size());
-        Iterator it = innerClasses.iterator();
-        while (it.hasNext()) {
-            InnerClassesEntry entry = (InnerClassesEntry) it.next();
+
+        for(int it = 0; it < innerClasses.size(); it++) {
+            InnerClassesEntry entry = (InnerClassesEntry) innerClasses.get(it);
             entry.write(dos);
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java?rev=678386&r1=678385&r2=678386&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java
Mon Jul 21 03:33:32 2008
@@ -48,8 +48,8 @@
      */
     protected int getLength() {
         int length = 0;
-        for (Iterator iter = lengths.iterator(); iter.hasNext();) {
-            length += ((Integer) iter.next()).intValue();
+        for(int iter = 0; iter < lengths.size(); iter++) {
+            length += ((Integer)lengths.get(iter)).intValue();
         }
         return length;
     }
@@ -150,8 +150,8 @@
 
     protected void resolve(ClassConstantPool pool) {
         super.resolve(pool);
-        for (Iterator iter = body.iterator(); iter.hasNext();) {
-            Object element = iter.next();
+        for(int iter = 0; iter < body.size(); iter++) {
+            Object element = body.get(iter);
             if (element instanceof ClassFileEntry) {
                 ((ClassFileEntry) element).resolve(pool);
             }



Mime
View raw message