harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r793821 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/String.java test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Date Tue, 14 Jul 2009 09:13:45 GMT
Author: tellison
Date: Tue Jul 14 09:13:44 2009
New Revision: 793821

URL: http://svn.apache.org/viewvc?rev=793821&view=rev
Log:
Improve string equality performance.  Don't use general regionMatches call but in-line the
char array comparison.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java?rev=793821&r1=793820&r2=793821&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java Tue Jul
14 09:13:44 2009
@@ -782,7 +782,12 @@
                     || (hashCode != s.hashCode && hashCode != 0 && s.hashCode
!= 0)) {
                 return false;
             }
-            return regionMatches(0, s, 0, count);
+            for (int i = 0; i < count; ++i) {
+                if (value[offset + i] != s.value[s.offset + i]) {
+                    return false;
+                }
+            }
+            return true;
         }
         return false;
     }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java?rev=793821&r1=793820&r2=793821&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Tue Jul 14 09:13:44 2009
@@ -321,8 +321,12 @@
      * @tests java.lang.String#equals(java.lang.Object)
      */
     public void test_equalsLjava_lang_Object() {
-        // Test for method boolean java.lang.String.equals(java.lang.Object)
-        assertTrue("String not equal", hw1.equals(hw2) && !(hw1.equals(comp11)));
+        assertEquals("String not equal", hw1, hw2);
+        assertEquals("Empty string equals check", "", "");
+        assertEquals("Null string equals check", (String)null, (String)null);
+        
+        assertFalse("Unequal strings reports as equal", hw1.equals(comp11));
+        assertFalse("Null string comparison failed", hw1.equals((String)null));        
     }
 
     /**



Mime
View raw message