Changeset 246951 in webkit


Ignore:
Timestamp:
Jun 29, 2019 2:50:00 PM (5 years ago)
Author:
Darin Adler
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.

Location:
trunk/Source
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r246925 r246951  
     12019-06-22  Darin Adler  <darin@apple.com>
     2
     3        Streamline some string code, focusing on functions that were using substringSharingImpl
     4        https://bugs.webkit.org/show_bug.cgi?id=198898
     5
     6        Reviewed by Daniel Bates.
     7
     8        * wtf/URLHelpers.cpp:
     9        (WTF::URLHelpers::applyHostNameFunctionToURLString): Change code using
     10        substringSharingImpl so it could call String::find to call StringView::contains
     11        instead. Also rewrote lambdas to be simpler and likely more efficient.
     12        Rewrote another case using substringSharingImpl so it could call String::find
     13        to call StringView::find instead.
     14
     15        * wtf/text/StringView.cpp:
     16        (WTF::StringView::startsWith const): Added.
     17
     18        * wtf/text/StringView.h: Tweaked style a bit, and added an overload of
     19        StringView::contains that takes a CodeUnitMatchFunction and an overload
     20        of startsWith that cakes a UChar.
     21
    1222019-06-28  Konstantin Tokarev  <annulen@yandex.ru>
    223
  • trunk/Source/WTF/wtf/URLHelpers.cpp

    r246906 r246951  
    665665        return;
    666666    }
    667    
     667
    668668    // Find the host name in a hierarchical URL.
    669669    // It comes after a "://" sequence, with scheme characters preceding.
     
    676676
    677677    unsigned authorityStart = separatorIndex + strlen(separator);
    678    
     678
    679679    // Check that all characters before the :// are valid scheme characters.
    680     auto invalidSchemeCharacter = string.substringSharingImpl(0, separatorIndex).find([](UChar ch) {
    681         static const char* allowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.";
    682         static size_t length = strlen(allowedCharacters);
    683         for (size_t i = 0; i < length; ++i) {
    684             if (allowedCharacters[i] == ch)
    685                 return false;
    686         }
    687         return true;
    688     });
    689 
    690     if (invalidSchemeCharacter != notFound)
     680    if (StringView { string }.left(separatorIndex).contains([](UChar character) {
     681        return !(isASCIIAlphanumeric(character) || character == '+' || character == '-' || character == '.');
     682    }))
    691683        return;
    692    
    693     unsigned stringLength = string.length();
    694    
     684
    695685    // Find terminating character.
    696     auto hostNameTerminator = string.find([](UChar ch) {
    697         static const char* terminatingCharacters = ":/?#";
    698         static size_t length = strlen(terminatingCharacters);
    699         for (size_t i = 0; i < length; ++i) {
    700             if (terminatingCharacters[i] == ch)
    701                 return true;
    702         }
    703         return false;
     686    auto hostNameTerminator = string.find([](UChar character) {
     687        return character == ':' || character == '/' || character == '?' || character == '#';
    704688    }, authorityStart);
    705     unsigned hostNameEnd = hostNameTerminator == notFound ? stringLength : hostNameTerminator;
    706    
     689    unsigned hostNameEnd = hostNameTerminator == notFound ? string.length() : hostNameTerminator;
     690
    707691    // Find "@" for the start of the host name.
    708     auto userInfoTerminator = string.substringSharingImpl(0, hostNameEnd).find('@', authorityStart);
     692    auto userInfoTerminator = StringView { string }.left(hostNameEnd).find('@', authorityStart);
    709693    unsigned hostNameStart = userInfoTerminator == notFound ? authorityStart : userInfoTerminator + 1;
    710    
     694
    711695    collectRangesThatNeedMapping(string, hostNameStart, hostNameEnd - hostNameStart, array, decodeFunction);
    712696}
  • trunk/Source/WTF/wtf/text/StringView.cpp

    r244828 r246951  
    5757{
    5858    return ::WTF::findIgnoringASCIICase(*this, matchString, startOffset);
     59}
     60
     61bool StringView::startsWith(UChar character) const
     62{
     63    return m_length && (*this)[0] == character;
    5964}
    6065
  • trunk/Source/WTF/wtf/text/StringView.h

    r246490 r246951  
    9797
    9898#if USE(CF)
    99     // This function converts null strings to empty strings.
     99    // These functions convert null strings to empty strings.
    100100    WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFString() const;
    101101    WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFStringWithoutCopying() const;
     
    118118
    119119    StringView substring(unsigned start, unsigned length = std::numeric_limits<unsigned>::max()) const;
    120     StringView left(unsigned len) const { return substring(0, len); }
    121     StringView right(unsigned len) const { return substring(length() - len, len); }
     120    StringView left(unsigned length) const { return substring(0, length); }
     121    StringView right(unsigned length) const { return substring(this->length() - length, length); }
    122122
    123123    template<typename MatchedCharacterPredicate>
     
    133133    WTF_EXPORT_PRIVATE size_t find(StringView, unsigned start) const;
    134134
    135     size_t reverseFind(UChar, unsigned index = UINT_MAX) const;
     135    size_t reverseFind(UChar, unsigned index = std::numeric_limits<unsigned>::max()) const;
    136136
    137137    WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(const StringView&) const;
     
    142142
    143143    bool contains(UChar) const;
     144    bool contains(CodeUnitMatchFunction) const;
    144145    WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&) const;
    145146    WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&, unsigned startOffset) const;
    146147
     148    WTF_EXPORT_PRIVATE bool startsWith(UChar) const;
    147149    WTF_EXPORT_PRIVATE bool startsWith(const StringView&) const;
    148150    WTF_EXPORT_PRIVATE bool startsWithIgnoringASCIICase(const StringView&) const;
     
    174176    WTF_EXPORT_PRIVATE void setUnderlyingString(const StringImpl*);
    175177    WTF_EXPORT_PRIVATE void setUnderlyingString(const StringView&);
     178    void adoptUnderlyingString(UnderlyingString*);
    176179#else
    177180    bool underlyingStringIsValid() const { return true; }
     
    186189
    187190#if CHECK_STRINGVIEW_LIFETIME
    188     void adoptUnderlyingString(UnderlyingString*);
    189191    UnderlyingString* m_underlyingString { nullptr };
    190192#endif
     
    467469{
    468470    return find(character) != notFound;
     471}
     472
     473inline bool StringView::contains(CodeUnitMatchFunction function) const
     474{
     475    return find(function) != notFound;
    469476}
    470477
  • trunk/Source/WebCore/ChangeLog

    r246950 r246951  
     12019-06-22  Darin Adler  <darin@apple.com>
     2
     3        Streamline some string code, focusing on functions that were using substringSharingImpl
     4        https://bugs.webkit.org/show_bug.cgi?id=198898
     5
     6        Reviewed by Daniel Bates.
     7
     8        * css/CSSComputedStyleDeclaration.cpp:
     9        (WebCore::CSSComputedStyleDeclaration::CSSComputedStyleDeclaration): Take a StringView
     10        instead of a String argument for the pseudo-element name. This prevents us from having
     11        to use substringSharingImpl to strip off leading colons.
     12        (WebCore::CSSComputedStyleDeclaration::create): Moved this function in here since it's
     13        no longer being inlined.
     14
     15        * css/CSSComputedStyleDeclaration.h: Moved the create function to no longer be inlined,
     16        since it's better to have the constructor be inlined in the create function instead.
     17        Changed the pseudo-element name argument to be a StringView rather than a String.
     18        Also initialize m_refCount in the class definition.
     19
     20        * css/CSSSelector.cpp:
     21        (WebCore::CSSSelector::parsePseudoElementType): Take a StringView instead of a String.
     22        * css/CSSSelector.h: Updated for the above change.
     23
     24        * css/SelectorPseudoTypeMap.h: Change both parse functions to take StringView. Before
     25        one took a StringImpl and the other used const StringView&, which is not as good as
     26        StringView.
     27
     28        * css/makeSelectorPseudoClassAndCompatibilityElementMap.py: Use StringView, not
     29        const StringView&.
     30
     31        * css/makeSelectorPseudoElementsMap.py: Use StringView rather than StringImpl.
     32
     33        * css/parser/CSSParserImpl.cpp:
     34        (WebCore::CSSParserImpl::parsePageSelector): Use a StringView for the pseudo-element
     35        name. It was already computed as a StringView, but the old code converted it to
     36        an AtomicString.
     37
     38        * css/parser/CSSParserSelector.cpp:
     39        (WebCore::CSSParserSelector::parsePagePseudoSelector): Take a StringView, and
     40        return a std::unique_ptr.
     41        (WebCore::CSSParserSelector::parsePseudoElementSelector): Renamed to not mention
     42        StringView in function name. Take a StringView, not a StringView&. Do the lowercasing
     43        inside this function rather than having it be a caller responsibility. Don't convert
     44        from a StringView to an AtomicString before starting to parse; only do it in the
     45        "unknown/custom" case. Return a std::unique_ptr.
     46        (WebCore::CSSParserSelector::parsePseudoClassSelector): Ditto.
     47        * css/parser/CSSParserSelector.h: Make the three parse functions all take a StringView
     48        and all return a std::unique_ptr. They were already creating objects, but before
     49        callers just had to know to adopt.
     50        * css/parser/CSSSelectorParser.cpp:
     51        (WebCore::CSSSelectorParser::consumePseudo): Updated to use improved parse
     52        functions above.
     53
     54        * page/DOMWindow.cpp:
     55        (WebCore::DOMWindow::getMatchedCSSRules const): Updated to use the new
     56        parsePseudoElementType above and use StringView::substring instead of
     57        String::substringSharingImpl.
     58
     59        * platform/Length.cpp:
     60        (WebCore::newCoordsArray): Local string that is "spacified" can't have any non-Latin-1
     61        characters, so use LChar instead of UChar.
     62
     63        * rendering/RenderText.cpp:
     64        (WebCore::convertNoBreakSpaceToSpace): Renamed for clarity. Also use constexpr
     65        instead of inline since this is a pure function.
     66        (WebCore::capitalize): Tighten up logic a bit.
     67
    1682019-06-29  Simon Fraser  <simon.fraser@apple.com>
    269
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r246490 r246951  
    16591659}
    16601660
    1661 CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(Element& element, bool allowVisitedStyle, const String& pseudoElementName)
     1661CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(Element& element, bool allowVisitedStyle, StringView pseudoElementName)
    16621662    : m_element(element)
    16631663    , m_allowVisitedStyle(allowVisitedStyle)
    1664     , m_refCount(1)
    1665 {
    1666     unsigned nameWithoutColonsStart = pseudoElementName[0] == ':' ? (pseudoElementName[1] == ':' ? 2 : 1) : 0;
    1667     m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoElementType(
    1668     (pseudoElementName.substringSharingImpl(nameWithoutColonsStart))));
     1664{
     1665    StringView name = pseudoElementName;
     1666    if (name.startsWith(':'))
     1667        name = name.substring(1);
     1668    if (name.startsWith(':'))
     1669        name = name.substring(1);
     1670    m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoElementType(name));
    16691671}
    16701672
    16711673CSSComputedStyleDeclaration::~CSSComputedStyleDeclaration() = default;
     1674
     1675Ref<CSSComputedStyleDeclaration> CSSComputedStyleDeclaration::create(Element& element, bool allowVisitedStyle, StringView pseudoElementName)
     1676{
     1677    return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName));
     1678}
    16721679
    16731680void CSSComputedStyleDeclaration::ref()
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h

    r245960 r246951  
    108108    WTF_MAKE_ISO_ALLOCATED_EXPORT(CSSComputedStyleDeclaration, WEBCORE_EXPORT);
    109109public:
    110     static Ref<CSSComputedStyleDeclaration> create(Element& element, bool allowVisitedStyle = false, const String& pseudoElementName = String())
    111     {
    112         return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName));
    113     }
     110    WEBCORE_EXPORT static Ref<CSSComputedStyleDeclaration> create(Element&, bool allowVisitedStyle = false, StringView pseudoElementName = StringView { });
    114111    virtual ~CSSComputedStyleDeclaration();
    115112
     
    120117
    121118private:
    122     WEBCORE_EXPORT CSSComputedStyleDeclaration(Element&, bool allowVisitedStyle, const String&);
     119    CSSComputedStyleDeclaration(Element&, bool allowVisitedStyle, StringView);
    123120
    124121    // CSSOM functions. Don't make these public.
     
    145142    PseudoId m_pseudoElementSpecifier;
    146143    bool m_allowVisitedStyle;
    147     unsigned m_refCount;
     144    unsigned m_refCount { 1 };
    148145};
    149146
  • trunk/Source/WebCore/css/CSSSelector.cpp

    r246490 r246951  
    309309}
    310310
    311 CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(const String& name)
     311CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(StringView name)
    312312{
    313313    if (name.isNull())
    314314        return PseudoElementUnknown;
    315 
    316     PseudoElementType type = parsePseudoElementString(*name.impl());
     315    auto type = parsePseudoElementString(name);
    317316    if (type == PseudoElementUnknown) {
    318317        if (name.startsWith("-webkit-"))
     
    321320    return type;
    322321}
    323 
    324322
    325323bool CSSSelector::operator==(const CSSSelector& other) const
  • trunk/Source/WebCore/css/CSSSelector.h

    r246490 r246951  
    224224        };
    225225
    226         static PseudoElementType parsePseudoElementType(const String&);
     226        static PseudoElementType parsePseudoElementType(StringView);
    227227        static PseudoId pseudoId(PseudoElementType);
    228228
  • trunk/Source/WebCore/css/SelectorPseudoTypeMap.h

    r209666 r246951  
    3535};
    3636
    37 PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(const StringView& pseudoTypeString);
    38 CSSSelector::PseudoElementType parsePseudoElementString(const StringImpl& pseudoTypeString);
     37PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(StringView pseudoTypeString);
     38CSSSelector::PseudoElementType parsePseudoElementString(StringView pseudoTypeString);
    3939
    4040} // namespace WebCore
  • trunk/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py

    r235935 r246951  
    185185
    186186output_file.write("""
    187 PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(const StringView& pseudoTypeString)
     187PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(StringView pseudoTypeString)
    188188{
    189189    const SelectorPseudoClassOrCompatibilityPseudoElementEntry* entry;
  • trunk/Source/WebCore/css/makeSelectorPseudoElementsMap.py

    r235935 r246951  
    186186
    187187output_file.write("""
    188 CSSSelector::PseudoElementType parsePseudoElementString(const StringImpl& pseudoTypeString)
     188CSSSelector::PseudoElementType parsePseudoElementString(StringView pseudoTypeString)
    189189{
    190190    if (pseudoTypeString.is8Bit())
  • trunk/Source/WebCore/css/parser/CSSParserImpl.cpp

    r246490 r246951  
    269269        typeSelector = range.consume().value().toAtomString();
    270270
    271     AtomString pseudo;
     271    StringView pseudo;
    272272    if (range.peek().type() == ColonToken) {
    273273        range.consume();
    274274        if (range.peek().type() != IdentToken)
    275275            return CSSSelectorList();
    276         pseudo = range.consume().value().toAtomString();
     276        pseudo = range.consume().value();
    277277    }
    278278
  • trunk/Source/WebCore/css/parser/CSSParserSelector.cpp

    r246490 r246951  
    3333namespace WebCore {
    3434
    35 CSSParserSelector* CSSParserSelector::parsePagePseudoSelector(const AtomString& pseudoTypeString)
     35std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePagePseudoSelector(StringView pseudoTypeString)
    3636{
    3737    CSSSelector::PagePseudoClassType pseudoType;
     
    4444    else
    4545        return nullptr;
    46    
     46
    4747    auto selector = std::make_unique<CSSParserSelector>();
    4848    selector->m_selector->setMatch(CSSSelector::PagePseudoClass);
    4949    selector->m_selector->setPagePseudoType(pseudoType);
    50     return selector.release();
    51 }
    52 
    53 CSSParserSelector* CSSParserSelector::parsePseudoElementSelectorFromStringView(StringView& pseudoTypeString)
    54 {
    55     AtomString name = pseudoTypeString.toAtomString();
    56    
    57     CSSSelector::PseudoElementType pseudoType = CSSSelector::parsePseudoElementType(name);
     50    return selector;
     51}
     52
     53std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePseudoElementSelector(StringView pseudoTypeString)
     54{
     55    auto pseudoType = CSSSelector::parsePseudoElementType(pseudoTypeString);
    5856    if (pseudoType == CSSSelector::PseudoElementUnknown) {
    5957        // FIXME-NEWPARSER: We can't add "slotted" to the map without breaking the old
     
    6967    selector->m_selector->setMatch(CSSSelector::PseudoElement);
    7068    selector->m_selector->setPseudoElementType(pseudoType);
    71     if (pseudoType == CSSSelector::PseudoElementWebKitCustomLegacyPrefixed) {
    72         ASSERT_WITH_MESSAGE(name == "-webkit-input-placeholder", "-webkit-input-placeholder is the only LegacyPrefix pseudo type.");
    73         if (name == "-webkit-input-placeholder")
     69    AtomString name;
     70    if (pseudoType != CSSSelector::PseudoElementWebKitCustomLegacyPrefixed)
     71        name = pseudoTypeString.convertToASCIILowercase();
     72    else {
     73        ASSERT_WITH_MESSAGE(equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-input-placeholder"), "-webkit-input-placeholder is the only LegacyPrefix pseudo type.");
     74        if (equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-input-placeholder"))
    7475            name = AtomString("placeholder", AtomString::ConstructFromLiteral);
     76        else
     77            name = pseudoTypeString.convertToASCIILowercase();
    7578    }
    7679    selector->m_selector->setValue(name);
    77     return selector.release();
    78 }
    79 
    80 CSSParserSelector* CSSParserSelector::parsePseudoClassSelectorFromStringView(StringView& pseudoTypeString)
    81 {
    82     PseudoClassOrCompatibilityPseudoElement pseudoType = parsePseudoClassAndCompatibilityElementString(pseudoTypeString);
     80    return selector;
     81}
     82
     83std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePseudoClassSelector(StringView pseudoTypeString)
     84{
     85    auto pseudoType = parsePseudoClassAndCompatibilityElementString(pseudoTypeString);
    8386    if (pseudoType.pseudoClass != CSSSelector::PseudoClassUnknown) {
    8487        auto selector = std::make_unique<CSSParserSelector>();
    8588        selector->m_selector->setMatch(CSSSelector::PseudoClass);
    8689        selector->m_selector->setPseudoClassType(pseudoType.pseudoClass);
    87         return selector.release();
     90        return selector;
    8891    }
    8992    if (pseudoType.compatibilityPseudoElement != CSSSelector::PseudoElementUnknown) {
     
    9194        selector->m_selector->setMatch(CSSSelector::PseudoElement);
    9295        selector->m_selector->setPseudoElementType(pseudoType.compatibilityPseudoElement);
    93         AtomString name = pseudoTypeString.toAtomString();
    94         selector->m_selector->setValue(name);
    95         return selector.release();
     96        selector->m_selector->setValue(pseudoTypeString.convertToASCIILowercase());
     97        return selector;
    9698    }
    9799    return nullptr;
  • trunk/Source/WebCore/css/parser/CSSParserSelector.h

    r246490 r246951  
    2222
    2323#include "CSSSelector.h"
    24 #include "CSSValueKeywords.h"
    25 #include <wtf/text/AtomString.h>
    2624#include <wtf/text/AtomStringHash.h>
    27 #include <wtf/text/WTFString.h>
    2825
    2926namespace WebCore {
    30 
    31 class CSSValue;
    32 class QualifiedName;
    3327
    3428enum class CSSParserSelectorCombinator {
     
    4236    WTF_MAKE_FAST_ALLOCATED;
    4337public:
    44     static CSSParserSelector* parsePseudoClassSelectorFromStringView(StringView&);
    45     static CSSParserSelector* parsePseudoElementSelectorFromStringView(StringView&);
    46     static CSSParserSelector* parsePagePseudoSelector(const AtomString&);
    47    
     38    static std::unique_ptr<CSSParserSelector> parsePseudoClassSelector(StringView);
     39    static std::unique_ptr<CSSParserSelector> parsePseudoElementSelector(StringView);
     40    static std::unique_ptr<CSSParserSelector> parsePagePseudoSelector(StringView);
     41
    4842    CSSParserSelector();
    4943    explicit CSSParserSelector(const QualifiedName&);
     
    7569    bool isCustomPseudoElement() const { return m_selector->isCustomPseudoElement(); }
    7670
    77     bool isPseudoElementCueFunction() const
    78     {
    79 #if ENABLE(VIDEO_TRACK)
    80         return m_selector->match() == CSSSelector::PseudoElement && m_selector->pseudoElementType() == CSSSelector::PseudoElementCue;
    81 #else
    82         return false;
    83 #endif
    84     }
     71    bool isPseudoElementCueFunction() const;
    8572
    8673    bool hasShadowDescendant() const;
     
    124111}
    125112
     113inline bool CSSParserSelector::isPseudoElementCueFunction() const
     114{
     115#if ENABLE(VIDEO_TRACK)
     116    return m_selector->match() == CSSSelector::PseudoElement && m_selector->pseudoElementType() == CSSSelector::PseudoElementCue;
     117#else
     118    return false;
     119#endif
    126120}
     121
     122}
  • trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp

    r246490 r246951  
    488488    std::unique_ptr<CSSParserSelector> selector;
    489489   
    490     auto lowercasedValue = token.value().convertToASCIILowercase();
    491     auto value = StringView { lowercasedValue };
    492 
    493490    if (colons == 1) {
    494         selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoClassSelectorFromStringView(value));
     491        selector = CSSParserSelector::parsePseudoClassSelector(token.value());
    495492#if ENABLE(ATTACHMENT_ELEMENT)
    496493        if (!m_context.attachmentEnabled && selector && selector->match() == CSSSelector::PseudoClass && selector->pseudoClassType() == CSSSelector::PseudoClassHasAttachment)
     
    498495#endif
    499496    } else {
    500         selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoElementSelectorFromStringView(value));
     497        selector = CSSParserSelector::parsePseudoElementSelector(token.value());
    501498#if ENABLE(VIDEO_TRACK)
    502499        // Treat the ident version of cue as PseudoElementWebkitCustom.
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r246490 r246951  
    14911491
    14921492    unsigned colonStart = pseudoElement[0] == ':' ? (pseudoElement[1] == ':' ? 2 : 1) : 0;
    1493     CSSSelector::PseudoElementType pseudoType = CSSSelector::parsePseudoElementType(pseudoElement.substringSharingImpl(colonStart));
     1493    auto pseudoType = CSSSelector::parsePseudoElementType(StringView { pseudoElement }.substring(colonStart));
    14941494    if (pseudoType == CSSSelector::PseudoElementUnknown && !pseudoElement.isEmpty())
    14951495        return nullptr;
  • trunk/Source/WebCore/page/EventSource.cpp

    r243887 r246951  
    350350    else if (field == "id") {
    351351        StringView parsedEventId = { &m_receiveBuffer[position], valueLength };
    352         if (!parsedEventId.contains('\0'))
     352        constexpr UChar nullCharacter = '\0';
     353        if (!parsedEventId.contains(nullCharacter))
    353354            m_currentlyParsedEventId = parsedEventId.toString();
    354355    } else if (field == "retry") {
  • trunk/Source/WebCore/platform/Length.cpp

    r243118 r246951  
    9090{
    9191    unsigned length = string.length();
    92     UChar* spacified;
    93     auto str = StringImpl::createUninitialized(length, spacified);
     92    LChar* spacifiedCharacters;
     93    auto str = StringImpl::createUninitialized(length, spacifiedCharacters);
    9494    for (unsigned i = 0; i < length; i++) {
    9595        UChar cc = string[i];
    9696        if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.'))
    97             spacified[i] = ' ';
     97            spacifiedCharacters[i] = ' ';
    9898        else
    99             spacified[i] = cc;
    100     }
    101 
     99            spacifiedCharacters[i] = cc;
     100    }
    102101    str = str->simplifyWhiteSpace();
    103102
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r245543 r246951  
    141141}
    142142
    143 static inline UChar convertNoBreakSpace(UChar character)
     143static constexpr UChar convertNoBreakSpaceToSpace(UChar character)
    144144{
    145145    return character == noBreakSpace ? ' ' : character;
     
    151151
    152152    unsigned length = string.length();
    153 
    154     // Prepend the previous character, and convert NO BREAK SPACE to SPACE so ICU will see a word separator.
    155     Vector<UChar> wordBreakCharacters;
    156     wordBreakCharacters.grow(length + 1);
    157     wordBreakCharacters[0] = convertNoBreakSpace(previousCharacter);
     153    auto& stringImpl = *string.impl();
     154
     155    static_assert(String::MaxLength < std::numeric_limits<unsigned>::max(), "Must be able to add one without overflowing unsigned");
     156
     157    // Replace NO BREAK SPACE with a normal spaces since ICU does not treat it as a word separator.
     158    Vector<UChar> stringWithPrevious(length + 1);
     159    stringWithPrevious[0] = convertNoBreakSpaceToSpace(previousCharacter);
    158160    for (unsigned i = 1; i < length + 1; i++)
    159         wordBreakCharacters[i] = convertNoBreakSpace(string[i - 1]);
    160 
    161     auto* boundary = wordBreakIterator(StringView { wordBreakCharacters.data(), length + 1 });
    162     if (!boundary)
     161        stringWithPrevious[i] = convertNoBreakSpaceToSpace(stringImpl[i - 1]);
     162
     163    auto* breakIterator = wordBreakIterator(StringView { stringWithPrevious.data(), length + 1 });
     164    if (!breakIterator)
    163165        return string;
    164166
     
    166168    result.reserveCapacity(length);
    167169
     170    int32_t startOfWord = ubrk_first(breakIterator);
    168171    int32_t endOfWord;
    169     int32_t startOfWord = ubrk_first(boundary);
    170     for (endOfWord = ubrk_next(boundary); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(boundary)) {
    171         if (startOfWord) // Ignore first char of previous string
    172             result.append(string[startOfWord - 1] == noBreakSpace ? noBreakSpace : u_totitle(wordBreakCharacters[startOfWord]));
     172    for (endOfWord = ubrk_next(breakIterator); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(breakIterator)) {
     173        if (startOfWord) // Do not append the first character, since it's the previous character, not from this string.
     174            result.append(u_totitle(stringImpl[startOfWord - 1]));
    173175        for (int i = startOfWord + 1; i < endOfWord; i++)
    174             result.append(string[i - 1]);
     176            result.append(stringImpl[i - 1]);
    175177    }
    176178
Note: See TracChangeset for help on using the changeset viewer.