WebKit Bugzilla
Attachment 372222 Details for
Bug 198898
: Streamline some string code, focusing on functions that were using substringSharingImpl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198898-20190616085831.patch (text/plain), 31.68 KB, created by
Darin Adler
on 2019-06-16 08:58:32 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Darin Adler
Created:
2019-06-16 08:58:32 PDT
Size:
31.68 KB
patch
obsolete
>Subversion Revision: 246472 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index edf2cefd4c57477779414273caccbe94f929a621..3a6ac688d735075e11cd5115cae9cb9a4a1ef4b7 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,24 @@ >+2019-06-15 Darin Adler <darin@apple.com> >+ >+ Streamline some string code, focusing on functions that were using substringSharingImpl >+ https://bugs.webkit.org/show_bug.cgi?id=198898 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * 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-12 Antoine Quint <graouts@apple.com> > > Show the web page URL when sharing an AR model >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 758776bc6e26eb7b84318bfd3a0d75d43e0d1fd6..c6d4716b57537659d0af70d0811beccfc587429d 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,70 @@ >+2019-06-15 Darin Adler <darin@apple.com> >+ >+ Streamline some string code, focusing on functions that were using substringSharingImpl >+ https://bugs.webkit.org/show_bug.cgi?id=198898 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * 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-15 Simon Fraser <simon.fraser@apple.com> > > Make layerTreeAsText() output a bit less verbose >diff --git a/Source/WTF/wtf/URLHelpers.cpp b/Source/WTF/wtf/URLHelpers.cpp >index f186267f9db38161e39f759a40ac2e26bbd1b6a9..cc94b67907404d89d00596c7d072063a6ef9b16c 100644 >--- a/Source/WTF/wtf/URLHelpers.cpp >+++ b/Source/WTF/wtf/URLHelpers.cpp >@@ -663,7 +663,7 @@ static void applyHostNameFunctionToURLString(const String& string, const Optiona > 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 "?". >@@ -674,39 +674,23 @@ static void applyHostNameFunctionToURLString(const String& string, const Optiona > 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 (invalidSchemeCharacter != notFound) >+ // Check that all characters before the :// are valid scheme characters. >+ if (StringView { string }.left(separatorIndex).contains([](UChar character) { >+ return !(isASCIIAlphanumeric(character) || character == '+' || character == '-' || character == '.'); >+ })) > 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); > } > >diff --git a/Source/WTF/wtf/text/StringView.cpp b/Source/WTF/wtf/text/StringView.cpp >index 78b5e2f5ad3f8fb2f746d23ddf28d0caad811ea3..31251672aaf322321ec9d9487060dfb58e16c73e 100644 >--- a/Source/WTF/wtf/text/StringView.cpp >+++ b/Source/WTF/wtf/text/StringView.cpp >@@ -58,6 +58,11 @@ size_t StringView::findIgnoringASCIICase(const StringView& matchString, unsigned > 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); >diff --git a/Source/WTF/wtf/text/StringView.h b/Source/WTF/wtf/text/StringView.h >index 64102bfaa805cb0c638f548612e469018a1b2687..9522f815769cd9d3bd783d3d76660b160e4f5ce9 100644 >--- a/Source/WTF/wtf/text/StringView.h >+++ b/Source/WTF/wtf/text/StringView.h >@@ -96,7 +96,7 @@ public: > RefPtr<AtomicStringImpl> toExistingAtomicString() 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 @@ public: > 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 @@ public: > > 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 @@ public: > 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 @@ private: > 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 @@ private: > bool m_is8Bit { true }; > > #if CHECK_STRINGVIEW_LIFETIME >- void adoptUnderlyingString(UnderlyingString*); > UnderlyingString* m_underlyingString { nullptr }; > #endif > }; >@@ -468,6 +470,11 @@ inline bool StringView::contains(UChar character) const > return find(character) != notFound; > } > >+inline bool StringView::contains(CodeUnitMatchFunction function) const >+{ >+ return find(function) != notFound; >+} >+ > inline void StringView::getCharactersWithUpconvert(LChar* destination) const > { > ASSERT(is8Bit()); >diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp >index 4bc064f776a25709dfa830f60f21adebcd70f924..fefaee0b4bff44fb6a00f5ce6024e9ca712f20c6 100644 >--- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp >+++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp >@@ -1658,18 +1658,25 @@ ComputedStyleExtractor::ComputedStyleExtractor(Element* element, bool allowVisit > { > } > >-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; >diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.h b/Source/WebCore/css/CSSComputedStyleDeclaration.h >index a78456494ab222d0496e62951a17caada23f471a..e6aa55ae5c7ae0528e6bfb1a307ce1d089554037 100644 >--- a/Source/WebCore/css/CSSComputedStyleDeclaration.h >+++ b/Source/WebCore/css/CSSComputedStyleDeclaration.h >@@ -107,10 +107,7 @@ private: > 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 @@ public: > 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 @@ private: > mutable Ref<Element> m_element; > PseudoId m_pseudoElementSpecifier; > bool m_allowVisitedStyle; >- unsigned m_refCount; >+ unsigned m_refCount { 1 }; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/css/CSSSelector.cpp b/Source/WebCore/css/CSSSelector.cpp >index f365a85e74db82657fbab888c0635541c0b6006f..62630d4a1ba82c4af07934ae34f214bf8be203f1 100644 >--- a/Source/WebCore/css/CSSSelector.cpp >+++ b/Source/WebCore/css/CSSSelector.cpp >@@ -308,12 +308,11 @@ PseudoId CSSSelector::pseudoId(PseudoElementType type) > 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 @@ CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(const String& > return type; > } > >- > bool CSSSelector::operator==(const CSSSelector& other) const > { > const CSSSelector* sel1 = this; >diff --git a/Source/WebCore/css/CSSSelector.h b/Source/WebCore/css/CSSSelector.h >index 544cc2cd58abea8044435b16485c23858853ea55..b7bd423ef39549b0c768d7e9b31cca790e3c19c3 100644 >--- a/Source/WebCore/css/CSSSelector.h >+++ b/Source/WebCore/css/CSSSelector.h >@@ -223,7 +223,7 @@ namespace WebCore { > 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 >diff --git a/Source/WebCore/css/SelectorPseudoTypeMap.h b/Source/WebCore/css/SelectorPseudoTypeMap.h >index 7dc1b795913e9aa24bcc7a751f2b3a0257fd2066..c5f73ac5648bbcecf085b765dbfa8de9b185d192 100644 >--- a/Source/WebCore/css/SelectorPseudoTypeMap.h >+++ b/Source/WebCore/css/SelectorPseudoTypeMap.h >@@ -34,7 +34,7 @@ struct PseudoClassOrCompatibilityPseudoElement { > 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 >diff --git a/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py b/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py >index 32da590fa36c5b7ab54ec93d45a045aef625cd79..bb17b8b5066aed4769faffebed4b3b4f2128c54a 100644 >--- a/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py >+++ b/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py >@@ -184,7 +184,7 @@ static inline const SelectorPseudoClassOrCompatibilityPseudoElementEntry* parseP > """ % longest_keyword) > > output_file.write(""" >-PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(const StringView& pseudoTypeString) >+PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(StringView pseudoTypeString) > { > const SelectorPseudoClassOrCompatibilityPseudoElementEntry* entry; > if (pseudoTypeString.is8Bit()) >diff --git a/Source/WebCore/css/makeSelectorPseudoElementsMap.py b/Source/WebCore/css/makeSelectorPseudoElementsMap.py >index e993fdd2221caa284da52ec0722dc4edd362f057..3d442e1b9e30131b64b6211f1e1516dcfbafc824 100644 >--- a/Source/WebCore/css/makeSelectorPseudoElementsMap.py >+++ b/Source/WebCore/css/makeSelectorPseudoElementsMap.py >@@ -185,7 +185,7 @@ static inline CSSSelector::PseudoElementType parsePseudoElementString(const UCha > """ % 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()); >diff --git a/Source/WebCore/css/parser/CSSParserImpl.cpp b/Source/WebCore/css/parser/CSSParserImpl.cpp >index 4110cd4f554e26767eee69aee48fec38d8d8a61a..94a322e1985181894315b288e06b6dae778241dd 100644 >--- a/Source/WebCore/css/parser/CSSParserImpl.cpp >+++ b/Source/WebCore/css/parser/CSSParserImpl.cpp >@@ -268,12 +268,12 @@ CSSSelectorList CSSParserImpl::parsePageSelector(CSSParserTokenRange range, Styl > if (range.peek().type() == IdentToken) > typeSelector = range.consume().value().toAtomicString(); > >- AtomicString pseudo; >+ StringView pseudo; > if (range.peek().type() == ColonToken) { > range.consume(); > if (range.peek().type() != IdentToken) > return CSSSelectorList(); >- pseudo = range.consume().value().toAtomicString(); >+ pseudo = range.consume().value(); > } > > range.consumeWhitespace(); >diff --git a/Source/WebCore/css/parser/CSSParserSelector.cpp b/Source/WebCore/css/parser/CSSParserSelector.cpp >index 1af424eac9ff3b70f52fe5e6b32417419c11b7a3..2395a0ecbec7f738f3316f79f591c0a1c5535094 100644 >--- a/Source/WebCore/css/parser/CSSParserSelector.cpp >+++ b/Source/WebCore/css/parser/CSSParserSelector.cpp >@@ -32,7 +32,7 @@ > > namespace WebCore { > >-CSSParserSelector* CSSParserSelector::parsePagePseudoSelector(const AtomicString& pseudoTypeString) >+std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePagePseudoSelector(StringView pseudoTypeString) > { > CSSSelector::PagePseudoClassType pseudoType; > if (equalLettersIgnoringASCIICase(pseudoTypeString, "first")) >@@ -43,18 +43,16 @@ CSSParserSelector* CSSParserSelector::parsePagePseudoSelector(const AtomicString > 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) > { >- AtomicString name = pseudoTypeString.toAtomicString(); >- >- 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,32 @@ CSSParserSelector* CSSParserSelector::parsePseudoElementSelectorFromStringView(S > auto selector = std::make_unique<CSSParserSelector>(); > selector->m_selector->setMatch(CSSSelector::PseudoElement); > selector->m_selector->setPseudoElementType(pseudoType); >- if (pseudoType == CSSSelector::PseudoElementWebKitCustomLegacyPrefixed) { >+ AtomicString name; >+ if (pseudoType != CSSSelector::PseudoElementWebKitCustomLegacyPrefixed) >+ name = pseudoTypeString.convertToASCIILowercase(); >+ else { > ASSERT_WITH_MESSAGE(name == "-webkit-input-placeholder", "-webkit-input-placeholder is the only LegacyPrefix pseudo type."); >- if (name == "-webkit-input-placeholder") >- name = AtomicString("placeholder", AtomicString::ConstructFromLiteral); >+ name = AtomicString("placeholder", AtomicString::ConstructFromLiteral); > } > 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); >- AtomicString name = pseudoTypeString.toAtomicString(); >- selector->m_selector->setValue(name); >- return selector.release(); >+ selector->m_selector->setValue(pseudoTypeString.convertToASCIILowercase()); >+ return selector; > } > return nullptr; > } >diff --git a/Source/WebCore/css/parser/CSSParserSelector.h b/Source/WebCore/css/parser/CSSParserSelector.h >index 860fda1c1112ab99a3283e3a23c6417cea5727ce..9600614412803fce40c40703544c28ed4e647389 100644 >--- a/Source/WebCore/css/parser/CSSParserSelector.h >+++ b/Source/WebCore/css/parser/CSSParserSelector.h >@@ -41,9 +41,9 @@ enum class CSSParserSelectorCombinator { > class CSSParserSelector { > WTF_MAKE_FAST_ALLOCATED; > public: >- static CSSParserSelector* parsePseudoClassSelectorFromStringView(StringView&); >- static CSSParserSelector* parsePseudoElementSelectorFromStringView(StringView&); >- static CSSParserSelector* parsePagePseudoSelector(const AtomicString&); >+ 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&); >diff --git a/Source/WebCore/css/parser/CSSSelectorParser.cpp b/Source/WebCore/css/parser/CSSSelectorParser.cpp >index 98d75c5c9b91f3f94dee2add8f70caa2d2e462bf..ca9de33c3046b79363b56e109a83d1af00634901 100644 >--- a/Source/WebCore/css/parser/CSSSelectorParser.cpp >+++ b/Source/WebCore/css/parser/CSSSelectorParser.cpp >@@ -487,17 +487,14 @@ std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumePseudo(CSSParserTok > > 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) >diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp >index cfcbb1d821ace8cebfbb3e28f3af51f4fcc7d516..3adcae6ac8275ed5e68ed3297ec88edaa0dcd009 100644 >--- a/Source/WebCore/page/DOMWindow.cpp >+++ b/Source/WebCore/page/DOMWindow.cpp >@@ -1490,7 +1490,7 @@ RefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* element, const String > 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; > >diff --git a/Source/WebCore/platform/Length.cpp b/Source/WebCore/platform/Length.cpp >index ce9c9458dc20f9e726ba439eaeab7c206290c3f2..4ff9804eaec1306b268a245f2771a112e28d2a1e 100644 >--- a/Source/WebCore/platform/Length.cpp >+++ b/Source/WebCore/platform/Length.cpp >@@ -89,16 +89,15 @@ static unsigned countCharacter(StringImpl& string, UChar character) > 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; >diff --git a/Source/WebCore/rendering/RenderText.cpp b/Source/WebCore/rendering/RenderText.cpp >index 84484e8ec8f48585ea78881a891729f5309c23b3..24d21f62157915b1c0f57c24dab8792e4782a7f5 100644 >--- a/Source/WebCore/rendering/RenderText.cpp >+++ b/Source/WebCore/rendering/RenderText.cpp >@@ -140,7 +140,7 @@ static HashMap<const RenderText*, WeakPtr<RenderInline>>& inlineWrapperForDispla > return map; > } > >-static inline UChar convertNoBreakSpace(UChar character) >+static constexpr UChar convertNoBreakSpaceToSpace(UChar character) > { > return character == noBreakSpace ? ' ' : character; > } >@@ -150,28 +150,30 @@ String capitalize(const String& string, UChar previousCharacter) > // 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();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198898
:
372222
|
372224
|
372688