[webkit-changes] [WebKit/WebKit] 46f1a9: Improve StringTypeAdapter templates and handling

Žan Doberšek noreply at github.com
Mon Jan 16 03:31:12 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 46f1a9702080e017f95d935a7ce12a5a2a17fd34
      https://github.com/WebKit/WebKit/commit/46f1a9702080e017f95d935a7ce12a5a2a17fd34
  Author: Žan Doberšek <zdobersek at igalia.com>
  Date:   2023-01-16 (Mon, 16 Jan 2023)

  Changed paths:
    M Source/JavaScriptCore/inspector/InjectedScriptBase.cpp
    M Source/WTF/wtf/text/StringConcatenate.h
    M Source/WTF/wtf/text/StringOperators.h
    M Source/WTF/wtf/text/StringView.h
    M Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp
    M Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h

  Log Message:
  -----------
  Improve StringTypeAdapter templates and handling
https://bugs.webkit.org/show_bug.cgi?id=250017

Reviewed by Fujii Hironori.

StringConcatenate's makeString() and makeAtomString() are adjusted to accept
arguments as const lvalue references, propagating them down to each
StringTypeAdapter object without unnecessary copies. Similarly, the adapter
objects too are handled through const lvalue references once constructed and
passed on.

Newly-imposed constness requires additional const qualifiers on common methods
across different StringTypeAdapter specializations.

The are8Bit() and stringTypeAdapterAccumulator() helper functions are simplified
through using parameter packs and fold expressions to perform the necessary
operations across a range of adapter objects.

StringTypeAdapter specialization for StringView is moved from the StringView
header into the StringConcatenate header. A new partial specialization for the
StringTypeAdapter template is added, conditionally enabled if a const reference
of the specified type can be used to construct a StringView object. This
specialization inherits from the StringView specialization, hence a StringView
is constructed for such objects.

This enables removing a bunch of other StringTypeAdapter specializations.
Different WTF string and impl types can be used to construct the StringView,
as well as ASCIILiteral. For Vectors of character values, a corresponding Span
can be implicitly constructed and is then used for StringView construction.

In StringView, constructors taking in ASCIILiteral or Span are adjusted to
handle const lvalue references of those objects. A new templated StringView
constructor is added to handle C arrays of character data, delegating to the
corresponding character-and-length StringView constructors. The const char*
constructor is removed to avoid ambiguity with the constructor handling C arrays
of char values, with its now functionality inlined into the fromLatin1() helper.

Different static integer values can now end up generating undesired symbols when
handled through references in calls to makeString() and makeAtomString(). This
can be avoided by explicitly copying the passed-in value.

* Source/JavaScriptCore/inspector/InjectedScriptBase.cpp:
(Inspector::InjectedScriptBase::makeCall):
(Inspector::InjectedScriptBase::makeAsyncCall):
* Source/WTF/wtf/text/StringConcatenate.h:
(WTF::are8Bit):
(WTF::stringTypeAdapterAccumulator):
(WTF::tryMakeStringImplFromAdaptersInternal):
(WTF::handleWithAdapters):
(WTF::tryMakeStringFromAdapters):
(WTF::tryMakeString):
(WTF::makeString):
(WTF::tryMakeAtomStringFromAdapters):
(WTF::tryMakeAtomString):
(WTF::makeAtomString):
* Source/WTF/wtf/text/StringOperators.h:
(WTF::StringAppend::is8Bit const):
(WTF::StringAppend::writeTo const):
(WTF::StringAppend::length const):
(WTF::StringAppend::is8Bit): Deleted.
(WTF::StringAppend::writeTo): Deleted.
(WTF::StringAppend::length): Deleted.
* Source/WTF/wtf/text/StringView.h:
(WTF::StringView::StringView):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::updateNodeProperties):
* Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::makeVersionedDirectoryPath):

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




More information about the webkit-changes mailing list