harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r561231 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
Date Tue, 31 Jul 2007 04:29:49 GMT
Author: tonywu
Date: Mon Jul 30 21:29:47 2007
New Revision: 561231

URL: http://svn.apache.org/viewvc?view=rev&rev=561231
Log:
optimize for performance, avoid method call and access to instence variable

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java?view=diff&rev=561231&r1=561230&r2=561231
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java Mon Jul
30 21:29:47 2007
@@ -104,10 +104,22 @@
 	 * @param o
 	 *            the object to be searched
 	 */
-	public synchronized int search(Object o) {
-		int index = lastIndexOf(o);
-		if (index >= 0)
-			return (elementCount - index);
-		return -1;
+	public synchronized int search(Object object) {
+        final Object[] dumpArray = elementData;
+        final int size = elementCount;
+        if (object != null) {
+            for (int i = size - 1; i >= 0; i--) {
+                if (object.equals(dumpArray[i])) {
+                    return size - i;
+                }
+            }
+        } else {
+            for (int i = size - 1; i >= 0; i--) {
+                if (dumpArray[i] == null) {
+                    return size - i;
+                }
+            }
+        }
+        return -1;
 	}
 }



Mime
View raw message