Title: [293703] trunk
Revision
293703
Author
[email protected]
Date
2022-05-02 17:37:42 -0700 (Mon, 02 May 2022)

Log Message

Drop some unused StringImpl / AtomStringImpl / AtomString API
https://bugs.webkit.org/show_bug.cgi?id=239912

Reviewed by Yusuke Suzuki.

Simplifies our API a bit and encourages people to write more efficient
code.

* Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WTF/StringOperators.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
(TestWebKitAPI::TEST):
* Source/_javascript_Core/API/JSValue.mm:
(createStructHandlerMap):
* Source/_javascript_Core/runtime/CachedTypes.cpp:
(JSC::CachedUniquedStringImplBase::decode const):
* Source/_javascript_Core/runtime/Identifier.cpp:
(JSC::Identifier::addLiteral): Deleted.
* Source/_javascript_Core/runtime/Identifier.h:
(JSC::Identifier::Identifier):
(JSC::Identifier::add):
* Source/_javascript_Core/runtime/ObjectPrototype.cpp:
(JSC::inferBuiltinTag):
(JSC::objectPrototypeToString):
* Source/_javascript_Core/runtime/SmallStrings.cpp:
(JSC::SmallStrings::initializeCommonStrings):
(JSC::SmallStrings::initialize):
* Source/_javascript_Core/runtime/SmallStrings.h:
* Source/WTF/wtf/text/AtomString.h:
(WTF::AtomString::AtomString):
* Source/WTF/wtf/text/AtomStringImpl.cpp:
(WTF::CStringTranslator::hash): Deleted.
(WTF::CStringTranslator::equal): Deleted.
(WTF::CStringTranslator::translate): Deleted.
* Source/WTF/wtf/text/AtomStringImpl.h:
* Source/WTF/wtf/text/StringImpl.cpp:
* Source/WTF/wtf/text/StringImpl.h:
(WTF::StringImpl::create):
(WTF::StringImpl::createFromCString):
(WTF::lengthOfNullTerminatedString): Deleted.
* Source/WTF/wtf/text/WTFString.cpp:
(WTF::String::String):
* Source/WTF/wtf/text/WTFString.h:
* Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp:
(WebCore::RenderMathMLFenced::updateFromElement):

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

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSValue.mm (293702 => 293703)


--- trunk/Source/_javascript_Core/API/JSValue.mm	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/_javascript_Core/API/JSValue.mm	2022-05-03 00:37:42 UTC (rev 293703)
@@ -1159,7 +1159,7 @@
             return;
         {
             auto type = adoptSystem<char[]>(method_copyArgumentType(method, 2));
-            structHandlers->add(StringImpl::create(type.get()), (StructTagHandler) { selector, 0 });
+            structHandlers->add(StringImpl::createFromCString(type.get()), (StructTagHandler) { selector, 0 });
         }
     });
 

Modified: trunk/Source/_javascript_Core/runtime/CachedTypes.cpp (293702 => 293703)


--- trunk/Source/_javascript_Core/runtime/CachedTypes.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/_javascript_Core/runtime/CachedTypes.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -755,7 +755,7 @@
         if (!m_length) {
             if (m_isSymbol)
                 return &SymbolImpl::createNullSymbol().leakRef();
-            return AtomStringImpl::add("").leakRef();
+            return RefPtr { emptyAtom().impl() }.leakRef();
         }
 
         if (m_is8Bit)

Modified: trunk/Source/_javascript_Core/runtime/Identifier.cpp (293702 => 293703)


--- trunk/Source/_javascript_Core/runtime/Identifier.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/_javascript_Core/runtime/Identifier.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -27,14 +27,6 @@
 
 namespace JSC {
 
-Ref<AtomStringImpl> Identifier::addLiteral(VM& vm, const char* literal, size_t length)
-{
-    if (length == 1)
-        return vm.smallStrings.singleCharacterStringRep(literal[0]);
-
-    return AtomStringImpl::addLiteral(literal, length);
-}
-
 Ref<AtomStringImpl> Identifier::add8(VM& vm, const UChar* s, int length)
 {
     if (length == 1) {

Modified: trunk/Source/_javascript_Core/runtime/Identifier.h (293702 => 293703)


--- trunk/Source/_javascript_Core/runtime/Identifier.h	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/_javascript_Core/runtime/Identifier.h	2022-05-03 00:37:42 UTC (rev 293703)
@@ -169,7 +169,7 @@
 
     Identifier(VM& vm, const LChar* s, int length) : m_string(add(vm, s, length)) { ASSERT(m_string.impl()->isAtom()); }
     Identifier(VM& vm, const UChar* s, int length) : m_string(add(vm, s, length)) { ASSERT(m_string.impl()->isAtom()); }
-    ALWAYS_INLINE Identifier(VM& vm, ASCIILiteral literal) : m_string(addLiteral(vm, literal.characters(), literal.length())) { ASSERT(m_string.impl()->isAtom()); }
+    ALWAYS_INLINE Identifier(VM& vm, ASCIILiteral literal) : m_string(add(vm, literal)) { ASSERT(m_string.impl()->isAtom()); }
     Identifier(VM&, AtomStringImpl*);
     Identifier(VM&, const AtomString&);
     Identifier(VM& vm, const String& string) : m_string(add(vm, string.impl())) { ASSERT(m_string.impl()->isAtom()); }
@@ -194,7 +194,7 @@
     template <typename T> ALWAYS_INLINE static constexpr bool canUseSingleCharacterString(T);
 
     static Ref<AtomStringImpl> add(VM&, StringImpl*);
-    JS_EXPORT_PRIVATE static Ref<AtomStringImpl> addLiteral(VM&, const char*, size_t length);
+    static Ref<AtomStringImpl> add(VM&, ASCIILiteral);
 
 #ifndef NDEBUG
     JS_EXPORT_PRIVATE static void checkCurrentAtomStringTable(VM&);
@@ -228,6 +228,13 @@
     return *AtomStringImpl::add(s, length);
 }
 
+inline Ref<AtomStringImpl> Identifier::add(VM& vm, ASCIILiteral literal)
+{
+    if (literal.length() == 1)
+        return vm.smallStrings.singleCharacterStringRep(literal.characterAt(0));
+    return AtomStringImpl::add(literal);
+}
+
 inline bool operator==(const Identifier& a, const Identifier& b)
 {
     return Identifier::equal(a, b);

Modified: trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp (293702 => 293703)


--- trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -321,7 +321,7 @@
 }
 #endif
 
-inline const char* inferBuiltinTag(JSGlobalObject* globalObject, JSObject* object)
+inline ASCIILiteral inferBuiltinTag(JSGlobalObject* globalObject, JSObject* object)
 {
     VM& vm = globalObject->vm();
 #if PLATFORM(IOS)
@@ -331,11 +331,11 @@
 #endif
     auto scope = DECLARE_THROW_SCOPE(vm);
     bool objectIsArray = isArray(globalObject, object);
-    RETURN_IF_EXCEPTION(scope, nullptr);
+    RETURN_IF_EXCEPTION(scope, { });
     if (objectIsArray)
-        return "Array";
+        return "Array"_s;
     if (object->isCallable())
-        return "Function";
+        return "Function"_s;
     JSType type = object->type();
     if (TypeInfo::isArgumentsType(type)
         || type == ErrorInstanceType
@@ -346,7 +346,7 @@
         || type == JSDateType
         || type == RegExpObjectType)
         return object->className();
-    return "Object";
+    return "Object"_s;
 }
 
 JSString* objectPrototypeToString(JSGlobalObject* globalObject, JSValue thisValue)
@@ -366,7 +366,7 @@
     if (result)
         return asString(result);
 
-    const char* tag = inferBuiltinTag(globalObject, thisObject);
+    ASCIILiteral tag = inferBuiltinTag(globalObject, thisObject);
     RETURN_IF_EXCEPTION(scope, nullptr);
     JSString* jsTag = nullptr;
 
@@ -381,7 +381,7 @@
     }
 
     if (!jsTag)
-        jsTag = jsString(vm, AtomStringImpl::add(tag).releaseNonNull());
+        jsTag = jsString(vm, AtomStringImpl::add(tag));
 
     JSString* jsResult = jsString(globalObject, vm.smallStrings.objectStringStart(), jsTag, vm.smallStrings.singleCharacterString(']'));
     RETURN_IF_EXCEPTION(scope, nullptr);

Modified: trunk/Source/_javascript_Core/runtime/SmallStrings.cpp (293702 => 293703)


--- trunk/Source/_javascript_Core/runtime/SmallStrings.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/_javascript_Core/runtime/SmallStrings.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -52,17 +52,17 @@
         ASSERT(m_needsToBeVisited);
     }
 
-#define JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE(name) initialize(&vm, m_##name, #name);
+#define JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE(name) initialize(&vm, m_##name, #name ## _s);
     JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE)
 #undef JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE
-    initialize(&vm, m_objectStringStart, "[object ");
-    initialize(&vm, m_nullObjectString, "[object Null]");
-    initialize(&vm, m_undefinedObjectString, "[object Undefined]");
-    initialize(&vm, m_boundPrefixString, "bound ");
-    initialize(&vm, m_notEqualString, "not-equal");
-    initialize(&vm, m_timedOutString, "timed-out");
-    initialize(&vm, m_okString, "ok");
-    initialize(&vm, m_sentinelString, "$");
+    initialize(&vm, m_objectStringStart, "[object "_s);
+    initialize(&vm, m_nullObjectString, "[object Null]"_s);
+    initialize(&vm, m_undefinedObjectString, "[object Undefined]"_s);
+    initialize(&vm, m_boundPrefixString, "bound "_s);
+    initialize(&vm, m_notEqualString, "not-equal"_s);
+    initialize(&vm, m_timedOutString, "timed-out"_s);
+    initialize(&vm, m_okString, "ok"_s);
+    initialize(&vm, m_sentinelString, "$"_s);
 
     setIsInitialized(true);
 }
@@ -102,9 +102,9 @@
     return AtomStringImpl::add(string, 1).releaseNonNull();
 }
 
-void SmallStrings::initialize(VM* vm, JSString*& string, const char* value)
+void SmallStrings::initialize(VM* vm, JSString*& string, ASCIILiteral value)
 {
-    string = JSString::create(*vm, AtomStringImpl::add(value).releaseNonNull());
+    string = JSString::create(*vm, AtomStringImpl::add(value));
     ASSERT(m_needsToBeVisited);
 }
 

Modified: trunk/Source/_javascript_Core/runtime/SmallStrings.h (293702 => 293703)


--- trunk/Source/_javascript_Core/runtime/SmallStrings.h	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/_javascript_Core/runtime/SmallStrings.h	2022-05-03 00:37:42 UTC (rev 293703)
@@ -131,7 +131,7 @@
 private:
     static constexpr unsigned singleCharacterStringCount = maxSingleCharacterString + 1;
 
-    void initialize(VM*, JSString*&, const char* value);
+    void initialize(VM*, JSString*&, ASCIILiteral value);
 
     JSString* m_emptyString { nullptr };
 #define JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION(name) JSString* m_##name { nullptr };

Modified: trunk/Source/WTF/wtf/text/AtomString.h (293702 => 293703)


--- trunk/Source/WTF/wtf/text/AtomString.h	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WTF/wtf/text/AtomString.h	2022-05-03 00:37:42 UTC (rev 293703)
@@ -40,7 +40,6 @@
     AtomString();
     AtomString(const LChar*, unsigned length);
     AtomString(const UChar*, unsigned length);
-    AtomString(const UChar*);
 
     ALWAYS_INLINE static AtomString fromLatin1(const char* characters) { return AtomString(characters); }
 
@@ -142,7 +141,7 @@
         : AtomString(ucharFrom(characters), length) { }
 
     AtomString(const wchar_t* characters)
-        : AtomString(ucharFrom(characters)) { }
+        : AtomString(characters, characters ? wcslen(characters) : 0) { }
 #endif
 
     // AtomString::fromUTF8 will return a null string if the input data contains invalid UTF-8 sequences.
@@ -203,7 +202,7 @@
 }
 
 inline AtomString::AtomString(const char* string)
-    : m_string(AtomStringImpl::add(string))
+    : m_string(AtomStringImpl::addCString(string))
 {
 }
 
@@ -217,11 +216,6 @@
 {
 }
 
-inline AtomString::AtomString(const UChar* string)
-    : m_string(AtomStringImpl::add(string))
-{
-}
-
 inline AtomString::AtomString(AtomStringImpl* string)
     : m_string(string)
 {

Modified: trunk/Source/WTF/wtf/text/AtomStringImpl.cpp (293702 => 293703)


--- trunk/Source/WTF/wtf/text/AtomStringImpl.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WTF/wtf/text/AtomStringImpl.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -88,36 +88,6 @@
     return addToStringTable<T, HashTranslator>(locker, stringTable(), value);
 }
 
-struct CStringTranslator {
-    static unsigned hash(const LChar* characters)
-    {
-        return StringHasher::computeHashAndMaskTop8Bits(characters);
-    }
-
-    static inline bool equal(PackedPtr<StringImpl> str, const LChar* characters)
-    {
-        return WTF::equal(str.get(), characters);
-    }
-
-    static void translate(PackedPtr<StringImpl>& location, const LChar* const& characters, unsigned hash)
-    {
-        auto* pointer = &StringImpl::create(characters).leakRef();
-        pointer->setHash(hash);
-        pointer->setIsAtom(true);
-        location = pointer;
-    }
-};
-
-RefPtr<AtomStringImpl> AtomStringImpl::add(const LChar* characters)
-{
-    if (!characters)
-        return nullptr;
-    if (!*characters)
-        return static_cast<AtomStringImpl*>(StringImpl::empty());
-
-    return addToStringTable<const LChar*, CStringTranslator>(characters);
-}
-
 using UCharBuffer = HashTranslatorCharBuffer<UChar>;
 struct UCharBufferTranslator {
     static unsigned hash(const UCharBuffer& buf)
@@ -221,22 +191,6 @@
     return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
 }
 
-RefPtr<AtomStringImpl> AtomStringImpl::add(const UChar* characters)
-{
-    if (!characters)
-        return nullptr;
-
-    unsigned length = 0;
-    while (characters[length] != UChar(0))
-        ++length;
-
-    if (!length)
-        return static_cast<AtomStringImpl*>(StringImpl::empty());
-
-    UCharBuffer buffer { characters, length };
-    return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
-}
-
 struct SubstringLocation {
     StringImpl* baseString;
     unsigned start;

Modified: trunk/Source/WTF/wtf/text/AtomStringImpl.h (293702 => 293703)


--- trunk/Source/WTF/wtf/text/AtomStringImpl.h	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WTF/wtf/text/AtomStringImpl.h	2022-05-03 00:37:42 UTC (rev 293703)
@@ -39,12 +39,9 @@
 
     static void remove(AtomStringImpl*);
 
-    WTF_EXPORT_PRIVATE static RefPtr<AtomStringImpl> add(const LChar*);
-    ALWAYS_INLINE static RefPtr<AtomStringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); };
     WTF_EXPORT_PRIVATE static RefPtr<AtomStringImpl> add(const LChar*, unsigned length);
     WTF_EXPORT_PRIVATE static RefPtr<AtomStringImpl> add(const UChar*, unsigned length);
-    ALWAYS_INLINE static RefPtr<AtomStringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); };
-    WTF_EXPORT_PRIVATE static RefPtr<AtomStringImpl> add(const UChar*);
+    ALWAYS_INLINE static RefPtr<AtomStringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); }
     WTF_EXPORT_PRIVATE static RefPtr<AtomStringImpl> add(StringImpl*, unsigned offset, unsigned length);
     ALWAYS_INLINE static RefPtr<AtomStringImpl> add(StringImpl* string)
     {
@@ -59,8 +56,11 @@
         return add(string.releaseNonNull());
     }
     WTF_EXPORT_PRIVATE static RefPtr<AtomStringImpl> add(const StaticStringImpl*);
-    WTF_EXPORT_PRIVATE static Ref<AtomStringImpl> addLiteral(const char* characters, unsigned length);
+    ALWAYS_INLINE static Ref<AtomStringImpl> add(ASCIILiteral literal) { return addLiteral(literal.characters(), literal.length()); }
 
+    // Not using the add() naming to encourage developers to call add(ASCIILiteral) when they have a string literal.
+    ALWAYS_INLINE static RefPtr<AtomStringImpl> addCString(const char* s) { return s ? add(s, strlen(s)) : nullptr; }
+
     // Returns null if the input data contains an invalid UTF-8 sequence.
     static RefPtr<AtomStringImpl> addUTF8(const char* start, const char* end);
 
@@ -101,6 +101,8 @@
         return addSlowCase(WTFMove(string));
     }
 
+    WTF_EXPORT_PRIVATE static Ref<AtomStringImpl> addLiteral(const char* characters, unsigned length);
+
     ALWAYS_INLINE static Ref<AtomStringImpl> add(AtomStringTable& stringTable, StringImpl& string)
     {
         if (string.isAtom()) {

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (293702 => 293703)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -319,21 +319,6 @@
     return string;
 }
 
-Ref<StringImpl> StringImpl::create8BitIfPossible(const UChar* string)
-{
-    return StringImpl::create8BitIfPossible(string, lengthOfNullTerminatedString(string));
-}
-
-Ref<StringImpl> StringImpl::create(const LChar* string)
-{
-    if (!string)
-        return *empty();
-    size_t length = strlen(reinterpret_cast<const char*>(string));
-    if (length > MaxLength)
-        CRASH();
-    return create(string, length);
-}
-
 Ref<StringImpl> StringImpl::substring(unsigned start, unsigned length)
 {
     if (start >= m_length)

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (293702 => 293703)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2022-05-03 00:37:42 UTC (rev 293703)
@@ -237,13 +237,12 @@
 
     WTF_EXPORT_PRIVATE static Ref<StringImpl> create(const UChar*, unsigned length);
     WTF_EXPORT_PRIVATE static Ref<StringImpl> create(const LChar*, unsigned length);
+    ALWAYS_INLINE static Ref<StringImpl> create(const char* characters, unsigned length) { return create(reinterpret_cast<const LChar*>(characters), length); }
     WTF_EXPORT_PRIVATE static Ref<StringImpl> create8BitIfPossible(const UChar*, unsigned length);
     template<size_t inlineCapacity> static Ref<StringImpl> create8BitIfPossible(const Vector<UChar, inlineCapacity>&);
-    WTF_EXPORT_PRIVATE static Ref<StringImpl> create8BitIfPossible(const UChar*);
 
-    ALWAYS_INLINE static Ref<StringImpl> create(const char* characters, unsigned length) { return create(reinterpret_cast<const LChar*>(characters), length); }
-    WTF_EXPORT_PRIVATE static Ref<StringImpl> create(const LChar*);
-    ALWAYS_INLINE static Ref<StringImpl> create(const char* string) { return create(reinterpret_cast<const LChar*>(string)); }
+    // Not using create() naming to encourage developers to call create(ASCIILiteral) when they have a string literal.
+    ALWAYS_INLINE static Ref<StringImpl> createFromCString(const char* characters) { return create(characters, strlen(characters)); }
 
     static Ref<StringImpl> createSubstringSharingImpl(StringImpl&, unsigned offset, unsigned length);
 
@@ -609,8 +608,6 @@
 bool isSpaceOrNewline(UChar32);
 bool isNotSpaceOrNewline(UChar32);
 
-template<typename CharacterType> unsigned lengthOfNullTerminatedString(const CharacterType*);
-
 // StringHashd is the default hash for StringImpl* and RefPtr<StringImpl>
 template<typename> struct DefaultHash;
 template<> struct DefaultHash<StringImpl*>;
@@ -775,17 +772,6 @@
     return !isSpaceOrNewline(character);
 }
 
-template<typename CharacterType> inline unsigned lengthOfNullTerminatedString(const CharacterType* string)
-{
-    ASSERT(string);
-    size_t length = 0;
-    while (string[length])
-        ++length;
-
-    RELEASE_ASSERT(length < StringImpl::MaxLength);
-    return static_cast<unsigned>(length);
-}
-
 inline StringImplShape::StringImplShape(unsigned refCount, unsigned length, const LChar* data8, unsigned hashAndFlags)
     : m_refCount(refCount)
     , m_length(length)

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (293702 => 293703)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -46,13 +46,6 @@
         m_impl = StringImpl::create(characters, length);
 }
 
-// Construct a string with UTF-16 data, from a null-terminated source.
-String::String(const UChar* nullTerminatedString)
-{
-    if (nullTerminatedString)
-        m_impl = StringImpl::create(nullTerminatedString, lengthOfNullTerminatedString(nullTerminatedString));
-}
-
 // Construct a string with latin1 data.
 String::String(const LChar* characters, unsigned length)
 {
@@ -70,7 +63,7 @@
 String::String(const char* nullTerminatedString)
 {
     if (nullTerminatedString)
-        m_impl = StringImpl::create(reinterpret_cast<const LChar*>(nullTerminatedString));
+        m_impl = StringImpl::createFromCString(nullTerminatedString);
 }
 
 int codePointCompare(const String& a, const String& b)

Modified: trunk/Source/WTF/wtf/text/WTFString.h (293702 => 293703)


--- trunk/Source/WTF/wtf/text/WTFString.h	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2022-05-03 00:37:42 UTC (rev 293703)
@@ -73,9 +73,6 @@
     template<size_t inlineCapacity, typename OverflowHandler>
     explicit String(const Vector<UChar, inlineCapacity, OverflowHandler>&);
 
-    // Construct a string with UTF-16 data, from a null-terminated source.
-    WTF_EXPORT_PRIVATE String(const UChar*);
-
     // Construct a string with Latin-1 data.
     WTF_EXPORT_PRIVATE String(const LChar* characters, unsigned length);
     WTF_EXPORT_PRIVATE String(const char* characters, unsigned length);
@@ -275,7 +272,7 @@
         : String(ucharFrom(characters), length) { }
 
     String(const wchar_t* characters)
-        : String(ucharFrom(characters)) { }
+        : String(characters, characters ? wcslen(characters) : 0) { }
 
     WTF_EXPORT_PRIVATE Vector<wchar_t> wideCharacters() const;
 #endif

Modified: trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp (293702 => 293703)


--- trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -83,10 +83,10 @@
     
     if (title) {
         PathRemoveExtension(filename);
-        *title = String((UChar*)filename);
+        *title = String(filename);
     }
     
-    url = ""
+    url = ""
     succeeded = true;
 
 exit:
@@ -448,7 +448,7 @@
 
     if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) {
         // URL using Unicode
-        UChar* data = ""
+        auto* data = ""
         url = "" title);
         GlobalUnlock(store.hGlobal);
         ReleaseStgMedium(&store);
@@ -519,7 +519,7 @@
     String text;
     if (SUCCEEDED(dataObject->GetData(plainTextWFormat(), &store))) {
         // Unicode text
-        UChar* data = ""
+        auto* data = ""
         text = String(data);
         GlobalUnlock(store.hGlobal);
         ReleaseStgMedium(&store);
@@ -554,7 +554,7 @@
     STGMEDIUM store;
     String html;
     if (SUCCEEDED(data->GetData(texthtmlFormat(), &store))) {
-        UChar* data = ""
+        auto* data = ""
         html = String(data);
         GlobalUnlock(store.hGlobal);
         ReleaseStgMedium(&store);

Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (293702 => 293703)


--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -630,11 +630,11 @@
     }
 
     if (extension.isEmpty())
-        return String(fsPathBuffer);
+        return String(wcharFrom(fsPathBuffer));
 
     if (!isLink && usedURL) {
         PathRenameExtension(wcharFrom(fsPathBuffer), extension.wideCharacters().data());
-        return String(fsPathBuffer);
+        return String(wcharFrom(fsPathBuffer));
     }
 
     return makeString(const_cast<const UChar*>(fsPathBuffer), extension);
@@ -829,7 +829,7 @@
 {
     if (::IsClipboardFormatAvailable(CF_UNICODETEXT) && ::OpenClipboard(m_owner)) {
         if (HANDLE cbData = ::GetClipboardData(CF_UNICODETEXT)) {
-            text.text = static_cast<UChar*>(GlobalLock(cbData));
+            text.text = static_cast<wchar_t*>(GlobalLock(cbData));
             GlobalUnlock(cbData);
             ::CloseClipboard();
             return;
@@ -872,7 +872,7 @@
         if (::OpenClipboard(m_owner)) {
             HANDLE cbData = ::GetClipboardData(CF_UNICODETEXT);
             if (cbData) {
-                UChar* buffer = static_cast<UChar*>(GlobalLock(cbData));
+                auto* buffer = static_cast<wchar_t*>(GlobalLock(cbData));
                 String str(buffer);
                 GlobalUnlock(cbData);
                 ::CloseClipboard();

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp (293702 => 293703)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -75,7 +75,7 @@
         m_separators = !characters.length() ? 0 : characters.toString().impl();
     } else {
         // The separator defaults to a single comma.
-        m_separators = StringImpl::create(",");
+        m_separators = StringImpl::createFromLiteral(","_s);
     }
 
     if (firstChild()) {

Modified: trunk/Source/WebKitLegacy/win/DOMCoreClasses.cpp (293702 => 293703)


--- trunk/Source/WebKitLegacy/win/DOMCoreClasses.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Source/WebKitLegacy/win/DOMCoreClasses.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -416,7 +416,7 @@
 HRESULT DOMNode::addEventListener(_In_ BSTR type, _In_opt_ IDOMEventListener* listener, BOOL useCapture)
 {
     auto webListener = WebEventListener::create(listener);
-    m_node->addEventListener(ucharFrom(type), WTFMove(webListener), useCapture);
+    m_node->addEventListener(String(type), WTFMove(webListener), useCapture);
 
     return S_OK;
 }
@@ -428,7 +428,7 @@
     if (!m_node)
         return E_FAIL;
     auto webListener = WebEventListener::create(listener);
-    m_node->removeEventListener(ucharFrom(type), webListener, useCapture);
+    m_node->removeEventListener(String(type), webListener, useCapture);
     return S_OK;
 }
 
@@ -926,7 +926,7 @@
     if (!m_window)
         return E_FAIL;
     auto webListener = WebEventListener::create(listener);
-    m_window->addEventListener(ucharFrom(type), WTFMove(webListener), useCapture);
+    m_window->addEventListener(String(type), WTFMove(webListener), useCapture);
     return S_OK;
 }
 
@@ -937,7 +937,7 @@
     if (!m_window)
         return E_FAIL;
     auto webListener = WebEventListener::create(listener);
-    m_window->removeEventListener(ucharFrom(type), webListener, useCapture);
+    m_window->removeEventListener(String(type), webListener, useCapture);
     return S_OK;
 }
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp (293702 => 293703)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -119,7 +119,7 @@
     auto b = StringImpl::createFromLiteral("ABCDEFG"_s);
     auto c = StringImpl::createFromLiteral("abcdefg"_s);
     constexpr auto d = "aBcDeFG"_s;
-    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     auto shorter = StringImpl::createFromLiteral("abcdef"_s);
     auto different = StringImpl::createFromLiteral("abcrefg"_s);
 
@@ -162,8 +162,8 @@
 
 TEST(WTF, StringImplEqualIgnoringASCIICaseWithEmpty)
 {
-    auto a = StringImpl::create(reinterpret_cast<const LChar*>(""));
-    auto b = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    auto a = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
+    auto b = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     ASSERT_TRUE(equalIgnoringASCIICase(a.ptr(), b.ptr()));
     ASSERT_TRUE(equalIgnoringASCIICase(b.ptr(), a.ptr()));
 }
@@ -341,7 +341,7 @@
 TEST(WTF, StringImplFindIgnoringASCIICaseOnEmpty)
 {
     auto reference = stringFromUTF8("ABCÉEFG");
-    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     EXPECT_EQ(static_cast<size_t>(0), reference->findIgnoringASCIICase(empty.ptr()));
     EXPECT_EQ(static_cast<size_t>(0), reference->findIgnoringASCIICase(empty.ptr(), 0));
     EXPECT_EQ(static_cast<size_t>(3), reference->findIgnoringASCIICase(empty.ptr(), 3));
@@ -417,7 +417,7 @@
     auto reference = StringImpl::createFromLiteral("aBcDeFG"_s);
     ASSERT_FALSE(reference->startsWithIgnoringASCIICase(StringView { }));
 
-    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     ASSERT_FALSE(empty->startsWithIgnoringASCIICase(StringView { }));
 }
 
@@ -424,7 +424,7 @@
 TEST(WTF, StringImplStartsWithIgnoringASCIICaseWithEmpty)
 {
     auto reference = StringImpl::createFromLiteral("aBcDeFG"_s);
-    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     ASSERT_TRUE(reference->startsWithIgnoringASCIICase(empty.ptr()));
     ASSERT_TRUE(reference->startsWithIgnoringASCIICase(*empty.ptr()));
     ASSERT_TRUE(empty->startsWithIgnoringASCIICase(empty.ptr()));
@@ -506,7 +506,7 @@
     auto reference = StringImpl::createFromLiteral("aBcDeFG"_s);
     ASSERT_FALSE(reference->endsWithIgnoringASCIICase(StringView { }));
 
-    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     ASSERT_FALSE(empty->endsWithIgnoringASCIICase(StringView { }));
 }
 
@@ -513,7 +513,7 @@
 TEST(WTF, StringImplEndsWithIgnoringASCIICaseWithEmpty)
 {
     auto reference = StringImpl::createFromLiteral("aBcDeFG"_s);
-    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    auto empty = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     ASSERT_TRUE(reference->endsWithIgnoringASCIICase(empty.ptr()));
     ASSERT_TRUE(reference->endsWithIgnoringASCIICase(*empty.ptr()));
     ASSERT_TRUE(empty->endsWithIgnoringASCIICase(empty.ptr()));

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringOperators.cpp (293702 => 293703)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringOperators.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringOperators.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -258,7 +258,7 @@
     UChar ucharArray[] = { 't', 'e', 's', 't', '\0' };
     String concatenation16 = ucharArray + emptyString;
     ASSERT_EQ(static_cast<unsigned>(4), concatenation16.length());
-    ASSERT_TRUE(concatenation16 == String(ucharArray));
+    ASSERT_TRUE(concatenation16 == String(ucharArray, 4));
 
     LChar lcharArray[] = { 't', 'e', 's', 't' };
     String concatenation8 = String(lcharArray, 4) + emptyString;

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp (293702 => 293703)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp	2022-05-03 00:37:42 UTC (rev 293703)
@@ -339,7 +339,7 @@
     RefPtr<StringImpl> b = StringImpl::createFromLiteral("ABCDEFG"_s);
     RefPtr<StringImpl> c = StringImpl::createFromLiteral("abcdefg"_s);
     constexpr auto d = "aBcDeFG"_s;
-    RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     RefPtr<StringImpl> shorter = StringImpl::createFromLiteral("abcdef"_s);
     RefPtr<StringImpl> different = StringImpl::createFromLiteral("abcrefg"_s);
 
@@ -384,8 +384,8 @@
 
 TEST(WTF, StringViewEqualIgnoringASCIICaseWithEmpty)
 {
-    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>(""));
-    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>(""));
+    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
+    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>(""), 0);
     StringView stringViewA(*a.get());
     StringView stringViewB(*b.get());
     ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewB));
@@ -394,10 +394,10 @@
 
 TEST(WTF, StringViewEqualIgnoringASCIICaseWithLatin1Characters)
 {
-    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>("aBcéeFG"));
-    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>("ABCÉEFG"));
-    RefPtr<StringImpl> c = StringImpl::create(reinterpret_cast<const LChar*>("ABCéEFG"));
-    RefPtr<StringImpl> d = StringImpl::create(reinterpret_cast<const LChar*>("abcéefg"));
+    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>("aBcéeFG"), 7);
+    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>("ABCÉEFG"), 7);
+    RefPtr<StringImpl> c = StringImpl::create(reinterpret_cast<const LChar*>("ABCéEFG"), 7);
+    RefPtr<StringImpl> d = StringImpl::create(reinterpret_cast<const LChar*>("abcéefg"), 7);
     StringView stringViewA(*a.get());
     StringView stringViewB(*b.get());
     StringView stringViewC(*c.get());
@@ -982,7 +982,7 @@
     EXPECT_TRUE(StringView(String("Cocoa"_s)).isAllASCII());
     EXPECT_FALSE(StringView(String::fromLatin1("📱")).isAllASCII());
     EXPECT_FALSE(StringView(String::fromLatin1("\u0080")).isAllASCII());
-    EXPECT_TRUE(StringView(String(bitwise_cast<const UChar*>(u"Hello"))).isAllASCII());
+    EXPECT_TRUE(StringView(String(bitwise_cast<const UChar*>(u"Hello"), 0)).isAllASCII());
 }
 
 } // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm (293702 => 293703)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm	2022-05-03 00:04:42 UTC (rev 293702)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm	2022-05-03 00:37:42 UTC (rev 293703)
@@ -234,7 +234,7 @@
     EXPECT_STREQ([[url2 absoluteString] UTF8String], "http://%E2%89%A7%E2%88%AE%EF%B9%A3%D9%A1%DB%B1");
 
     std::array<UChar, 3> utf16 { 0xC2, 0xB6, 0x00 };
-    WTF::URL url3 { String(utf16.data()) };
+    WTF::URL url3 { String(utf16.data(), utf16.size()) };
     EXPECT_FALSE(url3.string().is8Bit());
     EXPECT_FALSE(url3.isValid());
     EXPECT_STREQ([[url3 absoluteString] UTF8String], "%C3%82%C2%B6");
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to