Title: [102692] trunk/Source/_javascript_Core
Revision
102692
Author
msab...@apple.com
Date
2011-12-13 11:39:12 -0800 (Tue, 13 Dec 2011)

Log Message

Cleanup of StringImpl::equal in r102631 post commit
https://bugs.webkit.org/show_bug.cgi?id=74421

Reviewed by Darin Adler.

* wtf/text/AtomicString.h:
(WTF::operator==): Removed cast no longer needed.
* wtf/text/StringImpl.h:
(WTF::equal): Changed template to several overloaded methods.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (102691 => 102692)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-13 18:48:21 UTC (rev 102691)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-13 19:39:12 UTC (rev 102692)
@@ -1,3 +1,15 @@
+2011-12-13  Michael Saboff  <msab...@apple.com>
+
+        Cleanup of StringImpl::equal in r102631 post commit
+        https://bugs.webkit.org/show_bug.cgi?id=74421
+
+        Reviewed by Darin Adler.
+
+        * wtf/text/AtomicString.h:
+        (WTF::operator==): Removed cast no longer needed.
+        * wtf/text/StringImpl.h:
+        (WTF::equal): Changed template to several overloaded methods.
+
 2011-12-12  Michael Saboff  <msab...@apple.com>
 
         Eliminate Duplicate word at a time equal code in StringImpl.cpp and StringHash.h

Modified: trunk/Source/_javascript_Core/wtf/text/AtomicString.h (102691 => 102692)


--- trunk/Source/_javascript_Core/wtf/text/AtomicString.h	2011-12-13 18:48:21 UTC (rev 102691)
+++ trunk/Source/_javascript_Core/wtf/text/AtomicString.h	2011-12-13 19:39:12 UTC (rev 102692)
@@ -139,7 +139,7 @@
 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); }
 bool operator==(const AtomicString&, const LChar*);
 inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
-inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a.impl() && equal(static_cast<StringImpl*>(a.impl()), b.data(), b.size()); }    
+inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a.impl() && equal(a.impl(), b.data(), b.size()); }    
 inline bool operator==(const AtomicString& a, const String& b) { return equal(a.impl(), b.impl()); }
 inline bool operator==(const LChar* a, const AtomicString& b) { return b == a; }
 inline bool operator==(const String& a, const AtomicString& b) { return equal(a.impl(), b.impl()); }

Modified: trunk/Source/_javascript_Core/wtf/text/StringImpl.h (102691 => 102692)


--- trunk/Source/_javascript_Core/wtf/text/StringImpl.h	2011-12-13 18:48:21 UTC (rev 102691)
+++ trunk/Source/_javascript_Core/wtf/text/StringImpl.h	2011-12-13 19:39:12 UTC (rev 102692)
@@ -562,97 +562,92 @@
 inline bool equal(const LChar* a, StringImpl* b) { return equal(b, a); }
 inline bool equal(const char* a, StringImpl* b) { return equal(b, reinterpret_cast<const LChar*>(a)); }
 bool equal(const StringImpl*, const UChar*, unsigned);
-template <typename CharTypeL, typename CharTypeR>
-    ALWAYS_INLINE bool equal(const CharTypeL*, const CharTypeR*, unsigned);
 
 // Do comparisons 8 or 4 bytes-at-a-time on architectures where it's safe.
 #if CPU(X86_64)
-template <>
-ALWAYS_INLINE bool equal<LChar, LChar>(const LChar* a, const LChar* b, unsigned length)
+ALWAYS_INLINE bool equal(const LChar* a, const LChar* b, unsigned length)
 {
     unsigned dwordLength = length >> 3;
-    
+
     if (dwordLength) {
         const uint64_t* aDWordCharacters = reinterpret_cast<const uint64_t*>(a);
         const uint64_t* bDWordCharacters = reinterpret_cast<const uint64_t*>(b);
-        
+
         for (unsigned i = 0; i != dwordLength; ++i) {
             if (*aDWordCharacters++ != *bDWordCharacters++)
                 return false;
         }
-        
+
         a = reinterpret_cast<const LChar*>(aDWordCharacters);
         b = reinterpret_cast<const LChar*>(bDWordCharacters);
     }
-    
+
     if (length & 4) {
         if (*reinterpret_cast<const uint32_t*>(a) != *reinterpret_cast<const uint32_t*>(b))
             return false;
-        
+
         a += 4;
         b += 4;
     }
-    
+
     if (length & 2) {
         if (*reinterpret_cast<const uint16_t*>(a) != *reinterpret_cast<const uint16_t*>(b))
             return false;
-        
+
         a += 2;
         b += 2;
     }
-    
+
     if (length & 1 && (*a != *b))
         return false;
-    
+
     return true;
 }
 
-template <>
-ALWAYS_INLINE bool equal<UChar, UChar>(const UChar* a, const UChar* b, unsigned length)
+ALWAYS_INLINE bool equal(const UChar* a, const UChar* b, unsigned length)
 {
     unsigned dwordLength = length >> 2;
     
     if (dwordLength) {
         const uint64_t* aDWordCharacters = reinterpret_cast<const uint64_t*>(a);
         const uint64_t* bDWordCharacters = reinterpret_cast<const uint64_t*>(b);
-        
+
         for (unsigned i = 0; i != dwordLength; ++i) {
             if (*aDWordCharacters++ != *bDWordCharacters++)
                 return false;
         }
-        
+
         a = reinterpret_cast<const UChar*>(aDWordCharacters);
         b = reinterpret_cast<const UChar*>(bDWordCharacters);
     }
-    
+
     if (length & 2) {
         if (*reinterpret_cast<const uint32_t*>(a) != *reinterpret_cast<const uint32_t*>(b))
             return false;
-        
+
         a += 2;
         b += 2;
     }
-    
+
     if (length & 1 && (*a != *b))
         return false;
-    
+
     return true;
 }
 #elif CPU(X86)
-template <>
-ALWAYS_INLINE bool equal<LChar, LChar>(const LChar* a, const LChar* b, unsigned length)
+ALWAYS_INLINE bool equal(const LChar* a, const LChar* b, unsigned length)
 {
     const uint32_t* aCharacters = reinterpret_cast<const uint32_t*>(a);
     const uint32_t* bCharacters = reinterpret_cast<const uint32_t*>(b);
-    
+
     unsigned wordLength = length >> 2;
     for (unsigned i = 0; i != wordLength; ++i) {
         if (*aCharacters++ != *bCharacters++)
             return false;
     }
-    
+
     length &= 3;
-    
+
     if (length) {
         const LChar* aRemainder = reinterpret_cast<const LChar*>(aCharacters);
         const LChar* bRemainder = reinterpret_cast<const LChar*>(bCharacters);
@@ -662,12 +657,11 @@
                 return false;
         }
     }
-    
+
     return true;
 }
 
-template <>
-ALWAYS_INLINE bool equal<UChar, UChar>(const UChar* a, const UChar* b, unsigned length)
+ALWAYS_INLINE bool equal(const UChar* a, const UChar* b, unsigned length)
 {
     const uint32_t* aCharacters = reinterpret_cast<const uint32_t*>(a);
     const uint32_t* bCharacters = reinterpret_cast<const uint32_t*>(b);
@@ -683,19 +677,48 @@
     
     return true;
 }
+#else
+ALWAYS_INLINE bool equal(const LChar* a, const LChar* b, unsigned length)
+{
+    for (unsigned i = 0; i != length; ++i) {
+        if (a[i] != b[i])
+            return false;
+    }
+
+    return true;
+}
+
+ALWAYS_INLINE bool equal(const UChar* a, const UChar* b, unsigned length)
+{
+    for (unsigned i = 0; i != length; ++i) {
+        if (a[i] != b[i])
+            return false;
+    }
+
+    return true;
+}
 #endif
 
-template <typename CharTypeL, typename CharTypeR>
-ALWAYS_INLINE bool equal(const CharTypeL* a, const CharTypeR* b, unsigned length)
+ALWAYS_INLINE bool equal(const LChar* a, const UChar* b, unsigned length)
 {
     for (unsigned i = 0; i != length; ++i) {
         if (a[i] != b[i])
             return false;
     }
-    
+
     return true;
 }
 
+ALWAYS_INLINE bool equal(const UChar* a, const LChar* b, unsigned length)
+{
+    for (unsigned i = 0; i != length; ++i) {
+        if (a[i] != b[i])
+            return false;
+    }
+
+    return true;
+}
+
 bool equalIgnoringCase(StringImpl*, StringImpl*);
 bool equalIgnoringCase(StringImpl*, const LChar*);
 inline bool equalIgnoringCase(const LChar* a, StringImpl* b) { return equalIgnoringCase(b, a); }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to