harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r678424 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200: IcBands.java IcTuple.java
Date Mon, 21 Jul 2008 14:06:44 GMT
Author: sjanuary
Date: Mon Jul 21 07:06:43 2008
New Revision: 678424

URL: http://svn.apache.org/viewvc?rev=678424&view=rev
Log:
Apply patch for HARMONY-5921 ([classlib][pack200][performance] IcBands.getRelevantIcTuples()
optimization)

Modified:
    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/IcTuple.java

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=678424&r1=678423&r2=678424&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 07:06:43 2008
@@ -19,7 +19,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.harmony.pack200.Codec;
 import org.apache.harmony.pack200.Pack200Exception;
@@ -118,11 +120,13 @@
      * @return array of IcTuple
      */
     public IcTuple[] getRelevantIcTuples(String className, ClassConstantPool cp) {
+        Set relevantTuplesContains = new HashSet();
         List relevantTuples = new ArrayList();
         IcTuple[] allTuples = getIcTuples();
         int allTuplesSize = allTuples.length;
         for (int index = 0; index < allTuplesSize; index++) {
             if (allTuples[index].shouldAddToRelevantForClassName(className)) {
+                relevantTuplesContains.add(allTuples[index]);
                 relevantTuples.add(allTuples[index]);
             }
         }
@@ -142,7 +146,7 @@
                     if (poolClassName.equals(allTuples[allTupleIndex]
                             .thisClassString())) {
                         // If the tuple isn't already in there, then add it
-                        if (relevantTuples.indexOf(allTuples[allTupleIndex]) == -1) {
+                        if (relevantTuplesContains.add(allTuples[allTupleIndex])) {
                             relevantTuples.add(allTuples[allTupleIndex]);
                             changed = true;
                         }
@@ -175,7 +179,7 @@
             if (tuplesToAdd.size() > 0) {
                 for(int index = 0; index < tuplesToAdd.size(); index++) {
                     IcTuple tuple = (IcTuple) tuplesToAdd.get(index);
-                    if (!relevantTuples.contains(tuple)) {
+                    if (relevantTuplesContains.add(tuple)) {
                         changedFixup = true;
                         relevantTuples.add(tuple);
                     }
@@ -189,7 +193,7 @@
         IcTuple[] orderedRelevantTuples = new IcTuple[relevantTuples.size()];
         int orderedRelevantIndex = 0;
         for (int index = 0; index < allTuplesSize; index++) {
-            if (relevantTuples.contains(allTuples[index])) {
+            if (relevantTuplesContains.contains(allTuples[index])) {
                 orderedRelevantTuples[orderedRelevantIndex] = allTuples[index];
                 orderedRelevantIndex++;
             }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java?rev=678424&r1=678423&r2=678424&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java
Mon Jul 21 07:06:43 2008
@@ -75,6 +75,7 @@
     private String cachedSimpleClassName;
     private boolean initialized;
     private boolean anonymous;
+    private boolean outerIsAnonymous;
     private boolean member = true;
     private int cachedOuterClassIndex = -1;
     private int cachedSimpleClassNameIndex = -1;
@@ -155,7 +156,12 @@
         return anonymous;
     }
 
+
     public boolean outerIsAnonymous() {
+        return outerIsAnonymous;
+    }
+
+    private boolean computeOuterIsAnonymous() {
         String[] result = innerBreakAtDollar(cachedOuterClassString);
         if (result.length == 0) {
             throw new Error(
@@ -250,6 +256,8 @@
                 member = true;
             }
         }
+
+        outerIsAnonymous = computeOuterIsAnonymous();
     }
 
     private boolean isAllDigits(String nameString) {
@@ -303,8 +311,21 @@
         return true;
     }
 
+    private boolean hashcodeComputed;
+    private int cachedHashCode;
+
+    private void generateHashCode() {
+        hashcodeComputed = true;
+        cachedHashCode = 17;
+        if(C != null) { cachedHashCode =+ C.hashCode(); }
+        if(C2 != null) { cachedHashCode =+ C2.hashCode(); }
+        if(N != null) { cachedHashCode =+ N.hashCode(); }
+    }
+
     public int hashCode() {
-        return 17 + C.hashCode() + C2.hashCode() + N.hashCode();
+        if (!hashcodeComputed)
+            generateHashCode();
+        return cachedHashCode;
     }
 
     public String getC() {



Mime
View raw message