Title: [246951] trunk/Source
Revision
246951
Author
[email protected]
Date
2019-06-29 14:50:00 -0700 (Sat, 29 Jun 2019)

Log Message

Streamline some string code, focusing on functions that were using substringSharingImpl
https://bugs.webkit.org/show_bug.cgi?id=198898

Reviewed by Daniel Bates.

Source/WebCore:

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::CSSComputedStyleDeclaration): Take a StringView
instead of a String argument for the pseudo-element name. This prevents us from having
to use substringSharingImpl to strip off leading colons.
(WebCore::CSSComputedStyleDeclaration::create): Moved this function in here since it's
no longer being inlined.

* css/CSSComputedStyleDeclaration.h: Moved the create function to no longer be inlined,
since it's better to have the constructor be inlined in the create function instead.
Changed the pseudo-element name argument to be a StringView rather than a String.
Also initialize m_refCount in the class definition.

* css/CSSSelector.cpp:
(WebCore::CSSSelector::parsePseudoElementType): Take a StringView instead of a String.
* css/CSSSelector.h: Updated for the above change.

* css/SelectorPseudoTypeMap.h: Change both parse functions to take StringView. Before
one took a StringImpl and the other used const StringView&, which is not as good as
StringView.

* css/makeSelectorPseudoClassAndCompatibilityElementMap.py: Use StringView, not
const StringView&.

* css/makeSelectorPseudoElementsMap.py: Use StringView rather than StringImpl.

* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::parsePageSelector): Use a StringView for the pseudo-element
name. It was already computed as a StringView, but the old code converted it to
an AtomicString.

* css/parser/CSSParserSelector.cpp:
(WebCore::CSSParserSelector::parsePagePseudoSelector): Take a StringView, and
return a std::unique_ptr.
(WebCore::CSSParserSelector::parsePseudoElementSelector): Renamed to not mention
StringView in function name. Take a StringView, not a StringView&. Do the lowercasing
inside this function rather than having it be a caller responsibility. Don't convert
from a StringView to an AtomicString before starting to parse; only do it in the
"unknown/custom" case. Return a std::unique_ptr.
(WebCore::CSSParserSelector::parsePseudoClassSelector): Ditto.
* css/parser/CSSParserSelector.h: Make the three parse functions all take a StringView
and all return a std::unique_ptr. They were already creating objects, but before
callers just had to know to adopt.
* css/parser/CSSSelectorParser.cpp:
(WebCore::CSSSelectorParser::consumePseudo): Updated to use improved parse
functions above.

* page/DOMWindow.cpp:
(WebCore::DOMWindow::getMatchedCSSRules const): Updated to use the new
parsePseudoElementType above and use StringView::substring instead of
String::substringSharingImpl.

* platform/Length.cpp:
(WebCore::newCoordsArray): Local string that is "spacified" can't have any non-Latin-1
characters, so use LChar instead of UChar.

* rendering/RenderText.cpp:
(WebCore::convertNoBreakSpaceToSpace): Renamed for clarity. Also use constexpr
instead of inline since this is a pure function.
(WebCore::capitalize): Tighten up logic a bit.

Source/WTF:

* wtf/URLHelpers.cpp:
(WTF::URLHelpers::applyHostNameFunctionToURLString): Change code using
substringSharingImpl so it could call String::find to call StringView::contains
instead. Also rewrote lambdas to be simpler and likely more efficient.
Rewrote another case using substringSharingImpl so it could call String::find
to call StringView::find instead.

* wtf/text/StringView.cpp:
(WTF::StringView::startsWith const): Added.

* wtf/text/StringView.h: Tweaked style a bit, and added an overload of
StringView::contains that takes a CodeUnitMatchFunction and an overload
of startsWith that cakes a UChar.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (246950 => 246951)


--- trunk/Source/WTF/ChangeLog	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WTF/ChangeLog	2019-06-29 21:50:00 UTC (rev 246951)
@@ -1,3 +1,24 @@
+2019-06-22  Darin Adler  <[email protected]>
+
+        Streamline some string code, focusing on functions that were using substringSharingImpl
+        https://bugs.webkit.org/show_bug.cgi?id=198898
+
+        Reviewed by Daniel Bates.
+
+        * wtf/URLHelpers.cpp:
+        (WTF::URLHelpers::applyHostNameFunctionToURLString): Change code using
+        substringSharingImpl so it could call String::find to call StringView::contains
+        instead. Also rewrote lambdas to be simpler and likely more efficient.
+        Rewrote another case using substringSharingImpl so it could call String::find
+        to call StringView::find instead.
+
+        * wtf/text/StringView.cpp:
+        (WTF::StringView::startsWith const): Added.
+
+        * wtf/text/StringView.h: Tweaked style a bit, and added an overload of
+        StringView::contains that takes a CodeUnitMatchFunction and an overload
+        of startsWith that cakes a UChar.
+
 2019-06-28  Konstantin Tokarev  <[email protected]>
 
         Remove traces of ENABLE_ICONDATABASE remaining after its removal in 219733

Modified: trunk/Source/WTF/wtf/URLHelpers.cpp (246950 => 246951)


--- trunk/Source/WTF/wtf/URLHelpers.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WTF/wtf/URLHelpers.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -664,7 +664,7 @@
         applyHostNameFunctionToMailToURLString(string, decodeFunction, array);
         return;
     }
-    
+
     // Find the host name in a hierarchical URL.
     // It comes after a "://" sequence, with scheme characters preceding.
     // If ends with the end of the string or a ":", "/", or a "?".
@@ -675,39 +675,23 @@
         return;
 
     unsigned authorityStart = separatorIndex + strlen(separator);
-    
+
     // Check that all characters before the :// are valid scheme characters.
-    auto invalidSchemeCharacter = string.substringSharingImpl(0, separatorIndex).find([](UChar ch) {
-        static const char* allowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.";
-        static size_t length = strlen(allowedCharacters);
-        for (size_t i = 0; i < length; ++i) {
-            if (allowedCharacters[i] == ch)
-                return false;
-        }
-        return true;
-    });
+    if (StringView { string }.left(separatorIndex).contains([](UChar character) {
+        return !(isASCIIAlphanumeric(character) || character == '+' || character == '-' || character == '.');
+    }))
+        return;
 
-    if (invalidSchemeCharacter != notFound)
-        return;
-    
-    unsigned stringLength = string.length();
-    
     // Find terminating character.
-    auto hostNameTerminator = string.find([](UChar ch) {
-        static const char* terminatingCharacters = ":/?#";
-        static size_t length = strlen(terminatingCharacters);
-        for (size_t i = 0; i < length; ++i) {
-            if (terminatingCharacters[i] == ch)
-                return true;
-        }
-        return false;
+    auto hostNameTerminator = string.find([](UChar character) {
+        return character == ':' || character == '/' || character == '?' || character == '#';
     }, authorityStart);
-    unsigned hostNameEnd = hostNameTerminator == notFound ? stringLength : hostNameTerminator;
-    
+    unsigned hostNameEnd = hostNameTerminator == notFound ? string.length() : hostNameTerminator;
+
     // Find "@" for the start of the host name.
-    auto userInfoTerminator = string.substringSharingImpl(0, hostNameEnd).find('@', authorityStart);
+    auto userInfoTerminator = StringView { string }.left(hostNameEnd).find('@', authorityStart);
     unsigned hostNameStart = userInfoTerminator == notFound ? authorityStart : userInfoTerminator + 1;
-    
+
     collectRangesThatNeedMapping(string, hostNameStart, hostNameEnd - hostNameStart, array, decodeFunction);
 }
 

Modified: trunk/Source/WTF/wtf/text/StringView.cpp (246950 => 246951)


--- trunk/Source/WTF/wtf/text/StringView.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WTF/wtf/text/StringView.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -58,6 +58,11 @@
     return ::WTF::findIgnoringASCIICase(*this, matchString, startOffset);
 }
 
+bool StringView::startsWith(UChar character) const
+{
+    return m_length && (*this)[0] == character;
+}
+
 bool StringView::startsWith(const StringView& prefix) const
 {
     return ::WTF::startsWith(*this, prefix);

Modified: trunk/Source/WTF/wtf/text/StringView.h (246950 => 246951)


--- trunk/Source/WTF/wtf/text/StringView.h	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WTF/wtf/text/StringView.h	2019-06-29 21:50:00 UTC (rev 246951)
@@ -96,7 +96,7 @@
     RefPtr<AtomStringImpl> toExistingAtomString() const;
 
 #if USE(CF)
-    // This function converts null strings to empty strings.
+    // These functions convert null strings to empty strings.
     WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFString() const;
     WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFStringWithoutCopying() const;
 #endif
@@ -117,8 +117,8 @@
     void getCharactersWithUpconvert(UChar*) const;
 
     StringView substring(unsigned start, unsigned length = std::numeric_limits<unsigned>::max()) const;
-    StringView left(unsigned len) const { return substring(0, len); }
-    StringView right(unsigned len) const { return substring(length() - len, len); }
+    StringView left(unsigned length) const { return substring(0, length); }
+    StringView right(unsigned length) const { return substring(this->length() - length, length); }
 
     template<typename MatchedCharacterPredicate>
     StringView stripLeadingAndTrailingMatchedCharacters(const MatchedCharacterPredicate&);
@@ -132,7 +132,7 @@
 
     WTF_EXPORT_PRIVATE size_t find(StringView, unsigned start) const;
 
-    size_t reverseFind(UChar, unsigned index = UINT_MAX) const;
+    size_t reverseFind(UChar, unsigned index = std::numeric_limits<unsigned>::max()) const;
 
     WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(const StringView&) const;
     WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(const StringView&, unsigned startOffset) const;
@@ -141,9 +141,11 @@
     WTF_EXPORT_PRIVATE String convertToASCIIUppercase() const;
 
     bool contains(UChar) const;
+    bool contains(CodeUnitMatchFunction) const;
     WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&) const;
     WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&, unsigned startOffset) const;
 
+    WTF_EXPORT_PRIVATE bool startsWith(UChar) const;
     WTF_EXPORT_PRIVATE bool startsWith(const StringView&) const;
     WTF_EXPORT_PRIVATE bool startsWithIgnoringASCIICase(const StringView&) const;
 
@@ -173,6 +175,7 @@
     WTF_EXPORT_PRIVATE bool underlyingStringIsValid() const;
     WTF_EXPORT_PRIVATE void setUnderlyingString(const StringImpl*);
     WTF_EXPORT_PRIVATE void setUnderlyingString(const StringView&);
+    void adoptUnderlyingString(UnderlyingString*);
 #else
     bool underlyingStringIsValid() const { return true; }
     void setUnderlyingString(const StringImpl*) { }
@@ -185,7 +188,6 @@
     bool m_is8Bit { true };
 
 #if CHECK_STRINGVIEW_LIFETIME
-    void adoptUnderlyingString(UnderlyingString*);
     UnderlyingString* m_underlyingString { nullptr };
 #endif
 };
@@ -468,6 +470,11 @@
     return find(character) != notFound;
 }
 
+inline bool StringView::contains(CodeUnitMatchFunction function) const
+{
+    return find(function) != notFound;
+}
+
 inline void StringView::getCharactersWithUpconvert(LChar* destination) const
 {
     ASSERT(is8Bit());

Modified: trunk/Source/WebCore/ChangeLog (246950 => 246951)


--- trunk/Source/WebCore/ChangeLog	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/ChangeLog	2019-06-29 21:50:00 UTC (rev 246951)
@@ -1,3 +1,70 @@
+2019-06-22  Darin Adler  <[email protected]>
+
+        Streamline some string code, focusing on functions that were using substringSharingImpl
+        https://bugs.webkit.org/show_bug.cgi?id=198898
+
+        Reviewed by Daniel Bates.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::CSSComputedStyleDeclaration::CSSComputedStyleDeclaration): Take a StringView
+        instead of a String argument for the pseudo-element name. This prevents us from having
+        to use substringSharingImpl to strip off leading colons.
+        (WebCore::CSSComputedStyleDeclaration::create): Moved this function in here since it's
+        no longer being inlined.
+
+        * css/CSSComputedStyleDeclaration.h: Moved the create function to no longer be inlined,
+        since it's better to have the constructor be inlined in the create function instead.
+        Changed the pseudo-element name argument to be a StringView rather than a String.
+        Also initialize m_refCount in the class definition.
+
+        * css/CSSSelector.cpp:
+        (WebCore::CSSSelector::parsePseudoElementType): Take a StringView instead of a String.
+        * css/CSSSelector.h: Updated for the above change.
+
+        * css/SelectorPseudoTypeMap.h: Change both parse functions to take StringView. Before
+        one took a StringImpl and the other used const StringView&, which is not as good as
+        StringView.
+
+        * css/makeSelectorPseudoClassAndCompatibilityElementMap.py: Use StringView, not
+        const StringView&.
+
+        * css/makeSelectorPseudoElementsMap.py: Use StringView rather than StringImpl.
+
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::parsePageSelector): Use a StringView for the pseudo-element
+        name. It was already computed as a StringView, but the old code converted it to
+        an AtomicString.
+
+        * css/parser/CSSParserSelector.cpp:
+        (WebCore::CSSParserSelector::parsePagePseudoSelector): Take a StringView, and
+        return a std::unique_ptr.
+        (WebCore::CSSParserSelector::parsePseudoElementSelector): Renamed to not mention
+        StringView in function name. Take a StringView, not a StringView&. Do the lowercasing
+        inside this function rather than having it be a caller responsibility. Don't convert
+        from a StringView to an AtomicString before starting to parse; only do it in the
+        "unknown/custom" case. Return a std::unique_ptr.
+        (WebCore::CSSParserSelector::parsePseudoClassSelector): Ditto.
+        * css/parser/CSSParserSelector.h: Make the three parse functions all take a StringView
+        and all return a std::unique_ptr. They were already creating objects, but before
+        callers just had to know to adopt.
+        * css/parser/CSSSelectorParser.cpp:
+        (WebCore::CSSSelectorParser::consumePseudo): Updated to use improved parse
+        functions above.
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::getMatchedCSSRules const): Updated to use the new
+        parsePseudoElementType above and use StringView::substring instead of
+        String::substringSharingImpl.
+
+        * platform/Length.cpp:
+        (WebCore::newCoordsArray): Local string that is "spacified" can't have any non-Latin-1
+        characters, so use LChar instead of UChar.
+
+        * rendering/RenderText.cpp:
+        (WebCore::convertNoBreakSpaceToSpace): Renamed for clarity. Also use constexpr
+        instead of inline since this is a pure function.
+        (WebCore::capitalize): Tighten up logic a bit.
+
 2019-06-29  Simon Fraser  <[email protected]>
 
         Remove a PLATFORM(IOS_FAMILY) related to repaint offsets in composited scrolling layers

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (246950 => 246951)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -1658,18 +1658,25 @@
 {
 }
 
-CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(Element& element, bool allowVisitedStyle, const String& pseudoElementName)
+CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(Element& element, bool allowVisitedStyle, StringView pseudoElementName)
     : m_element(element)
     , m_allowVisitedStyle(allowVisitedStyle)
-    , m_refCount(1)
 {
-    unsigned nameWithoutColonsStart = pseudoElementName[0] == ':' ? (pseudoElementName[1] == ':' ? 2 : 1) : 0;
-    m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoElementType(
-    (pseudoElementName.substringSharingImpl(nameWithoutColonsStart))));
+    StringView name = pseudoElementName;
+    if (name.startsWith(':'))
+        name = name.substring(1);
+    if (name.startsWith(':'))
+        name = name.substring(1);
+    m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoElementType(name));
 }
 
 CSSComputedStyleDeclaration::~CSSComputedStyleDeclaration() = default;
 
+Ref<CSSComputedStyleDeclaration> CSSComputedStyleDeclaration::create(Element& element, bool allowVisitedStyle, StringView pseudoElementName)
+{
+    return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName));
+}
+
 void CSSComputedStyleDeclaration::ref()
 {
     ++m_refCount;

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h (246950 => 246951)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2019-06-29 21:50:00 UTC (rev 246951)
@@ -107,10 +107,7 @@
 class CSSComputedStyleDeclaration final : public CSSStyleDeclaration {
     WTF_MAKE_ISO_ALLOCATED_EXPORT(CSSComputedStyleDeclaration, WEBCORE_EXPORT);
 public:
-    static Ref<CSSComputedStyleDeclaration> create(Element& element, bool allowVisitedStyle = false, const String& pseudoElementName = String())
-    {
-        return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName));
-    }
+    WEBCORE_EXPORT static Ref<CSSComputedStyleDeclaration> create(Element&, bool allowVisitedStyle = false, StringView pseudoElementName = StringView { });
     virtual ~CSSComputedStyleDeclaration();
 
     WEBCORE_EXPORT void ref() final;
@@ -119,7 +116,7 @@
     String getPropertyValue(CSSPropertyID) const;
 
 private:
-    WEBCORE_EXPORT CSSComputedStyleDeclaration(Element&, bool allowVisitedStyle, const String&);
+    CSSComputedStyleDeclaration(Element&, bool allowVisitedStyle, StringView);
 
     // CSSOM functions. Don't make these public.
     CSSRule* parentRule() const final;
@@ -144,7 +141,7 @@
     mutable Ref<Element> m_element;
     PseudoId m_pseudoElementSpecifier;
     bool m_allowVisitedStyle;
-    unsigned m_refCount;
+    unsigned m_refCount { 1 };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/CSSSelector.cpp (246950 => 246951)


--- trunk/Source/WebCore/css/CSSSelector.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/CSSSelector.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -308,12 +308,11 @@
     return PseudoId::None;
 }
 
-CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(const String& name)
+CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(StringView name)
 {
     if (name.isNull())
         return PseudoElementUnknown;
-
-    PseudoElementType type = parsePseudoElementString(*name.impl());
+    auto type = parsePseudoElementString(name);
     if (type == PseudoElementUnknown) {
         if (name.startsWith("-webkit-"))
             type = PseudoElementWebKitCustom;
@@ -321,7 +320,6 @@
     return type;
 }
 
-
 bool CSSSelector::operator==(const CSSSelector& other) const
 {
     const CSSSelector* sel1 = this;

Modified: trunk/Source/WebCore/css/CSSSelector.h (246950 => 246951)


--- trunk/Source/WebCore/css/CSSSelector.h	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/CSSSelector.h	2019-06-29 21:50:00 UTC (rev 246951)
@@ -223,7 +223,7 @@
             CaseInsensitive,
         };
 
-        static PseudoElementType parsePseudoElementType(const String&);
+        static PseudoElementType parsePseudoElementType(StringView);
         static PseudoId pseudoId(PseudoElementType);
 
         // Selectors are kept in an array by CSSSelectorList. The next component of the selector is

Modified: trunk/Source/WebCore/css/SelectorPseudoTypeMap.h (246950 => 246951)


--- trunk/Source/WebCore/css/SelectorPseudoTypeMap.h	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/SelectorPseudoTypeMap.h	2019-06-29 21:50:00 UTC (rev 246951)
@@ -34,7 +34,7 @@
     CSSSelector::PseudoElementType compatibilityPseudoElement;
 };
 
-PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(const StringView& pseudoTypeString);
-CSSSelector::PseudoElementType parsePseudoElementString(const StringImpl& pseudoTypeString);
+PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(StringView pseudoTypeString);
+CSSSelector::PseudoElementType parsePseudoElementString(StringView pseudoTypeString);
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py (246950 => 246951)


--- trunk/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py	2019-06-29 21:50:00 UTC (rev 246951)
@@ -184,7 +184,7 @@
 """ % longest_keyword)
 
 output_file.write("""
-PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(const StringView& pseudoTypeString)
+PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(StringView pseudoTypeString)
 {
     const SelectorPseudoClassOrCompatibilityPseudoElementEntry* entry;
     if (pseudoTypeString.is8Bit())

Modified: trunk/Source/WebCore/css/makeSelectorPseudoElementsMap.py (246950 => 246951)


--- trunk/Source/WebCore/css/makeSelectorPseudoElementsMap.py	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/makeSelectorPseudoElementsMap.py	2019-06-29 21:50:00 UTC (rev 246951)
@@ -185,7 +185,7 @@
 """ % longest_keyword)
 
 output_file.write("""
-CSSSelector::PseudoElementType parsePseudoElementString(const StringImpl& pseudoTypeString)
+CSSSelector::PseudoElementType parsePseudoElementString(StringView pseudoTypeString)
 {
     if (pseudoTypeString.is8Bit())
         return parsePseudoElementString(pseudoTypeString.characters8(), pseudoTypeString.length());

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (246950 => 246951)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -268,12 +268,12 @@
     if (range.peek().type() == IdentToken)
         typeSelector = range.consume().value().toAtomString();
 
-    AtomString pseudo;
+    StringView pseudo;
     if (range.peek().type() == ColonToken) {
         range.consume();
         if (range.peek().type() != IdentToken)
             return CSSSelectorList();
-        pseudo = range.consume().value().toAtomString();
+        pseudo = range.consume().value();
     }
 
     range.consumeWhitespace();

Modified: trunk/Source/WebCore/css/parser/CSSParserSelector.cpp (246950 => 246951)


--- trunk/Source/WebCore/css/parser/CSSParserSelector.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/parser/CSSParserSelector.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -32,7 +32,7 @@
 
 namespace WebCore {
 
-CSSParserSelector* CSSParserSelector::parsePagePseudoSelector(const AtomString& pseudoTypeString)
+std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePagePseudoSelector(StringView pseudoTypeString)
 {
     CSSSelector::PagePseudoClassType pseudoType;
     if (equalLettersIgnoringASCIICase(pseudoTypeString, "first"))
@@ -43,18 +43,16 @@
         pseudoType = CSSSelector::PagePseudoClassRight;
     else
         return nullptr;
-    
+
     auto selector = std::make_unique<CSSParserSelector>();
     selector->m_selector->setMatch(CSSSelector::PagePseudoClass);
     selector->m_selector->setPagePseudoType(pseudoType);
-    return selector.release();
+    return selector;
 }
 
-CSSParserSelector* CSSParserSelector::parsePseudoElementSelectorFromStringView(StringView& pseudoTypeString)
+std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePseudoElementSelector(StringView pseudoTypeString)
 {
-    AtomString name = pseudoTypeString.toAtomString();
-    
-    CSSSelector::PseudoElementType pseudoType = CSSSelector::parsePseudoElementType(name);
+    auto pseudoType = CSSSelector::parsePseudoElementType(pseudoTypeString);
     if (pseudoType == CSSSelector::PseudoElementUnknown) {
         // FIXME-NEWPARSER: We can't add "slotted" to the map without breaking the old
         // parser, so this hack ensures the new parser still recognizes it. When the new
@@ -68,31 +66,35 @@
     auto selector = std::make_unique<CSSParserSelector>();
     selector->m_selector->setMatch(CSSSelector::PseudoElement);
     selector->m_selector->setPseudoElementType(pseudoType);
-    if (pseudoType == CSSSelector::PseudoElementWebKitCustomLegacyPrefixed) {
-        ASSERT_WITH_MESSAGE(name == "-webkit-input-placeholder", "-webkit-input-placeholder is the only LegacyPrefix pseudo type.");
-        if (name == "-webkit-input-placeholder")
+    AtomString name;
+    if (pseudoType != CSSSelector::PseudoElementWebKitCustomLegacyPrefixed)
+        name = pseudoTypeString.convertToASCIILowercase();
+    else {
+        ASSERT_WITH_MESSAGE(equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-input-placeholder"), "-webkit-input-placeholder is the only LegacyPrefix pseudo type.");
+        if (equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-input-placeholder"))
             name = AtomString("placeholder", AtomString::ConstructFromLiteral);
+        else
+            name = pseudoTypeString.convertToASCIILowercase();
     }
     selector->m_selector->setValue(name);
-    return selector.release();
+    return selector;
 }
 
-CSSParserSelector* CSSParserSelector::parsePseudoClassSelectorFromStringView(StringView& pseudoTypeString)
+std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePseudoClassSelector(StringView pseudoTypeString)
 {
-    PseudoClassOrCompatibilityPseudoElement pseudoType = parsePseudoClassAndCompatibilityElementString(pseudoTypeString);
+    auto pseudoType = parsePseudoClassAndCompatibilityElementString(pseudoTypeString);
     if (pseudoType.pseudoClass != CSSSelector::PseudoClassUnknown) {
         auto selector = std::make_unique<CSSParserSelector>();
         selector->m_selector->setMatch(CSSSelector::PseudoClass);
         selector->m_selector->setPseudoClassType(pseudoType.pseudoClass);
-        return selector.release();
+        return selector;
     }
     if (pseudoType.compatibilityPseudoElement != CSSSelector::PseudoElementUnknown) {
         auto selector = std::make_unique<CSSParserSelector>();
         selector->m_selector->setMatch(CSSSelector::PseudoElement);
         selector->m_selector->setPseudoElementType(pseudoType.compatibilityPseudoElement);
-        AtomString name = pseudoTypeString.toAtomString();
-        selector->m_selector->setValue(name);
-        return selector.release();
+        selector->m_selector->setValue(pseudoTypeString.convertToASCIILowercase());
+        return selector;
     }
     return nullptr;
 }

Modified: trunk/Source/WebCore/css/parser/CSSParserSelector.h (246950 => 246951)


--- trunk/Source/WebCore/css/parser/CSSParserSelector.h	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/parser/CSSParserSelector.h	2019-06-29 21:50:00 UTC (rev 246951)
@@ -21,16 +21,10 @@
 #pragma once
 
 #include "CSSSelector.h"
-#include "CSSValueKeywords.h"
-#include <wtf/text/AtomString.h>
 #include <wtf/text/AtomStringHash.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-class CSSValue;
-class QualifiedName;
-
 enum class CSSParserSelectorCombinator {
     Child,
     DescendantSpace,
@@ -41,10 +35,10 @@
 class CSSParserSelector {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static CSSParserSelector* parsePseudoClassSelectorFromStringView(StringView&);
-    static CSSParserSelector* parsePseudoElementSelectorFromStringView(StringView&);
-    static CSSParserSelector* parsePagePseudoSelector(const AtomString&);
-    
+    static std::unique_ptr<CSSParserSelector> parsePseudoClassSelector(StringView);
+    static std::unique_ptr<CSSParserSelector> parsePseudoElementSelector(StringView);
+    static std::unique_ptr<CSSParserSelector> parsePagePseudoSelector(StringView);
+
     CSSParserSelector();
     explicit CSSParserSelector(const QualifiedName&);
     ~CSSParserSelector();
@@ -74,14 +68,7 @@
     CSSSelector::PseudoClassType pseudoClassType() const { return m_selector->pseudoClassType(); }
     bool isCustomPseudoElement() const { return m_selector->isCustomPseudoElement(); }
 
-    bool isPseudoElementCueFunction() const
-    {
-#if ENABLE(VIDEO_TRACK)
-        return m_selector->match() == CSSSelector::PseudoElement && m_selector->pseudoElementType() == CSSSelector::PseudoElementCue;
-#else
-        return false;
-#endif
-    }
+    bool isPseudoElementCueFunction() const;
 
     bool hasShadowDescendant() const;
     bool matchesPseudoElement() const;
@@ -123,4 +110,13 @@
             || pseudoElementType() == CSSSelector::PseudoElementWebKitCustomLegacyPrefixed);
 }
 
+inline bool CSSParserSelector::isPseudoElementCueFunction() const
+{
+#if ENABLE(VIDEO_TRACK)
+    return m_selector->match() == CSSSelector::PseudoElement && m_selector->pseudoElementType() == CSSSelector::PseudoElementCue;
+#else
+    return false;
+#endif
 }
+
+}

Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp (246950 => 246951)


--- trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -487,17 +487,14 @@
 
     std::unique_ptr<CSSParserSelector> selector;
     
-    auto lowercasedValue = token.value().convertToASCIILowercase();
-    auto value = StringView { lowercasedValue };
-
     if (colons == 1) {
-        selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoClassSelectorFromStringView(value));
+        selector = CSSParserSelector::parsePseudoClassSelector(token.value());
 #if ENABLE(ATTACHMENT_ELEMENT)
         if (!m_context.attachmentEnabled && selector && selector->match() == CSSSelector::PseudoClass && selector->pseudoClassType() == CSSSelector::PseudoClassHasAttachment)
             return nullptr;
 #endif
     } else {
-        selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoElementSelectorFromStringView(value));
+        selector = CSSParserSelector::parsePseudoElementSelector(token.value());
 #if ENABLE(VIDEO_TRACK)
         // Treat the ident version of cue as PseudoElementWebkitCustom.
         if (token.type() == IdentToken && selector && selector->match() == CSSSelector::PseudoElement && selector->pseudoElementType() == CSSSelector::PseudoElementCue)

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (246950 => 246951)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -1490,7 +1490,7 @@
         return nullptr;
 
     unsigned colonStart = pseudoElement[0] == ':' ? (pseudoElement[1] == ':' ? 2 : 1) : 0;
-    CSSSelector::PseudoElementType pseudoType = CSSSelector::parsePseudoElementType(pseudoElement.substringSharingImpl(colonStart));
+    auto pseudoType = CSSSelector::parsePseudoElementType(StringView { pseudoElement }.substring(colonStart));
     if (pseudoType == CSSSelector::PseudoElementUnknown && !pseudoElement.isEmpty())
         return nullptr;
 

Modified: trunk/Source/WebCore/page/EventSource.cpp (246950 => 246951)


--- trunk/Source/WebCore/page/EventSource.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/page/EventSource.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -349,7 +349,8 @@
         m_eventName = { &m_receiveBuffer[position], valueLength };
     else if (field == "id") {
         StringView parsedEventId = { &m_receiveBuffer[position], valueLength };
-        if (!parsedEventId.contains('\0'))
+        constexpr UChar nullCharacter = '\0';
+        if (!parsedEventId.contains(nullCharacter))
             m_currentlyParsedEventId = parsedEventId.toString();
     } else if (field == "retry") {
         if (!valueLength)

Modified: trunk/Source/WebCore/platform/Length.cpp (246950 => 246951)


--- trunk/Source/WebCore/platform/Length.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/platform/Length.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -89,16 +89,15 @@
 UniqueArray<Length> newCoordsArray(const String& string, int& len)
 {
     unsigned length = string.length();
-    UChar* spacified;
-    auto str = StringImpl::createUninitialized(length, spacified);
+    LChar* spacifiedCharacters;
+    auto str = StringImpl::createUninitialized(length, spacifiedCharacters);
     for (unsigned i = 0; i < length; i++) {
         UChar cc = string[i];
         if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.'))
-            spacified[i] = ' ';
+            spacifiedCharacters[i] = ' ';
         else
-            spacified[i] = cc;
+            spacifiedCharacters[i] = cc;
     }
-
     str = str->simplifyWhiteSpace();
 
     len = countCharacter(str, ' ') + 1;

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (246950 => 246951)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2019-06-29 21:01:40 UTC (rev 246950)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2019-06-29 21:50:00 UTC (rev 246951)
@@ -140,7 +140,7 @@
     return map;
 }
 
-static inline UChar convertNoBreakSpace(UChar character)
+static constexpr UChar convertNoBreakSpaceToSpace(UChar character)
 {
     return character == noBreakSpace ? ' ' : character;
 }
@@ -150,28 +150,30 @@
     // FIXME: Change this to use u_strToTitle instead of u_totitle and to consider locale.
 
     unsigned length = string.length();
+    auto& stringImpl = *string.impl();
 
-    // Prepend the previous character, and convert NO BREAK SPACE to SPACE so ICU will see a word separator.
-    Vector<UChar> wordBreakCharacters;
-    wordBreakCharacters.grow(length + 1);
-    wordBreakCharacters[0] = convertNoBreakSpace(previousCharacter);
+    static_assert(String::MaxLength < std::numeric_limits<unsigned>::max(), "Must be able to add one without overflowing unsigned");
+
+    // Replace NO BREAK SPACE with a normal spaces since ICU does not treat it as a word separator.
+    Vector<UChar> stringWithPrevious(length + 1);
+    stringWithPrevious[0] = convertNoBreakSpaceToSpace(previousCharacter);
     for (unsigned i = 1; i < length + 1; i++)
-        wordBreakCharacters[i] = convertNoBreakSpace(string[i - 1]);
+        stringWithPrevious[i] = convertNoBreakSpaceToSpace(stringImpl[i - 1]);
 
-    auto* boundary = wordBreakIterator(StringView { wordBreakCharacters.data(), length + 1 });
-    if (!boundary)
+    auto* breakIterator = wordBreakIterator(StringView { stringWithPrevious.data(), length + 1 });
+    if (!breakIterator)
         return string;
 
     StringBuilder result;
     result.reserveCapacity(length);
 
+    int32_t startOfWord = ubrk_first(breakIterator);
     int32_t endOfWord;
-    int32_t startOfWord = ubrk_first(boundary);
-    for (endOfWord = ubrk_next(boundary); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(boundary)) {
-        if (startOfWord) // Ignore first char of previous string
-            result.append(string[startOfWord - 1] == noBreakSpace ? noBreakSpace : u_totitle(wordBreakCharacters[startOfWord]));
+    for (endOfWord = ubrk_next(breakIterator); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(breakIterator)) {
+        if (startOfWord) // Do not append the first character, since it's the previous character, not from this string.
+            result.append(u_totitle(stringImpl[startOfWord - 1]));
         for (int i = startOfWord + 1; i < endOfWord; i++)
-            result.append(string[i - 1]);
+            result.append(stringImpl[i - 1]);
     }
 
     return result == string ? string : result.toString();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to