Changeset 152418 in webkit


Ignore:
Timestamp:
Jul 5, 2013 10:25:08 AM (11 years ago)
Author:
mikhail.pozdnyakov@intel.com
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):

Location:
trunk/Source/WTF
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r152415 r152418  
     12013-07-05  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
     2
     3        A lot of code duplication within StringImpl 'equal' functions
     4        https://bugs.webkit.org/show_bug.cgi?id=118415
     5
     6        Reviewed by Anders Carlsson.
     7
     8        There has been a lot of code duplication within StringImpl 'equal' functions:
     9        the whole logic was copied to every overloaded 'equal' function.
     10        Fixed now using templates and std::equal.
     11
     12        * wtf/text/StringImpl.cpp:
     13        (WTF::equalInternal):
     14        (WTF::equal):
     15        * wtf/text/StringImpl.h:
     16        (WTF::arraysEqual):
     17        (WTF::equal):
     18
    1192013-07-05  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
    220
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r152415 r152418  
    17191719}
    17201720
    1721 bool equal(const StringImpl* a, const LChar* b, unsigned length)
     1721template <typename CharType>
     1722inline bool equalInternal(const StringImpl* a, const CharType* b, unsigned length)
    17221723{
    17231724    if (!a)
    17241725        return !b;
    17251726    if (!b)
    1726         return !a;
    1727 
    1728     if (length != a->length())
    17291727        return false;
    17301728
     1729    if (a->length() != length)
     1730        return false;
    17311731    if (a->is8Bit())
    17321732        return equal(a->characters8(), b, length);
    17331733    return equal(a->characters16(), b, length);
     1734}
     1735
     1736bool equal(const StringImpl* a, const LChar* b, unsigned length)
     1737{
     1738    return equalInternal(a, b, length);
     1739}
     1740
     1741bool equal(const StringImpl* a, const UChar* b, unsigned length)
     1742{
     1743    return equalInternal(a, b, length);
    17341744}
    17351745
     
    17671777
    17681778    return !b[length];
    1769 }
    1770 
    1771 bool equal(const StringImpl* a, const UChar* b, unsigned length)
    1772 {
    1773     if (!a)
    1774         return !b;
    1775     if (!b)
    1776         return false;
    1777 
    1778     if (a->length() != length)
    1779         return false;
    1780     if (a->is8Bit())
    1781         return equal(a->characters8(), b, length);
    1782     return equal(a->characters16(), b, length);
    17831779}
    17841780
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r152415 r152418  
    869869inline bool equal(const StringImpl* a, const char* b) { return equal(a, reinterpret_cast<const LChar*>(b)); }
    870870WTF_EXPORT_STRING_API bool equal(const StringImpl*, const LChar*, unsigned);
     871WTF_EXPORT_STRING_API bool equal(const StringImpl*, const UChar*, unsigned);
    871872inline bool equal(const StringImpl* a, const char* b, unsigned length) { return equal(a, reinterpret_cast<const LChar*>(b), length); }
    872873inline bool equal(const LChar* a, StringImpl* b) { return equal(b, a); }
    873874inline bool equal(const char* a, StringImpl* b) { return equal(b, reinterpret_cast<const LChar*>(a)); }
    874 WTF_EXPORT_STRING_API bool equal(const StringImpl*, const UChar*, unsigned);
    875875WTF_EXPORT_STRING_API bool equalNonNull(const StringImpl* a, const StringImpl* b);
    876876
     
    10781078}
    10791079#else
    1080 ALWAYS_INLINE bool equal(const LChar* a, const LChar* b, unsigned length)
    1081 {
    1082     for (unsigned i = 0; i != length; ++i) {
    1083         if (a[i] != b[i])
    1084             return false;
    1085     }
    1086 
    1087     return true;
    1088 }
    1089 
    1090 ALWAYS_INLINE bool equal(const UChar* a, const UChar* b, unsigned length)
    1091 {
    1092     for (unsigned i = 0; i != length; ++i) {
    1093         if (a[i] != b[i])
    1094             return false;
    1095     }
    1096 
    1097     return true;
    1098 }
    1099 #endif
    1100 
    1101 ALWAYS_INLINE bool equal(const LChar* a, const UChar* b, unsigned length)
    1102 {
    1103     for (unsigned i = 0; i != length; ++i) {
    1104         if (a[i] != b[i])
    1105             return false;
    1106     }
    1107 
    1108     return true;
    1109 }
    1110 
    1111 ALWAYS_INLINE bool equal(const UChar* a, const LChar* b, unsigned length)
    1112 {
    1113     for (unsigned i = 0; i != length; ++i) {
    1114         if (a[i] != b[i])
    1115             return false;
    1116     }
    1117 
    1118     return true;
    1119 }
    1120 
     1080ALWAYS_INLINE bool equal(const LChar* a, const LChar* b, unsigned length) { return std::equal(a, a + length, b); }
     1081ALWAYS_INLINE bool equal(const UChar* a, const UChar* b, unsigned length) { return std::equal(a, a + length, b); }
     1082#endif
     1083
     1084ALWAYS_INLINE bool equal(const LChar* a, const UChar* b, unsigned length) { return std::equal(a, a + length, b); }
     1085ALWAYS_INLINE bool equal(const UChar* a, const LChar* b, unsigned length) { return std::equal(a, a + length, b); }
    11211086WTF_EXPORT_STRING_API bool equalIgnoringCase(const StringImpl*, const StringImpl*);
    11221087WTF_EXPORT_STRING_API bool equalIgnoringCase(const StringImpl*, const LChar*);
Note: See TracChangeset for help on using the changeset viewer.