Title: [94475] trunk/Source/_javascript_Core
Revision
94475
Author
msab...@apple.com
Date
2011-09-02 18:08:10 -0700 (Fri, 02 Sep 2011)

Log Message

Replace local implementation of string equals() methods with UString versions
https://bugs.webkit.org/show_bug.cgi?id=67342

In preparation to allowing StringImpl to be backed by 8 bit 
characters when appropriate, we need to eliminate or change the
usage of StringImpl::characters(). Change the uses of characters()
that are used to implement redundant equals() methods.

Reviewed by Gavin Barraclough.

* runtime/Identifier.cpp:
(JSC::Identifier::equal):
* runtime/Identifier.h:
(JSC::Identifier::equal):
* wtf/text/AtomicString.cpp:
(WTF::CStringTranslator::equal): Moved an optimized method to here.
(WTF::operator==):
* wtf/text/StringImpl.cpp:
(WTF::equal):
* wtf/text/StringImpl.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (94474 => 94475)


--- trunk/Source/_javascript_Core/ChangeLog	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-09-03 01:08:10 UTC (rev 94475)
@@ -1,5 +1,28 @@
 2011-09-02  Michael Saboff  <msab...@apple.com>
 
+        Replace local implementation of string equals() methods with UString versions
+        https://bugs.webkit.org/show_bug.cgi?id=67342
+
+        In preparation to allowing StringImpl to be backed by 8 bit 
+        characters when appropriate, we need to eliminate or change the
+        usage of StringImpl::characters(). Change the uses of characters()
+        that are used to implement redundant equals() methods.
+
+        Reviewed by Gavin Barraclough.
+
+        * runtime/Identifier.cpp:
+        (JSC::Identifier::equal):
+        * runtime/Identifier.h:
+        (JSC::Identifier::equal):
+        * wtf/text/AtomicString.cpp:
+        (WTF::CStringTranslator::equal): Moved an optimized method to here.
+        (WTF::operator==):
+        * wtf/text/StringImpl.cpp:
+        (WTF::equal):
+        * wtf/text/StringImpl.h:
+
+2011-09-02  Michael Saboff  <msab...@apple.com>
+
         Add JSC:RegExp functional tests
         https://bugs.webkit.org/show_bug.cgi?id=67339
 

Modified: trunk/Source/_javascript_Core/_javascript_Core.exp (94474 => 94475)


--- trunk/Source/_javascript_Core/_javascript_Core.exp	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/_javascript_Core.exp	2011-09-03 01:08:10 UTC (rev 94475)
@@ -108,7 +108,6 @@
 __ZN3JSC10Identifier3addEPNS_9ExecStateEPKc
 __ZN3JSC10Identifier4fromEPNS_9ExecStateEi
 __ZN3JSC10Identifier4fromEPNS_9ExecStateEj
-__ZN3JSC10Identifier5equalEPKN3WTF10StringImplEPKc
 __ZN3JSC10Identifier8toUInt32ERKNS_7UStringERb
 __ZN3JSC10JSFunction14finishCreationEPNS_9ExecStateEPNS_14JSGlobalObjectEPNS_18FunctionExecutableEPNS_14ScopeChainNodeE
 __ZN3JSC10JSFunction14finishCreationEPNS_9ExecStateEPNS_14JSGlobalObjectEiRKNS_10IdentifierEPNS_14ExecutableBaseE
@@ -477,6 +476,7 @@
 __ZN3WTF5MutexC1Ev
 __ZN3WTF5MutexD1Ev
 __ZN3WTF5equalEPKNS_10StringImplEPKc
+__ZN3WTF5equalEPKNS_10StringImplEPKtj
 __ZN3WTF5equalEPKNS_10StringImplES2_
 __ZN3WTF5yieldEv
 __ZN3WTF6String26fromUTF8WithLatin1FallbackEPKcm
@@ -524,8 +524,6 @@
 __ZN3WTF9dayInYearEdi
 __ZN3WTF9emptyAtomE
 __ZN3WTF9xmlnsAtomE
-__ZN3WTFeqERKNS_12AtomicStringEPKc
-__ZN3WTFeqERKNS_12AtomicStringERKNS_6VectorItLm0EEE
 __ZN3WTFeqERKNS_7CStringES2_
 __ZNK3JSC10JSFunction23isHostFunctionNonInlineEv
 __ZNK3JSC11Interpreter14retrieveCallerEPNS_9ExecStateEPNS_10JSFunctionE

Modified: trunk/Source/_javascript_Core/runtime/Identifier.cpp (94474 => 94475)


--- trunk/Source/_javascript_Core/runtime/Identifier.cpp	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/runtime/Identifier.cpp	2011-09-03 01:08:10 UTC (rev 94475)
@@ -67,16 +67,6 @@
     delete table;
 }
 
-bool Identifier::equal(const StringImpl* r, const char* s)
-{
-    int length = r->length();
-    const UChar* d = r->characters();
-    for (int i = 0; i != length; ++i)
-        if (d[i] != (unsigned char)s[i])
-            return false;
-    return s[length] == 0;
-}
-
 struct IdentifierCStringTranslator {
     static unsigned hash(const char* c)
     {

Modified: trunk/Source/_javascript_Core/runtime/Identifier.h (94474 => 94475)


--- trunk/Source/_javascript_Core/runtime/Identifier.h	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/runtime/Identifier.h	2011-09-03 01:08:10 UTC (rev 94475)
@@ -135,15 +135,14 @@
         return !Identifier::equal(a, b);
     }
 
+    inline bool Identifier::equal(const StringImpl* r, const char* s)
+    {
+        return WTF::equal(r, s);
+    }
+    
     inline bool Identifier::equal(const StringImpl* r, const UChar* s, unsigned length)
     {
-        if (r->length() != length)
-            return false;
-        const UChar* d = r->characters();
-        for (unsigned i = 0; i != length; ++i)
-            if (d[i] != s[i])
-                return false;
-        return true;
+        return WTF::equal(r, s, length);
     }
     
     IdentifierTable* createIdentifierTable();

Modified: trunk/Source/_javascript_Core/wtf/text/AtomicString.cpp (94474 => 94475)


--- trunk/Source/_javascript_Core/wtf/text/AtomicString.cpp	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/wtf/text/AtomicString.cpp	2011-09-03 01:08:10 UTC (rev 94475)
@@ -90,16 +90,9 @@
         return StringHasher::computeHash(c);
     }
 
-    static bool equal(StringImpl* r, const char* s)
+    static inline bool equal(StringImpl* r, const char* s)
     {
-        int length = r->length();
-        const UChar* d = r->characters();
-        for (int i = 0; i != length; ++i) {
-            unsigned char c = s[i];
-            if (d[i] != c)
-                return false;
-        }
-        return !s[length];
+        return WTF::equal(r, s);
     }
 
     static void translate(StringImpl*& location, const char* const& c, unsigned hash)
@@ -110,16 +103,6 @@
     }
 };
 
-bool operator==(const AtomicString& a, const char* b)
-{ 
-    StringImpl* impl = a.impl();
-    if ((!impl || !impl->characters()) && !b)
-        return true;
-    if ((!impl || !impl->characters()) || !b)
-        return false;
-    return CStringTranslator::equal(impl, b); 
-}
-
 PassRefPtr<StringImpl> AtomicString::add(const char* c)
 {
     if (!c)
@@ -135,44 +118,6 @@
     unsigned length;
 };
 
-static inline bool equal(StringImpl* string, const UChar* characters, unsigned length)
-{
-    if (string->length() != length)
-        return false;
-
-    // FIXME: perhaps we should have a more abstract macro that indicates when
-    // going 4 bytes at a time is unsafe
-#if CPU(ARM) || CPU(SH4) || CPU(MIPS) || CPU(SPARC)
-    const UChar* stringCharacters = string->characters();
-    for (unsigned i = 0; i != length; ++i) {
-        if (*stringCharacters++ != *characters++)
-            return false;
-    }
-    return true;
-#else
-    /* Do it 4-bytes-at-a-time on architectures where it's safe */
-
-    const uint32_t* stringCharacters = reinterpret_cast<const uint32_t*>(string->characters());
-    const uint32_t* bufferCharacters = reinterpret_cast<const uint32_t*>(characters);
-
-    unsigned halfLength = length >> 1;
-    for (unsigned i = 0; i != halfLength; ++i) {
-        if (*stringCharacters++ != *bufferCharacters++)
-            return false;
-    }
-
-    if (length & 1 &&  *reinterpret_cast<const uint16_t*>(stringCharacters) != *reinterpret_cast<const uint16_t*>(bufferCharacters))
-        return false;
-
-    return true;
-#endif
-}
-
-bool operator==(const AtomicString& string, const Vector<UChar>& vector)
-{
-    return string.impl() && equal(string.impl(), vector.data(), vector.size());
-}
-
 struct UCharBufferTranslator {
     static unsigned hash(const UCharBuffer& buf)
     {

Modified: trunk/Source/_javascript_Core/wtf/text/AtomicString.h (94474 => 94475)


--- trunk/Source/_javascript_Core/wtf/text/AtomicString.h	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/wtf/text/AtomicString.h	2011-09-03 01:08:10 UTC (rev 94475)
@@ -135,7 +135,8 @@
 
 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); }
 bool operator==(const AtomicString& a, const char* b);
-bool operator==(const AtomicString& a, const Vector<UChar>& b);
+inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal(a.impl(), b); }
+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 char* 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.cpp (94474 => 94475)


--- trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp	2011-09-03 01:08:10 UTC (rev 94475)
@@ -995,6 +995,42 @@
     return !b[length];
 }
 
+bool equal(const StringImpl* a, const UChar* b, unsigned length)
+{
+    if (!a)
+        return !b;
+    if (!b)
+        return false;
+
+    if (a->length() != length)
+        return false;
+    // FIXME: perhaps we should have a more abstract macro that indicates when
+    // going 4 bytes at a time is unsafe
+#if CPU(ARM) || CPU(SH4) || CPU(MIPS) || CPU(SPARC)
+    const UChar* as = a->characters();
+    for (unsigned i = 0; i != length; ++i)
+        if (as[i] != b[i])
+            return false;
+    return true;
+#else
+    /* Do it 4-bytes-at-a-time on architectures where it's safe */
+    
+    const uint32_t* aCharacters = reinterpret_cast<const uint32_t*>(a->characters());
+    const uint32_t* bCharacters = reinterpret_cast<const uint32_t*>(b);
+    
+    unsigned halfLength = length >> 1;
+    for (unsigned i = 0; i != halfLength; ++i) {
+        if (*aCharacters++ != *bCharacters++)
+            return false;
+    }
+    
+    if (length & 1 &&  *reinterpret_cast<const uint16_t*>(aCharacters) != *reinterpret_cast<const uint16_t*>(bCharacters))
+        return false;
+    
+    return true;
+#endif
+}
+
 bool equalIgnoringCase(StringImpl* a, StringImpl* b)
 {
     return CaseFoldingHash::equal(a, b);

Modified: trunk/Source/_javascript_Core/wtf/text/StringImpl.h (94474 => 94475)


--- trunk/Source/_javascript_Core/wtf/text/StringImpl.h	2011-09-03 01:06:27 UTC (rev 94474)
+++ trunk/Source/_javascript_Core/wtf/text/StringImpl.h	2011-09-03 01:08:10 UTC (rev 94475)
@@ -347,6 +347,7 @@
 bool equal(const StringImpl*, const StringImpl*);
 bool equal(const StringImpl*, const char*);
 inline bool equal(const char* a, StringImpl* b) { return equal(b, a); }
+bool equal(const StringImpl*, const UChar*, unsigned);
 
 bool equalIgnoringCase(StringImpl*, StringImpl*);
 bool equalIgnoringCase(StringImpl*, const char*);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to