Title: [152418] trunk/Source/WTF
Revision
152418
Author
[email protected]
Date
2013-07-05 10:25:08 -0700 (Fri, 05 Jul 2013)

Log Message

A lot of code duplication within StringImpl 'equal' functions
https://bugs.webkit.org/show_bug.cgi?id=118415

Reviewed by Anders Carlsson.

There has been a lot of code duplication within StringImpl 'equal' functions:
the whole logic was copied to every overloaded 'equal' function.
Fixed now using templates and std::equal.

* wtf/text/StringImpl.cpp:
(WTF::equalInternal):
(WTF::equal):
* wtf/text/StringImpl.h:
(WTF::arraysEqual):
(WTF::equal):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (152417 => 152418)


--- trunk/Source/WTF/ChangeLog	2013-07-05 16:35:48 UTC (rev 152417)
+++ trunk/Source/WTF/ChangeLog	2013-07-05 17:25:08 UTC (rev 152418)
@@ -1,5 +1,23 @@
 2013-07-05  Mikhail Pozdnyakov  <[email protected]>
 
+        A lot of code duplication within StringImpl 'equal' functions
+        https://bugs.webkit.org/show_bug.cgi?id=118415
+
+        Reviewed by Anders Carlsson.
+
+        There has been a lot of code duplication within StringImpl 'equal' functions:
+        the whole logic was copied to every overloaded 'equal' function.
+        Fixed now using templates and std::equal.
+
+        * wtf/text/StringImpl.cpp:
+        (WTF::equalInternal):
+        (WTF::equal):
+        * wtf/text/StringImpl.h:
+        (WTF::arraysEqual):
+        (WTF::equal):
+
+2013-07-05  Mikhail Pozdnyakov  <[email protected]>
+
         Remove code duplication from StringImpl create()/reallocate() methods
         https://bugs.webkit.org/show_bug.cgi?id=118355
 

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (152417 => 152418)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2013-07-05 16:35:48 UTC (rev 152417)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2013-07-05 17:25:08 UTC (rev 152418)
@@ -1718,21 +1718,31 @@
     return stringImplContentEqual(a, b);
 }
 
-bool equal(const StringImpl* a, const LChar* b, unsigned length)
+template <typename CharType>
+inline bool equalInternal(const StringImpl* a, const CharType* b, unsigned length)
 {
     if (!a)
         return !b;
     if (!b)
-        return !a;
-
-    if (length != a->length())
         return false;
 
+    if (a->length() != length)
+        return false;
     if (a->is8Bit())
         return equal(a->characters8(), b, length);
     return equal(a->characters16(), b, length);
 }
 
+bool equal(const StringImpl* a, const LChar* b, unsigned length)
+{
+    return equalInternal(a, b, length);
+}
+
+bool equal(const StringImpl* a, const UChar* b, unsigned length)
+{
+    return equalInternal(a, b, length);
+}
+
 bool equal(const StringImpl* a, const LChar* b)
 {
     if (!a)
@@ -1768,20 +1778,6 @@
     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;
-    if (a->is8Bit())
-        return equal(a->characters8(), b, length);
-    return equal(a->characters16(), b, length);
-}
-
 bool equalNonNull(const StringImpl* a, const StringImpl* b)
 {
     ASSERT(a && b);

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (152417 => 152418)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2013-07-05 16:35:48 UTC (rev 152417)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2013-07-05 17:25:08 UTC (rev 152418)
@@ -868,10 +868,10 @@
 WTF_EXPORT_STRING_API bool equal(const StringImpl*, const LChar*);
 inline bool equal(const StringImpl* a, const char* b) { return equal(a, reinterpret_cast<const LChar*>(b)); }
 WTF_EXPORT_STRING_API bool equal(const StringImpl*, const LChar*, unsigned);
+WTF_EXPORT_STRING_API bool equal(const StringImpl*, const UChar*, unsigned);
 inline bool equal(const StringImpl* a, const char* b, unsigned length) { return equal(a, reinterpret_cast<const LChar*>(b), length); }
 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)); }
-WTF_EXPORT_STRING_API bool equal(const StringImpl*, const UChar*, unsigned);
 WTF_EXPORT_STRING_API bool equalNonNull(const StringImpl* a, const StringImpl* b);
 
 // Do comparisons 8 or 4 bytes-at-a-time on architectures where it's safe.
@@ -1077,47 +1077,12 @@
     return isEqual;
 }
 #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;
-}
+ALWAYS_INLINE bool equal(const LChar* a, const LChar* b, unsigned length) { return std::equal(a, a + length, b); }
+ALWAYS_INLINE bool equal(const UChar* a, const UChar* b, unsigned length) { return std::equal(a, a + length, b); }
 #endif
 
-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;
-}
-
+ALWAYS_INLINE bool equal(const LChar* a, const UChar* b, unsigned length) { return std::equal(a, a + length, b); }
+ALWAYS_INLINE bool equal(const UChar* a, const LChar* b, unsigned length) { return std::equal(a, a + length, b); }
 WTF_EXPORT_STRING_API bool equalIgnoringCase(const StringImpl*, const StringImpl*);
 WTF_EXPORT_STRING_API bool equalIgnoringCase(const StringImpl*, const LChar*);
 inline bool equalIgnoringCase(const LChar* a, const StringImpl* b) { return equalIgnoringCase(b, a); }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to