Title: [293588] trunk/Source
Revision
293588
Author
[email protected]
Date
2022-04-28 13:13:57 -0700 (Thu, 28 Apr 2022)

Log Message

Leverage the known length of an ASCIILiteral when comparing it to a String / AtomString
https://bugs.webkit.org/show_bug.cgi?id=239798

Reviewed by Yusuke Suzuki and Darin Adler.

Leverage the known length of an ASCIILiteral when comparing it to a String / AtomString.
Make sure we call ASCIILiteral::length() inline to allow the compiler to optimize out
the strlen() call, then call the more efficient `equal(StringImpl*, const LChar*, unsigned)`
instead of `equal(StringImpl*, const LChar*)`.

* Source/_javascript_Core/jsc.cpp:
(printInternal):
* Source/_javascript_Core/runtime/JSCJSValueInlines.h:
(JSC::toPreferredPrimitiveType):
* Source/_javascript_Core/runtime/PropertyName.h:
(JSC::isCanonicalNumericIndexString):
* Source/WTF/wtf/text/AtomString.h:
(WTF::operator==):
* Source/WTF/wtf/text/StringImpl.h:
(WTF::equal):
* Source/WTF/wtf/text/WTFString.h:
(WTF::operator==):
(WTF::operator!=):

Canonical link: https://commits.webkit.org/250097@main

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/jsc.cpp (293587 => 293588)


--- trunk/Source/_javascript_Core/jsc.cpp	2022-04-28 20:04:30 UTC (rev 293587)
+++ trunk/Source/_javascript_Core/jsc.cpp	2022-04-28 20:13:57 UTC (rev 293588)
@@ -1278,7 +1278,7 @@
 
     if (asyncTestExpectedPasses) {
         JSValue value = callFrame->argument(0);
-        if (value.isString() && WTF::equal(asString(value)->value(globalObject).impl(), "Test262:AsyncTestComplete")) {
+        if (value.isString() && WTF::equal(asString(value)->value(globalObject).impl(), "Test262:AsyncTestComplete"_s)) {
             asyncTestPasses++;
             return JSValue::encode(jsUndefined());
         }

Modified: trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h (293587 => 293588)


--- trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h	2022-04-28 20:04:30 UTC (rev 293587)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h	2022-04-28 20:13:57 UTC (rev 293588)
@@ -842,11 +842,11 @@
     String hintString = asString(value)->value(globalObject);
     RETURN_IF_EXCEPTION(scope, NoPreference);
 
-    if (WTF::equal(hintString, "default"))
+    if (WTF::equal(hintString, "default"_s))
         return NoPreference;
-    if (WTF::equal(hintString, "number"))
+    if (WTF::equal(hintString, "number"_s))
         return PreferNumber;
-    if (WTF::equal(hintString, "string"))
+    if (WTF::equal(hintString, "string"_s))
         return PreferString;
 
     throwTypeError(globalObject, scope, "Expected primitive hint to match one of 'default', 'number', 'string'."_s);

Modified: trunk/Source/_javascript_Core/runtime/PropertyName.h (293587 => 293588)


--- trunk/Source/_javascript_Core/runtime/PropertyName.h	2022-04-28 20:04:30 UTC (rev 293587)
+++ trunk/Source/_javascript_Core/runtime/PropertyName.h	2022-04-28 20:13:57 UTC (rev 293588)
@@ -139,7 +139,7 @@
         return false;
     if (property->isSymbol())
         return false;
-    if (equal(property, "-0"))
+    if (equal(property, "-0"_s))
         return true;
     double index = jsToNumber(property);
     NumberToStringBuffer buffer;

Modified: trunk/Source/WTF/wtf/text/AtomString.h (293587 => 293588)


--- trunk/Source/WTF/wtf/text/AtomString.h	2022-04-28 20:04:30 UTC (rev 293587)
+++ trunk/Source/WTF/wtf/text/AtomString.h	2022-04-28 20:13:57 UTC (rev 293588)
@@ -171,7 +171,7 @@
 inline bool operator==(const AtomString& a, const AtomString& b) { return a.impl() == b.impl(); }
 bool operator==(const AtomString&, const LChar*);
 inline bool operator==(const AtomString& a, const char* b) { return WTF::equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
-inline bool operator==(const AtomString& a, ASCIILiteral b) { return WTF::equal(a.impl(), reinterpret_cast<const LChar*>(b.characters())); }
+inline bool operator==(const AtomString& a, ASCIILiteral b) { return WTF::equal(a.impl(), b); }
 inline bool operator==(const AtomString& a, const Vector<UChar>& b) { return a.impl() && equal(a.impl(), b.data(), b.size()); }    
 inline bool operator==(const AtomString& a, const String& b) { return equal(a.impl(), b.impl()); }
 inline bool operator==(const LChar* a, const AtomString& b) { return b == a; }

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (293587 => 293588)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2022-04-28 20:04:30 UTC (rev 293587)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2022-04-28 20:13:57 UTC (rev 293588)
@@ -570,6 +570,7 @@
 inline bool equal(const StringImpl* a, const char* b) { return equal(a, reinterpret_cast<const LChar*>(b)); }
 WTF_EXPORT_PRIVATE bool equal(const StringImpl*, const LChar*, unsigned);
 WTF_EXPORT_PRIVATE bool equal(const StringImpl*, const UChar*, unsigned);
+ALWAYS_INLINE bool equal(const StringImpl* a, ASCIILiteral b) { return equal(a, b.characters8(), b.length()); }
 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)); }

Modified: trunk/Source/WTF/wtf/text/WTFString.h (293587 => 293588)


--- trunk/Source/WTF/wtf/text/WTFString.h	2022-04-28 20:04:30 UTC (rev 293587)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2022-04-28 20:13:57 UTC (rev 293588)
@@ -341,10 +341,10 @@
 inline bool operator==(const String& a, const String& b) { return equal(a.impl(), b.impl()); }
 inline bool operator==(const String& a, const LChar* b) { return equal(a.impl(), b); }
 inline bool operator==(const String& a, const char* b) { return equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
-inline bool operator==(const String& a, ASCIILiteral b) { return equal(a.impl(), reinterpret_cast<const LChar*>(b.characters())); }
+inline bool operator==(const String& a, ASCIILiteral b) { return equal(a.impl(), b); }
 inline bool operator==(const LChar* a, const String& b) { return equal(a, b.impl()); }
 inline bool operator==(const char* a, const String& b) { return equal(reinterpret_cast<const LChar*>(a), b.impl()); }
-inline bool operator==(ASCIILiteral a, const String& b) { return equal(reinterpret_cast<const LChar*>(a.characters()), b.impl()); }
+inline bool operator==(ASCIILiteral a, const String& b) { return equal(b.impl(), a); }
 template<size_t inlineCapacity> inline bool operator==(const Vector<char, inlineCapacity>& a, const String& b) { return equal(b.impl(), a.data(), a.size()); }
 template<size_t inlineCapacity> inline bool operator==(const String& a, const Vector<char, inlineCapacity>& b) { return b == a; }
 
@@ -351,10 +351,10 @@
 inline bool operator!=(const String& a, const String& b) { return !equal(a.impl(), b.impl()); }
 inline bool operator!=(const String& a, const LChar* b) { return !equal(a.impl(), b); }
 inline bool operator!=(const String& a, const char* b) { return !equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
-inline bool operator!=(const String& a, ASCIILiteral b) { return !equal(a.impl(), reinterpret_cast<const LChar*>(b.characters())); }
+inline bool operator!=(const String& a, ASCIILiteral b) { return !equal(a.impl(), b); }
 inline bool operator!=(const LChar* a, const String& b) { return !equal(a, b.impl()); }
 inline bool operator!=(const char* a, const String& b) { return !equal(reinterpret_cast<const LChar*>(a), b.impl()); }
-inline bool operator!=(ASCIILiteral a, const String& b) { return !equal(reinterpret_cast<const LChar*>(a.characters()), b.impl()); }
+inline bool operator!=(ASCIILiteral a, const String& b) { return !equal(b.impl(), a); }
 template<size_t inlineCapacity> inline bool operator!=(const Vector<char, inlineCapacity>& a, const String& b) { return !(a == b); }
 template<size_t inlineCapacity> inline bool operator!=(const String& a, const Vector<char, inlineCapacity>& b) { return b != a; }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to