Title: [293768] trunk/Source/WTF
Revision
293768
Author
ysuz...@apple.com
Date
2022-05-04 02:30:16 -0700 (Wed, 04 May 2022)

Log Message

[WTF] Initialize emptyString and nullString data at compile time
https://bugs.webkit.org/show_bug.cgi?id=240054

Reviewed by Mark Lam.

As we did for AtomString in r293757, we can initialize emptyString() and nullString()
data at compile time. This patch does that for WTF::String.

* Source/WTF/wtf/text/WTFString.cpp:
(WTF::emptyString): Deleted.
(WTF::nullString): Deleted.
* Source/WTF/wtf/text/WTFString.h:
(WTF::StaticString::StaticString):
(WTF::nullString):
(WTF::emptyString):

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

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (293767 => 293768)


--- trunk/Source/WTF/ChangeLog	2022-05-04 09:12:15 UTC (rev 293767)
+++ trunk/Source/WTF/ChangeLog	2022-05-04 09:30:16 UTC (rev 293768)
@@ -1,5 +1,23 @@
 2022-05-03  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [WTF] Initialize emptyString and nullString data at compile time
+        https://bugs.webkit.org/show_bug.cgi?id=240054
+
+        Reviewed by Mark Lam.
+
+        As we did for AtomString in r293757, we can initialize emptyString() and nullString()
+        data at compile time. This patch does that for WTF::String.
+
+        * wtf/text/WTFString.cpp:
+        (WTF::emptyString): Deleted.
+        (WTF::nullString): Deleted.
+        * wtf/text/WTFString.h:
+        (WTF::StaticString::StaticString):
+        (WTF::nullString):
+        (WTF::emptyString):
+
+2022-05-03  Yusuke Suzuki  <ysuz...@apple.com>
+
         [JSC] Initialize empty and null AtomString at compile time
         https://bugs.webkit.org/show_bug.cgi?id=240031
 

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (293767 => 293768)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2022-05-04 09:12:15 UTC (rev 293767)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2022-05-04 09:30:16 UTC (rev 293768)
@@ -635,18 +635,9 @@
     return static_cast<float>(toDoubleType<UChar, TrailingJunkPolicy::Allow>(data, length, nullptr, parsedLength));
 }
 
-const String& emptyString()
-{
-    static NeverDestroyed<String> emptyString(StringImpl::empty());
-    return emptyString;
-}
+WTF_EXPORT_PRIVATE const StaticString nullStringData { nullptr };
+WTF_EXPORT_PRIVATE const StaticString emptyStringData { &StringImpl::s_emptyAtomString };
 
-const String& nullString()
-{
-    static NeverDestroyed<String> nullString;
-    return nullString;
-}
-
 } // namespace WTF
 
 #ifndef NDEBUG

Modified: trunk/Source/WTF/wtf/text/WTFString.h (293767 => 293768)


--- trunk/Source/WTF/wtf/text/WTFString.h	2022-05-04 09:12:15 UTC (rev 293767)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2022-05-04 09:30:16 UTC (rev 293768)
@@ -380,9 +380,21 @@
 template<typename CharacterType> void appendNumber(Vector<CharacterType>&, unsigned char number);
 
 // Shared global empty and null string.
-WTF_EXPORT_PRIVATE const String& emptyString();
-WTF_EXPORT_PRIVATE const String& nullString();
+struct StaticString {
+    constexpr StaticString(StringImpl::StaticStringImpl* pointer)
+        : m_pointer(pointer)
+    {
+    }
 
+    StringImpl::StaticStringImpl* m_pointer;
+};
+static_assert(sizeof(String) == sizeof(StaticString), "String and StaticString must be the same size!");
+extern WTF_EXPORT_PRIVATE const StaticString nullStringData;
+extern WTF_EXPORT_PRIVATE const StaticString emptyStringData;
+
+inline const String& nullString() { return *reinterpret_cast<const String*>(&nullStringData); }
+inline const String& emptyString() { return *reinterpret_cast<const String*>(&emptyStringData); }
+
 template<typename> struct DefaultHash;
 template<> struct DefaultHash<String>;
 template<> struct VectorTraits<String> : VectorTraitsBase<false, void> {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to