Skip to content

Commit 5917cb1

Browse files
Reduce WTF::String operations that do unnecessary Unicode operations instead of ASCII
https://bugs.webkit.org/show_bug.cgi?id=179907 Reviewed by Sam Weinig. Source/JavaScriptCore: * inspector/agents/InspectorDebuggerAgent.cpp: (Inspector::matches): Removed explicit TextCaseSensitive because RegularExpression now defaults to that. * runtime/StringPrototype.cpp: (JSC::stringIncludesImpl): Use String::find since there is no overload of String::contains that takes a start offset now that we removed the one that took a caseSensitive boolean. We can add one later if we like, but this should do for now. * yarr/RegularExpression.h: Moved the TextCaseSensitivity enumeration here from the StringImpl.h header because it is only used here. Source/WebCore: * Modules/plugins/YouTubePluginReplacement.cpp: (WebCore::hasCaseInsensitivePrefix): Deleted. (WebCore::processAndCreateYouTubeURL): Use startsWithLettersIgnoringASCIICase. * Modules/websockets/WebSocketHandshake.cpp: (WebCore::WebSocketHandshake::readHTTPHeaders): Use isAllASCII. * accessibility/atk/AccessibilityObjectAtk.cpp: (WebCore::AccessibilityObject::getLengthForTextRange const): Use text().length(). * accessibility/AXObjectCache.cpp: (WebCore::AXObjectCache::traverseToOffsetInRange): Use isHTMLSpace instead of isSpaceOrNewline since the code is trying to skip collapsible HTML spaces, not arbitrary Unicode whitespace. * accessibility/AccessibilityList.cpp: (WebCore::AccessibilityList::childHasPseudoVisibleListItemMarkers): Use isAllSpecialCharacters<isHTMLSpace> for the same reason as above. * accessibility/AccessibilityNodeObject.cpp: (WebCore::AccessibilityNodeObject::isSearchField const): Use containsIgnoringASCIICase. * accessibility/AccessibilityObject.cpp: (WebCore::AccessibilityObject::accessibilityObjectContainsText const): Use new findPlainText function exported from TextIterator so this can share the same search matching logic used to find text in webpages. (WebCore::AccessibilityObject::selectText): Use capitalize and its return value rather than makeCapitalize modifying a string in place. * accessibility/AccessibilityRenderObject.cpp: (WebCore::objectInclusionFromAltText): Use isAllSpecialCharacters<isHTMLSpace> for the same reason as above. (WebCore::AccessibilityRenderObject::computeAccessibilityIsIgnored const): Ditto. * bindings/js/JSDOMConvertStrings.cpp: (WebCore::stringToByteString): Use isAllLatin1. * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::containsOnlyASCIIWithNoUppercase): Use StringView::codeUnits instead of String::at. * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad const): Use isAllASCII. * contentextensions/URLFilterParser.cpp: (WebCore::ContentExtensions::URLFilterParser::addPattern): Ditto. * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::isSupportedFormat const): Use protocolIs and endsWithIgnoringASCIICase. * css/DOMCSSNamespace.cpp: (WebCore::valueWithoutImportant): Use endsWithIgnoringASCIICase. * css/parser/CSSPropertyParser.cpp: (WebCore::parseGridTemplateAreasRow): Use isAllSpecialCharacters<isCSSSpace>, for the preflight, which matches what the actual parsing code uses. * dom/CharacterData.cpp: (WebCore::CharacterData::containsOnlyWhitespace const): Deleted. Callers can efficiently get at the data and do this kind of check on the data directly. * dom/CharacterData.h: Updated for the above. * dom/DataTransfer.cpp: (WebCore::normalizeType): Use startsWith since the string is already converted to ASCII lowercase. * dom/Position.cpp: (WebCore::Position::leadingWhitespacePosition const): Use isHTMLSpace since since the code is trying to check for collapsible HTML spaces, not general Unicode spaces. Other call sites of isSpaceOrNewline need to be checked for this, but I did not fix them all at this time. (WebCore::Position::trailingWhitespacePosition const): Ditto. * editing/Editor.cpp: (WebCore::Editor::editorUIUpdateTimerFired): Use noBreakSpace. * editing/FrameSelection.cpp: (WebCore::FrameSelection::debugRenderer const): Use text().length() instead of textLength. (WebCore::FrameSelection::selectionAtWordStart const): Use noBreakSpace. (WebCore::FrameSelection::wordSelectionContainingCaretSelection): Ditto. (WebCore::FrameSelection::actualSelectionAtSentenceStart const): Ditto. * editing/TextIterator.cpp: (WebCore::textNodeOffsetInFlow): Use text().length(). (WebCore::TextIterator::handleTextNode): Ditto. (WebCore::collapsedSpaceLength): Updated since RenderText::text now returns a reference rather than a pointer. (WebCore::findPlainText): Added. Uses SearchBuffer to search for one string within another. Exported so accessibility code can do this operation. * editing/TextIterator.h: Updated for the above. * editing/TypingCommand.cpp: (WebCore::TypingCommand::markMisspellingsAfterTyping): Use noBreakSpace. * editing/VisibleUnits.cpp: (WebCore::findStartOfParagraph): Updated since RenderText::text now returns a reference. (WebCore::findEndOfParagraph): Ditto. * editing/cocoa/HTMLConverter.mm: (HTMLConverter::_processText): Use String::characterAt instead of String::at. Use capitalize instead of makeCapitalized. * editing/cocoa/WebContentReaderCocoa.mm: (WebCore::stripMicrosoftPrefix): Use findIgnoringASCIICase. * html/Autofill.cpp: (WebCore::AutofillData::createFromHTMLFormControlElement): Use startsWithLettersIgnoringASCIICase. * html/BaseTextInputType.cpp: (WebCore::BaseTextInputType::patternMismatch const): Removed explicit TextCaseSensitive since it now is the default, and needed to touch this anyway because the enumeration is now in a different namespace. * html/EmailInputType.cpp: (WebCore::isValidEmailAddress): Updated to use JSC::Yarr::TextCaseInsensitive. * html/HTMLObjectElement.cpp: (WebCore::HTMLObjectElement::hasFallbackContent const): Use isAllSpecialCharacters<isHTMLSpace>. (WebCore::HTMLObjectElement::shouldAllowQuickTimeClassIdQuirk): Use startsWithLettersIgnoringASCIICase. (WebCore::HTMLObjectElement::hasValidClassId): Use protocolIs. (WebCore::preventsParentObjectFromExposure): Use isAllSpecialCharacters<isHTMLSpace>. * html/parser/HTMLConstructionSite.cpp: (WebCore::HTMLConstructionSite::setCompatibilityModeFromDoctype): Use startsWithLettersIgnoringASCIICase. * html/parser/HTMLMetaCharsetParser.cpp: (WebCore::extractCharset): Use findIgnoringASCIICase. * html/parser/XSSAuditor.cpp: (WebCore::XSSAuditor::isContainedInRequest): Use containsIgnoringASCIICase. * html/track/WebVTTParser.cpp: (WebCore::WebVTTParser::hasRequiredFileIdentifier): Don't pass the length to the String::startsWith function. There has never been a version of that function that takes the length, there is no need to pass the length since the function handles null-terminated strings like the one here, and in the past the length has been getting converted to a boolean making the comparison be case sensitive. Removing the argument entirely leaves it case sensitive. * inspector/InspectorNodeFinder.cpp: (WebCore::InspectorNodeFinder::matchesElement): Use startsWithIgnoringASCIICase and endsWithIgnoringASCIICase. * inspector/InspectorStyleSheet.cpp: (WebCore::selectorsFromSource): Use JSC::Yarr::TextCaseSensitive. * inspector/agents/InspectorDOMAgent.cpp: (WebCore::containsOnlyHTMLWhitespace): Made this a non-member function and reimplemented using isAllSpecialCharacters<isHTMLSpace>(). (WebCore::InspectorDOMAgent::innerFirstChild): Use containsOnlyHTMLWhitespace. (WebCore::InspectorDOMAgent::innerNextSibling): Ditto. (WebCore::InspectorDOMAgent::innerPreviousSibling): Ditto. (WebCore::InspectorDOMAgent::innerChildNodeCount): Ditto. (WebCore::InspectorDOMAgent::didInsertDOMNode): Ditto. (WebCore::InspectorDOMAgent::didRemoveDOMNode): Ditto. * inspector/agents/InspectorDOMAgent.h: Updated for above change. * loader/appcache/ApplicationCacheStorage.cpp: (WebCore::ApplicationCacheStorage::shouldStoreResourceAsFlatFile): Use startsWithLettersIgnoringASCIICase. * page/Base64Utilities.cpp: (WebCore::Base64Utilities::btoa): Use isAllLatin1. * page/Frame.cpp: (WebCore::createRegExpForLabels): Removed TextCaseSensitive argument since that is now the default and also used JSC::Yarr::TextCaseInsensitive. (WebCore::matchLabelsAgainstString): More of the same. * page/FrameView.cpp: (WebCore::countRenderedCharactersInRenderObjectWithThreshold): Use text().length(). * page/SecurityOrigin.cpp: (WebCore::isFeedWithNestedProtocolInHTTPFamily): Use startsWithLettersIgnoringASCIICase. * page/UserContentURLPattern.cpp: (WebCore::UserContentURLPattern::matchesHost const): Use endsWithIgnoringASCIICase. * page/csp/ContentSecurityPolicySource.cpp: (WebCore::ContentSecurityPolicySource::hostMatches const): Ditto. * page/csp/ContentSecurityPolicySourceList.cpp: (WebCore::ContentSecurityPolicySourceList::parseNonceSource): Use startsWithIgnoringASCIICase. * page/ios/FrameIOS.mm: (WebCore::Frame::wordsInCurrentParagraph const): Use noBreakSpace. * platform/ContentType.cpp: (WebCore::ContentType::parameter const): Use findIgnoringASCIICase. * platform/MIMETypeRegistry.cpp: (WebCore::MIMETypeRegistry::isSupportedFontMIMEType): Use startsWithLettersIgnoringASCIICase. (WebCore::MIMETypeRegistry::isSupportedJSONMIMEType): Use mimeType.endsWithIgnoringASCIICase. (WebCore::MIMETypeRegistry::isTextMIMEType): Use startsWithLettersIgnoringASCIICase. (WebCore::MIMETypeRegistry::isXMLMIMEType): Use endsWithIgnoringASCIICase. (WebCore::MIMETypeRegistry::isJavaAppletMIMEType): Use startsWithLettersIgnoringASCIICase. (WebCore::MIMETypeRegistry::canShowMIMEType): Ditto. * platform/URL.cpp: (WebCore::isAllASCII): Renamed from containsOnlyASCII. (WebCore::appendEncodedHostname): Use isAllASCII. * platform/URLParser.cpp: (WebCore::containsOnlyASCII): Deleted. (WebCore::URLParser::domainToASCII): Use StringImpl::isAllASCII. Changed to take StringImpl& to guarantee we won't keep doing null checks since the caller already checks for null. (WebCore::URLParser::parseHostAndPort): Pass StringImpl&. * platform/URLParser.h: Updated for above. * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::supportsType): Use endsWithIgnoringASCIICase and startsWithLettersIgnoringASCIICase. * platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm: (WebCore::validKeySystemRE): Use JSC::Yarr::TextCaseInsensitive. * platform/graphics/cocoa/FontCacheCoreText.cpp: (WebCore::FontCache::similarFont): Use containsIgnoringASCIICase for the Geeza font special cases. * platform/graphics/mac/MediaPlayerPrivateQTKit.mm: (WebCore::shouldRejectMIMEType): Use startsWithLettersIgnoringASCIICase. * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::GraphicsContext3D::getUnmangledInfoLog): Removed TextCaseSensitive since it now is the default. * platform/mac/PublicSuffixMac.mm: (WebCore::topPrivatelyControlledDomain): Use isAllASCII. * platform/mac/SSLKeyGeneratorMac.mm: (WebCore::signedPublicKeyAndChallengeString): Use isAllASCII. * platform/mac/StringUtilities.mm: (WebCore::stringMatchesWildcardString): Use JSC::Yarr::TextCaseInsensitive. * platform/mediastream/RealtimeMediaSourceCenter.cpp: (WebCore::addStringToSHA1): Use isAllASCII. * platform/network/CacheValidation.cpp: (WebCore::parseCacheControlDirectives): Use containsIgnoringASCIICase. * platform/network/HTTPParsers.cpp: (WebCore::parseHTTPRefresh): Use findIgnoringASCIICase. (WebCore::findCharsetInMediaType): Ditto. (WebCore::parseRange): Use startsWithLettersIgnoringASCIICase. * platform/network/curl/AuthenticationChallengeCurl.cpp: (WebCore::AuthenticationChallenge::protectionSpaceFromHandle): Use findIgnoringASCIICase. * platform/network/curl/MultipartHandle.cpp: (WebCore::MultipartHandle::extractBoundary): Ditto. * platform/network/curl/ResourceHandleCurlDelegate.cpp: (WebCore::ResourceHandleCurlDelegate::handleDataURL): Use endsWithIgnoringASCIICase. * platform/network/curl/ResourceResponseCurl.cpp: (WebCore::ResourceResponse::isAppendableHeader): Use startsWithLettersIgnoringASCIICase. (WebCore::ResourceResponse::appendHTTPHeaderField): Ditto. * platform/win/ClipboardUtilitiesWin.cpp: (WebCore::extractMarkupFromCFHTML): Use findIgnoringASCIICase. (WebCore::fragmentFromCFHTML): Ditto. * rendering/BidiRun.cpp: (WebCore::BidiRun::BidiRun): Use text().length(). * rendering/HitTestResult.cpp: (WebCore::HitTestResult::absolutePDFURL const): Use endsWithIgnoringASCIICase. * rendering/InlineFlowBox.cpp: (WebCore::InlineFlowBox::placeBoxRangeInInlineDirection): Use text().length(). * rendering/InlineIterator.h: (WebCore::InlineIterator::fastIncrementInTextNode): Ditto. (WebCore::InlineIterator::increment): Dtto. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::isLineBreak const): Updated since RenderText::text now returns a StringImpl&. (WebCore::InlineTextBox::selectionStartEnd const): Use text().length(). (WebCore::InlineTextBox::text const): Updated since RenderText::text now returns a StringImpl&. * rendering/RenderBlock.cpp: (WebCore::RenderBlock::constructTextRun): Use text().length(). * rendering/RenderBlockFlow.cpp: (WebCore::isVisibleRenderText): Use isAllSpecialCharacters<isHTMLSpace>(). (WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths const): Use the new trimmedPreferredWidths that returns a structure instead of the old one with lots of arguments. Also use text().length(). * rendering/RenderBlockLineLayout.cpp: (WebCore::endsWithHTMLSpaces): Renamed and changed to use isHTMLSpace instead of isASCIISpace. (WebCore::reachedEndOfTextRenderer): Use endsWithHTMLSpaces. (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): Updated for hcanges to RenderText. (WebCore::RenderBlockFlow::handleTrailingSpaces): Ditto. (WebCore::RenderBlockFlow::determineStartPosition): Ditto. * rendering/RenderCombineText.cpp: (WebCore::RenderCombineText::combineTextIfNeeded): Use isAllSpecialCharacters<isHTMLSpace>. * rendering/RenderLayer.cpp: (WebCore::RenderLayer::calculateClipRects const): Ditto. * rendering/RenderListBox.cpp: (WebCore::bolder): Added. Helper function. (WebCore::RenderListBox::updateFromElement): Rewrote to only compute the bolder font once rather than for every item. (WebCore::RenderListBox::paintItemForeground): Updated for change to applyTextTransform. * rendering/RenderMenuList.cpp: (WebCore::RenderMenuList::adjustInnerStyle): Updated for change to RenderText::text. (RenderMenuList::updateOptionsWidth): Updated for change to applyTextTransform. (RenderMenuList::itemText const): Ditto. * rendering/RenderText.cpp: (WebCore::capitalize): Renamed from makeCapitalized. Changed to take and return a String instead of taking a String*. (WebCore::RenderText::RenderText): Use isAllASCII. Also moved initialization of most non-bitfield members to the class definition. (WebCore::RenderText::positionForPoint): Use text(). (WebCore::RenderText::widthFromCache const): Ditto. (WebCore::RenderText::hangablePunctuationStartWidth const): Ditto. (WebCore::RenderText::hangablePunctuationEndWidth const): Ditto. (WebCore::RenderText::isHangableStopOrComma): Ditto. (WebCore::RenderText::firstCharacterIndexStrippingSpaces const): Ditto. (WebCore::RenderText::lastCharacterIndexStrippingSpaces const): Ditto. (WebCore::RenderText::trimmedPreferredWidths): Changed to return values in a structure instead of taking lots of arguments. (WebCore::RenderText::computePreferredLogicalWidths): Updated to use the text() function. (WebCore::isAllCollapsibleWhitespace): Added. (WebCore::RenderText::isAllCollapsibleWhitespace const): Updated to use a tighter loop. (WebCore::isAllPossiblyCollapsibleWhitespace): Added. (WebCore::RenderText::containsOnlyHTMLWhitespace const): Updated to use a tighter loop. Renamed from containsOnlyWhitespace. (WebCore::RenderText::setTextWithOffset): Updated to use text(). (WebCore::isInlineFlowOrEmptyText): Rewrote to be easier to read. (WebCore::RenderText::previousCharacter const): Got rid of unneeded null check and simplified. (WebCore::applyTextTransform): Changed to return a String rather than modifying one that is passed in. (WebCore::RenderText::setRenderedText): Updated use of applyTextTransform. (WebCore::RenderText::secureText): More of the same. (WebCore::RenderText::computeCanUseSimplifiedTextMeasuring const): Ditto. (WebCore::RenderText::textWithoutConvertingBackslashToYenSymbol const): Ditto. (WebCore::RenderText::width const): Ditto. (WebCore::RenderText::collectSelectionRectsForLineBoxes): Ditto. (WebCore::RenderText::previousOffset const): Ditto. (WebCore::RenderText::previousOffsetForBackwardDeletion const): Ditto. (WebCore::RenderText::nextOffset const): Ditto. (WebCore::RenderText::computeCanUseSimpleFontCodePath const): Ditto. (WebCore::RenderText::stringView const): Ditto. * rendering/RenderText.h: Made some more members private and final. Updated for above, including adding the Widths structure. Got rid of the textLength function, which existed as a workaround before we could mark a function like length final. Made the text function return a StringImpl&, which is good since the m_text string is never null, and so callers end up using StringImpl directly and saving null checks. Removed functions that are not needed, including is8Bit, characters8, characters16, uncheckedCharacterAt, operator[], and isAllASCII. * rendering/RenderTextFragment.cpp: (WebCore::RenderTextFragment::setText): Use text().length(). * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::caretMaxOffset const): Ditto. (WebCore::RenderTextLineBoxes::positionForPoint const): Ditto. (WebCore::RenderTextLineBoxes::setSelectionState): Ditto. (WebCore::RenderTextLineBoxes::absoluteQuads const): Ditto. * rendering/SimpleLineLayout.cpp: (WebCore::SimpleLineLayout::canUseForFontAndText): Ditto. * rendering/SimpleLineLayoutCoverage.cpp: (WebCore::SimpleLineLayout::textLengthForSubtree): Ditto. (WebCore::SimpleLineLayout::collectNonEmptyLeafRenderBlockFlows): Ditto. * rendering/SimpleLineLayoutFlowContents.cpp: (WebCore::SimpleLineLayout::initializeSegments): Ditto. * rendering/SimpleLineLayoutFunctions.cpp: (WebCore::SimpleLineLayout::textOffsetForPoint): Ditto. * rendering/SimpleLineLayoutFunctions.h: (WebCore::SimpleLineLayout::findCaretMaximumOffset): Ditto. * rendering/line/BreakingContext.h: (WebCore::shouldAddBorderPaddingMargin): Ditto. (WebCore::shouldSkipWhitespaceAfterStartObject): Ditto. (WebCore::iteratorIsBeyondEndOfRenderCombineText): Ditto. (WebCore::textWidth): Ditto. (WebCore::BreakingContext::handleText): Ditto. (WebCore::BreakingContext::optimalLineBreakLocationForTrailingWord): Ditto. * rendering/line/TrailingObjects.cpp: (WebCore::TrailingObjects::updateWhitespaceCollapsingTransitionsForTrailingBoxes): Ditto. * rendering/mathml/RenderMathMLFenced.cpp: (WebCore::RenderMathMLFenced::updateFromElement): Removed stray use of "unsigned int". * rendering/svg/RenderSVGInlineText.cpp: (WebCore::RenderSVGInlineText::characterStartsNewTextChunk const): Use text().length(). (WebCore::RenderSVGInlineText::positionForPoint): Ditto. * rendering/svg/SVGTextLayoutAttributesBuilder.cpp: (WebCore::processRenderSVGInlineText): Ditto. * rendering/svg/SVGTextLayoutEngine.cpp: (WebCore::SVGTextLayoutEngine::currentLogicalCharacterAttributes): Ditto. * rendering/svg/SVGTextQuery.cpp: (WebCore::SVGTextQuery::modifyStartEndPositionsRespectingLigatures const): Ditto. * style/RenderTreeUpdater.cpp: (WebCore::RenderTreeUpdater::updateRenderTree): Use isAllSpecialCharacters<isHTMLSpace>. (WebCore::RenderTreeUpdater::textRendererIsNeeded): Ditto. * svg/SVGTests.cpp: (WebCore::SVGTests::hasFeatureForLegacyBindings): Use startsWithLettersIgnoringASCIICase. * xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::shouldAllowExternalLoad): Ditto. Source/WebKit: * NetworkProcess/cache/NetworkCache.cpp: (WebKit::NetworkCache::isMediaMIMEType): Use startsWithLettersIgnoringASCIICase. * NetworkProcess/cache/NetworkCacheKey.cpp: (WebKit::NetworkCache::hashString): Use isAllASCII.. * UIProcess/API/C/WKWebsitePolicies.cpp: (WKWebsitePoliciesSetCustomHeaderFields): Use startsWithLettersIgnoringASCIICase.. * UIProcess/API/Cocoa/_WKWebsitePolicies.mm: (-[_WKWebsitePolicies setCustomHeaderFields:]): Ditto. * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::savePDFToFileInDownloadsFolder): Use endsWithIgnoringASCIICase. * UIProcess/WebPreferences.cpp: (WebKit::WebPreferences::WebPreferences): Initialize m_identifier explicitly. Somehow changing the String default constructor to be "= default" led to a warning that we otherwise did not get about not initializing m_identifier. Arguably a compiler bug, but legitimately strange that the copy constructor does not copy m_identifier and so nice to be explicit about it, I guess. * UIProcess/mac/WebPageProxyMac.mm: (WebKit::WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw): Use endsWithIgnoringASCIICase. (WebKit::WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication): Ditto. * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::createPlugin): Ditto. * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::platformEditorState const): Use isAllSpecialCharacters<isHTMLSpace>. Source/WebKitLegacy/mac: * History/BinaryPropertyList.cpp: (BinaryPropertyListPlan::writeStringObject): Use isAllASCII. (BinaryPropertyListSerializer::appendStringObject): Ditto. * WebView/WebHTMLRepresentation.mm: (regExpForLabels): Removed TextCaseSensitive since it is now the default. (matchLabelsAgainstString): Use JSC::Yarr::TextCaseInsensitive. Source/WebKitLegacy/win: * Plugins/PluginDatabaseWin.cpp: (WebCore::PluginDatabase::getPluginPathsInDirectories const): Use startsWithLettersIgnoringASCIICase and endsWithIgnoringASCIICase. * WebDownloadCFNet.cpp: (WebDownload::initToResumeWithBundle): Use endsWithIgnoringASCIICase. * WebView.cpp: (WebView::markAllMatchesForText): Fix old code that was passing TextCaseSensitivity to a function that actually takes FindOptions. By luck, TextCaseSensitive happens to be 0, which is correct FindOptions for case sensitive matching, and TextCaseInsensitive happens to be 1, which is correct FindOptions for case insensitive matching, so fixing the code does not cause any change in behavior. Source/WTF: * wtf/text/ASCIIFastPath.h: Moved the using for charactersAreAllASCII here since the function is defined here. * wtf/text/AtomicString.h: Removed overloads of contains, find, startsWith, and endsWith that take a boolean indicating whether they should be "case sensitive". When false, this was doing Unicode case folding, and no callers needed that. Also tweaked formatting and argument names. * wtf/text/IntegerToStringConversion.h: Added an include of LChar.h since this file uses that. Also tweaked formatting a bit. * wtf/text/StringImpl.cpp: (WTF::StringImpl::containsOnlyWhitespace): Deleted. Despite its name sounding like it used the full Unicode whitespace definition, this actually checked isASCIISpace. Callers now all use isAllSpecialCharacters instead with the whitespace definition that is appropriate to each call site. (WTF::latin1CaseFoldTable): Deleted. (WTF::equalCompatibilityCaseless): Deleted. (WTF::StringImpl::findIgnoringCase): Deleted. (WTF::findIgnoringCaseInner): Deleted. (WTF::reverseFindIgnoringCaseInner): Deleted. (WTF::StringImpl::reverseFindIgnoringCase): Deleted. (WTF::equalInner): Removed boolean caseSensitive argument. (WTF::StringImpl::startsWith): Ditto. (WTF::StringImpl::endsWith): Ditto. * wtf/text/StringImpl.h: Moved TextCaseSensitivity out into a different header. Moved ASCIIFastPath.h include here from WTFString.h. Moved isAllSpecialCharacters free function here from WTFString.h. Moved lots of function bodies out of class definitions to make the class definitions easier to read. Sorted things a bit. Tweaked formatting. Marked constructor that takes one argument explicit. Added an isEmpty function like the one in String. Renamed copyChars to copyCharacters. Added isAllASCII, isAllLatin1 and isAllSpecialCharacters functions. Removed boolean caseSensitive arguments from various functions. Removed findIgnoringCase and reverseFindIgnoringCase. Added a FIXME to codePointCompare about the way it treats null and empty strings as equal. Changed length argument in remove to unsigned to match other lengths. * wtf/text/WTFString.cpp: (WTF::String::removeInternal): Changed length argument to be unsigned. (WTF::createWithFormatAndArguments): Use emptyString. (WTF::String::isSafeToSendToAnotherThread const): Rewrote to be easier to read. * wtf/text/WTFString.h: Moved ASCIIFastPath.h to StringImpl.h. Moved lots of function bodies out of class definitions to make the class definitions easier to read, made others one-liners. Removed the String::at function but kept the String::characterAt function; the two were identical. Removed boolean caseSensitive arguments from various functions. Removed findIgnoringCase and reverseFindIgnoringCase. Renamed containsOnlyASCII to isAllASCII and containsOnlyLatin1 to isAllLatin1 to match the naming of isAllSpecialCharacters. Moved the inline implementations of functions that are defined above further down, after things like the ASCIILiteral class and various functions. * wtf/text/icu/UTextProviderLatin1.cpp: Updated name of copyChars. Tools: * DumpRenderTree/mac/DumpRenderTree.mm: (changeWindowScaleIfNeeded): Use containsIgnoringASCIICase. * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::urlContains const): Ditto. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@225117 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent d7f8b89 commit 5917cb1

File tree

137 files changed

+2426
-2284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+2426
-2284
lines changed

Source/JavaScriptCore/ChangeLog

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2017-11-23 Darin Adler <[email protected]>
2+
3+
Reduce WTF::String operations that do unnecessary Unicode operations instead of ASCII
4+
https://bugs.webkit.org/show_bug.cgi?id=179907
5+
6+
Reviewed by Sam Weinig.
7+
8+
* inspector/agents/InspectorDebuggerAgent.cpp:
9+
(Inspector::matches): Removed explicit TextCaseSensitive because RegularExpression now
10+
defaults to that.
11+
12+
* runtime/StringPrototype.cpp:
13+
(JSC::stringIncludesImpl): Use String::find since there is no overload of
14+
String::contains that takes a start offset now that we removed the one that took a
15+
caseSensitive boolean. We can add one later if we like, but this should do for now.
16+
17+
* yarr/RegularExpression.h: Moved the TextCaseSensitivity enumeration here from
18+
the StringImpl.h header because it is only used here.
19+
120
2017-11-22 Simon Fraser <[email protected]>
221

322
Followup after r225084: if anyone called GenericTypedArrayView() it didn't compile,

Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static Ref<InspectorObject> buildObjectForBreakpointCookie(const String& url, in
335335
static bool matches(const String& url, const String& pattern, bool isRegex)
336336
{
337337
if (isRegex) {
338-
JSC::Yarr::RegularExpression regex(pattern, TextCaseSensitive);
338+
JSC::Yarr::RegularExpression regex(pattern);
339339
return regex.match(url) != -1;
340340
}
341341
return url == pattern;

Source/JavaScriptCore/runtime/JSString.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ static const unsigned maxLengthForOnStackResolve = 2048;
117117
void JSRopeString::resolveRopeInternal8(LChar* buffer) const
118118
{
119119
if (isSubstring()) {
120-
StringImpl::copyChars(
121-
buffer, substringBase()->m_value.characters8() + substringOffset(), length());
120+
StringImpl::copyCharacters(buffer, substringBase()->m_value.characters8() + substringOffset(), length());
122121
return;
123122
}
124123

@@ -138,7 +137,7 @@ void JSRopeString::resolveRopeInternal8NoSubstring(LChar* buffer) const
138137
for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i) {
139138
const StringImpl& fiberString = *fiber(i)->m_value.impl();
140139
unsigned length = fiberString.length();
141-
StringImpl::copyChars(position, fiberString.characters8(), length);
140+
StringImpl::copyCharacters(position, fiberString.characters8(), length);
142141
position += length;
143142
}
144143
ASSERT((buffer + length()) == position);
@@ -147,7 +146,7 @@ void JSRopeString::resolveRopeInternal8NoSubstring(LChar* buffer) const
147146
void JSRopeString::resolveRopeInternal16(UChar* buffer) const
148147
{
149148
if (isSubstring()) {
150-
StringImpl::copyChars(
149+
StringImpl::copyCharacters(
151150
buffer, substringBase()->m_value.characters16() + substringOffset(), length());
152151
return;
153152
}
@@ -169,9 +168,9 @@ void JSRopeString::resolveRopeInternal16NoSubstring(UChar* buffer) const
169168
const StringImpl& fiberString = *fiber(i)->m_value.impl();
170169
unsigned length = fiberString.length();
171170
if (fiberString.is8Bit())
172-
StringImpl::copyChars(position, fiberString.characters8(), length);
171+
StringImpl::copyCharacters(position, fiberString.characters8(), length);
173172
else
174-
StringImpl::copyChars(position, fiberString.characters16(), length);
173+
StringImpl::copyCharacters(position, fiberString.characters16(), length);
175174
position += length;
176175
}
177176
ASSERT((buffer + length()) == position);
@@ -335,7 +334,7 @@ void JSRopeString::resolveRopeSlowCase8(LChar* buffer) const
335334

336335
unsigned length = currentFiber->length();
337336
position -= length;
338-
StringImpl::copyChars(position, characters, length);
337+
StringImpl::copyCharacters(position, characters, length);
339338
}
340339

341340
ASSERT(buffer == position);
@@ -363,9 +362,9 @@ void JSRopeString::resolveRopeSlowCase(UChar* buffer) const
363362
unsigned length = currentFiberAsRope->length();
364363
position -= length;
365364
if (string->is8Bit())
366-
StringImpl::copyChars(position, string->characters8() + offset, length);
365+
StringImpl::copyCharacters(position, string->characters8() + offset, length);
367366
else
368-
StringImpl::copyChars(position, string->characters16() + offset, length);
367+
StringImpl::copyCharacters(position, string->characters16() + offset, length);
369368
continue;
370369
}
371370
for (size_t i = 0; i < s_maxInternalRopeLength && currentFiberAsRope->fiber(i); ++i)
@@ -377,9 +376,9 @@ void JSRopeString::resolveRopeSlowCase(UChar* buffer) const
377376
unsigned length = string->length();
378377
position -= length;
379378
if (string->is8Bit())
380-
StringImpl::copyChars(position, string->characters8(), length);
379+
StringImpl::copyCharacters(position, string->characters8(), length);
381380
else
382-
StringImpl::copyChars(position, string->characters16(), length);
381+
StringImpl::copyCharacters(position, string->characters16(), length);
383382
}
384383

385384
ASSERT(buffer == position);

Source/JavaScriptCore/runtime/StringPrototype.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static ALWAYS_INLINE JSValue jsSpliceSubstrings(ExecState* exec, JSString* sourc
341341
int bufferPos = 0;
342342
for (int i = 0; i < rangeCount; i++) {
343343
if (int srcLen = substringRanges[i].length) {
344-
StringImpl::copyChars(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen);
344+
StringImpl::copyCharacters(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen);
345345
bufferPos += srcLen;
346346
}
347347
}
@@ -360,7 +360,7 @@ static ALWAYS_INLINE JSValue jsSpliceSubstrings(ExecState* exec, JSString* sourc
360360
int bufferPos = 0;
361361
for (int i = 0; i < rangeCount; i++) {
362362
if (int srcLen = substringRanges[i].length) {
363-
StringImpl::copyChars(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen);
363+
StringImpl::copyCharacters(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen);
364364
bufferPos += srcLen;
365365
}
366366
}
@@ -413,13 +413,13 @@ static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, J
413413
for (int i = 0; i < maxCount; i++) {
414414
if (i < rangeCount) {
415415
if (int srcLen = substringRanges[i].length) {
416-
StringImpl::copyChars(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen);
416+
StringImpl::copyCharacters(buffer + bufferPos, sourceData + substringRanges[i].position, srcLen);
417417
bufferPos += srcLen;
418418
}
419419
}
420420
if (i < separatorCount) {
421421
if (int sepLen = separators[i].length()) {
422-
StringImpl::copyChars(buffer + bufferPos, separators[i].characters8(), sepLen);
422+
StringImpl::copyCharacters(buffer + bufferPos, separators[i].characters8(), sepLen);
423423
bufferPos += sepLen;
424424
}
425425
}
@@ -440,18 +440,18 @@ static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, J
440440
if (i < rangeCount) {
441441
if (int srcLen = substringRanges[i].length) {
442442
if (source.is8Bit())
443-
StringImpl::copyChars(buffer + bufferPos, source.characters8() + substringRanges[i].position, srcLen);
443+
StringImpl::copyCharacters(buffer + bufferPos, source.characters8() + substringRanges[i].position, srcLen);
444444
else
445-
StringImpl::copyChars(buffer + bufferPos, source.characters16() + substringRanges[i].position, srcLen);
445+
StringImpl::copyCharacters(buffer + bufferPos, source.characters16() + substringRanges[i].position, srcLen);
446446
bufferPos += srcLen;
447447
}
448448
}
449449
if (i < separatorCount) {
450450
if (int sepLen = separators[i].length()) {
451451
if (separators[i].is8Bit())
452-
StringImpl::copyChars(buffer + bufferPos, separators[i].characters8(), sepLen);
452+
StringImpl::copyCharacters(buffer + bufferPos, separators[i].characters8(), sepLen);
453453
else
454-
StringImpl::copyChars(buffer + bufferPos, separators[i].characters16(), sepLen);
454+
StringImpl::copyCharacters(buffer + bufferPos, separators[i].characters16(), sepLen);
455455
bufferPos += sepLen;
456456
}
457457
}
@@ -1799,7 +1799,7 @@ static EncodedJSValue JSC_HOST_CALL stringIncludesImpl(VM& vm, ExecState* exec,
17991799
RETURN_IF_EXCEPTION(scope, encodedJSValue());
18001800
}
18011801

1802-
return JSValue::encode(jsBoolean(stringToSearchIn.contains(searchString, true, start)));
1802+
return JSValue::encode(jsBoolean(stringToSearchIn.find(searchString, start) != notFound));
18031803
}
18041804

18051805
EncodedJSValue JSC_HOST_CALL stringProtoFuncIncludes(ExecState* exec)
@@ -1900,7 +1900,7 @@ static JSValue normalize(ExecState* exec, const UChar* source, size_t sourceLeng
19001900

19011901
if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) {
19021902
// The behavior is not specified when normalize fails.
1903-
// Now we throw a type erorr since it seems that the contents of the string are invalid.
1903+
// Now we throw a type error since it seems that the contents of the string are invalid.
19041904
return throwTypeError(exec, scope);
19051905
}
19061906

Source/JavaScriptCore/yarr/RegularExpression.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929

3030
namespace JSC { namespace Yarr {
3131

32-
enum MultilineMode {
33-
MultilineDisabled,
34-
MultilineEnabled
35-
};
32+
enum MultilineMode { MultilineDisabled, MultilineEnabled };
33+
enum TextCaseSensitivity { TextCaseSensitive, TextCaseInsensitive };
3634

3735
class JS_EXPORT_PRIVATE RegularExpression {
3836
WTF_MAKE_FAST_ALLOCATED;
3937
public:
40-
RegularExpression(const String&, TextCaseSensitivity, MultilineMode = MultilineDisabled);
38+
explicit RegularExpression(const String&, TextCaseSensitivity = TextCaseSensitive, MultilineMode = MultilineDisabled);
4139
~RegularExpression();
4240

4341
RegularExpression(const RegularExpression&);

Source/WTF/ChangeLog

+62
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1+
2017-11-23 Darin Adler <[email protected]>
2+
3+
Reduce WTF::String operations that do unnecessary Unicode operations instead of ASCII
4+
https://bugs.webkit.org/show_bug.cgi?id=179907
5+
6+
Reviewed by Sam Weinig.
7+
8+
* wtf/text/ASCIIFastPath.h: Moved the using for charactersAreAllASCII here since
9+
the function is defined here.
10+
11+
* wtf/text/AtomicString.h: Removed overloads of contains, find, startsWith, and
12+
endsWith that take a boolean indicating whether they should be "case sensitive".
13+
When false, this was doing Unicode case folding, and no callers needed that.
14+
Also tweaked formatting and argument names.
15+
16+
* wtf/text/IntegerToStringConversion.h: Added an include of LChar.h since this file
17+
uses that. Also tweaked formatting a bit.
18+
19+
* wtf/text/StringImpl.cpp:
20+
(WTF::StringImpl::containsOnlyWhitespace): Deleted. Despite its name sounding like
21+
it used the full Unicode whitespace definition, this actually checked isASCIISpace.
22+
Callers now all use isAllSpecialCharacters instead with the whitespace definition
23+
that is appropriate to each call site.
24+
(WTF::latin1CaseFoldTable): Deleted.
25+
(WTF::equalCompatibilityCaseless): Deleted.
26+
(WTF::StringImpl::findIgnoringCase): Deleted.
27+
(WTF::findIgnoringCaseInner): Deleted.
28+
(WTF::reverseFindIgnoringCaseInner): Deleted.
29+
(WTF::StringImpl::reverseFindIgnoringCase): Deleted.
30+
(WTF::equalInner): Removed boolean caseSensitive argument.
31+
(WTF::StringImpl::startsWith): Ditto.
32+
(WTF::StringImpl::endsWith): Ditto.
33+
34+
* wtf/text/StringImpl.h: Moved TextCaseSensitivity out into a different header.
35+
Moved ASCIIFastPath.h include here from WTFString.h. Moved isAllSpecialCharacters
36+
free function here from WTFString.h. Moved lots of function bodies out of class
37+
definitions to make the class definitions easier to read. Sorted things a bit.
38+
Tweaked formatting. Marked constructor that takes one argument explicit. Added
39+
an isEmpty function like the one in String. Renamed copyChars to copyCharacters.
40+
Added isAllASCII, isAllLatin1 and isAllSpecialCharacters functions. Removed
41+
boolean caseSensitive arguments from various functions. Removed findIgnoringCase
42+
and reverseFindIgnoringCase. Added a FIXME to codePointCompare about the way it
43+
treats null and empty strings as equal. Changed length argument in remove to
44+
unsigned to match other lengths.
45+
46+
* wtf/text/WTFString.cpp:
47+
(WTF::String::removeInternal): Changed length argument to be unsigned.
48+
(WTF::createWithFormatAndArguments): Use emptyString.
49+
(WTF::String::isSafeToSendToAnotherThread const): Rewrote to be easier to read.
50+
51+
* wtf/text/WTFString.h: Moved ASCIIFastPath.h to StringImpl.h. Moved lots of
52+
function bodies out of class definitions to make the class definitions easier
53+
to read, made others one-liners. Removed the String::at function but kept the
54+
String::characterAt function; the two were identical. Removed boolean
55+
caseSensitive arguments from various functions. Removed findIgnoringCase and
56+
reverseFindIgnoringCase. Renamed containsOnlyASCII to isAllASCII and
57+
containsOnlyLatin1 to isAllLatin1 to match the naming of isAllSpecialCharacters.
58+
Moved the inline implementations of functions that are defined above further
59+
down, after things like the ASCIILiteral class and various functions.
60+
61+
* wtf/text/icu/UTextProviderLatin1.cpp: Updated name of copyChars.
62+
163
2017-11-22 Stephan Szabo <[email protected]>
264

365
tuple related items are used in WTF without including tuple

Source/WTF/wtf/text/ASCIIFastPath.h

+2
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,6 @@ inline void copyLCharsFromUCharSource(LChar* destination, const UChar* source, s
194194

195195
} // namespace WTF
196196

197+
using WTF::charactersAreAllASCII;
198+
197199
#endif // ASCIIFastPath_h

0 commit comments

Comments
 (0)