Reviewed by Gavin Barraclough.
- speed up string comparison, especially for short strings
~1% on SunSpider
* JavaScriptCore.exp:
* runtime/UString.cpp:
* runtime/UString.h:
(JSC::operator==): Inline UString's operator==, since it is called from
hot places in the runtime. Also, specialize 2-char strings in a similar way to
1-char, since we're taking the hit of a switch anyway.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@43856
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2009-05-19 Maciej Stachowiak <mjs@apple.com>
+
+ Reviewed by Gavin Barraclough.
+
+ - speed up string comparison, especially for short strings
+
+ ~1% on SunSpider
+
+ * JavaScriptCore.exp:
+ * runtime/UString.cpp:
+ * runtime/UString.h:
+ (JSC::operator==): Inline UString's operator==, since it is called from
+ hot places in the runtime. Also, specialize 2-char strings in a similar way to
+ 1-char, since we're taking the hit of a switch anyway.
+
2009-05-18 Maciej Stachowiak <mjs@apple.com>
Reviewed by Gavin Barraclough.
__ZN3JSC9StructureD1Ev
__ZN3JSC9constructEPNS_9ExecStateENS_7JSValueENS_13ConstructTypeERKNS_13ConstructDataERKNS_7ArgListE
__ZN3JSCeqERKNS_7UStringEPKc
-__ZN3JSCeqERKNS_7UStringES2_
__ZN3JSCgtERKNS_7UStringES2_
__ZN3JSCltERKNS_7UStringES2_
__ZN3WTF10fastCallocEmm
return UString(Rep::create(m_rep, pos, len));
}
-bool operator==(const UString& s1, const UString& s2)
-{
- int size = s1.size();
- switch (size) {
- case 0:
- return !s2.size();
- case 1:
- return s2.size() == 1 && s1.data()[0] == s2.data()[0];
- default:
- return s2.size() == size && memcmp(s1.data(), s2.data(), size * sizeof(UChar)) == 0;
- }
-}
-
bool operator==(const UString& s1, const char *s2)
{
if (s2 == 0)
PassRefPtr<UString::Rep> concatenate(UString::Rep*, int);
PassRefPtr<UString::Rep> concatenate(UString::Rep*, double);
- bool operator==(const UString&, const UString&);
+ inline bool operator==(const UString& s1, const UString& s2)
+ {
+ int size = s1.size();
+ switch (size) {
+ case 0:
+ return !s2.size();
+ case 1:
+ return s2.size() == 1 && s1.data()[0] == s2.data()[0];
+ case 2: {
+ if (s2.size() != 2)
+ return false;
+ const UChar* d1 = s1.data();
+ const UChar* d2 = s2.data();
+ return (d1[0] == d2[0]) & (d1[1] == d2[1]);
+ }
+ default:
+ return s2.size() == size && memcmp(s1.data(), s2.data(), size * sizeof(UChar)) == 0;
+ }
+ }
+
inline bool operator!=(const UString& s1, const UString& s2)
{