WebKit Bugzilla
Attachment 341516 Details for
Bug 186059
: Reduce String allocations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-186059-20180529141935.patch (text/plain), 11.94 KB, created by
Alex Christensen
on 2018-05-29 14:19:36 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Alex Christensen
Created:
2018-05-29 14:19:36 PDT
Size:
11.94 KB
patch
obsolete
>Index: Source/WTF/ChangeLog >=================================================================== >--- Source/WTF/ChangeLog (revision 232272) >+++ Source/WTF/ChangeLog (working copy) >@@ -1,3 +1,18 @@ >+2018-05-29 Alex Christensen <achristensen@webkit.org> >+ >+ Reduce String allocations >+ https://bugs.webkit.org/show_bug.cgi?id=186059 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * wtf/text/StringView.cpp: >+ (WTF::convertASCIICase): >+ (WTF::StringView::convertToASCIILowercase const): >+ (WTF::StringView::convertToASCIIUppercase const): >+ * wtf/text/StringView.h: >+ * wtf/text/cf/StringViewCF.cpp: >+ (WTF::StringView::createCFString const): >+ > 2018-05-29 Saam Barati <sbarati@apple.com> > > JSC should put bmalloc's scavenger into mini mode >Index: Source/WTF/wtf/text/StringView.cpp >=================================================================== >--- Source/WTF/wtf/text/StringView.cpp (revision 232267) >+++ Source/WTF/wtf/text/StringView.cpp (working copy) >@@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBI > #include <wtf/Lock.h> > #include <wtf/NeverDestroyed.h> > #include <wtf/Optional.h> >+#include <wtf/text/StringBuffer.h> > #include <wtf/text/TextBreakIterator.h> > #include <wtf/unicode/UTF8.h> > >@@ -206,6 +207,35 @@ bool StringView::GraphemeClusters::Itera > return !(*this == other); > } > >+enum class ASCIICase { Lower, Upper }; >+ >+template<ASCIICase type, typename CharacterType> >+String convertASCIICase(const CharacterType* input, unsigned length) >+{ >+ if (!input) >+ return { }; >+ >+ StringBuffer<CharacterType> buffer(length); >+ CharacterType* characters = buffer.characters(); >+ for (unsigned i = 0; i < length; ++i) >+ characters[i] = type == ASCIICase::Lower ? toASCIILower(input[i]) : toASCIIUpper(input[i]); >+ return String::adopt(WTFMove(buffer)); >+} >+ >+String StringView::convertToASCIILowercase() const >+{ >+ if (m_is8Bit) >+ return convertASCIICase<ASCIICase::Lower>(static_cast<const LChar*>(m_characters), m_length); >+ return convertASCIICase<ASCIICase::Lower>(static_cast<const UChar*>(m_characters), m_length); >+} >+ >+String StringView::convertToASCIIUppercase() const >+{ >+ if (m_is8Bit) >+ return convertASCIICase<ASCIICase::Upper>(static_cast<const LChar*>(m_characters), m_length); >+ return convertASCIICase<ASCIICase::Upper>(static_cast<const UChar*>(m_characters), m_length); >+} >+ > #if CHECK_STRINGVIEW_LIFETIME > > // Manage reference count manually so UnderlyingString does not need to be defined in the header. >Index: Source/WTF/wtf/text/StringView.h >=================================================================== >--- Source/WTF/wtf/text/StringView.h (revision 232267) >+++ Source/WTF/wtf/text/StringView.h (working copy) >@@ -98,6 +98,7 @@ public: > > #if USE(CF) > // This function converts null strings to empty strings. >+ WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFString() const; > WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFStringWithoutCopying() const; > #endif > >@@ -136,6 +137,9 @@ public: > WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(const StringView&) const; > WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(const StringView&, unsigned startOffset) const; > >+ WTF_EXPORT_PRIVATE String convertToASCIILowercase() const; >+ WTF_EXPORT_PRIVATE String convertToASCIIUppercase() const; >+ > bool contains(UChar) const; > WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&) const; > WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&, unsigned startOffset) const; >Index: Source/WTF/wtf/text/cf/StringViewCF.cpp >=================================================================== >--- Source/WTF/wtf/text/cf/StringViewCF.cpp (revision 232267) >+++ Source/WTF/wtf/text/cf/StringViewCF.cpp (working copy) >@@ -33,6 +33,14 @@ > > namespace WTF { > >+RetainPtr<CFStringRef> StringView::createCFString() const >+{ >+ if (is8Bit()) >+ return adoptCF(CFStringCreateWithBytes(kCFAllocatorDefault, characters8(), length(), kCFStringEncodingISOLatin1, false)); >+ >+ return adoptCF(CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(characters16()), length())); >+} >+ > RetainPtr<CFStringRef> StringView::createCFStringWithoutCopying() const > { > if (is8Bit()) >Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 232267) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,33 @@ >+2018-05-29 Alex Christensen <achristensen@webkit.org> >+ >+ Reduce String allocations >+ https://bugs.webkit.org/show_bug.cgi?id=186059 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Don't allocate Strings just to convert it to another form. >+ Based mostly on Darin's feedback on bug 185986. >+ >+ No change in behavior. >+ >+ * Modules/websockets/WebSocketHandshake.cpp: >+ (WebCore::hostName): >+ (WebCore::WebSocketHandshake::host const): >+ * css/parser/CSSSelectorParser.cpp: >+ (WebCore::CSSSelectorParser::consumePseudo): >+ (WebCore::CSSSelectorParser::consumeANPlusB): >+ * loader/mac/LoaderNSURLExtras.mm: >+ (suggestedFilenameWithMIMEType): >+ * page/SecurityOriginData.h: >+ (WebCore::SecurityOriginData::fromURL): >+ * page/csp/ContentSecurityPolicySource.cpp: >+ (WebCore::wildcardMatches): >+ (WebCore::ContentSecurityPolicySource::hostMatches const): >+ * platform/URL.cpp: >+ (WebCore::URL::hostAndPort const): >+ * platform/network/cf/SocketStreamHandleImplCFNet.cpp: >+ (WebCore::SocketStreamHandleImpl::createStreams): >+ > 2018-05-29 Alex Christensen <achristensen@webkit.org> > > Do even fewer allocations in URL host operations >Index: Source/WebCore/Modules/websockets/WebSocketHandshake.cpp >=================================================================== >--- Source/WebCore/Modules/websockets/WebSocketHandshake.cpp (revision 232267) >+++ Source/WebCore/Modules/websockets/WebSocketHandshake.cpp (working copy) >@@ -82,7 +82,7 @@ static String hostName(const URL& url, b > { > ASSERT(url.protocolIs("wss") == secure); > StringBuilder builder; >- builder.append(url.host().toString().convertToASCIILowercase()); >+ builder.append(url.host().convertToASCIILowercase()); > if (url.port() && ((!secure && url.port().value() != 80) || (secure && url.port().value() != 443))) { > builder.append(':'); > builder.appendNumber(url.port().value()); >@@ -146,7 +146,7 @@ void WebSocketHandshake::setURL(const UR > // FIXME: Return type should just be String, not const String. > const String WebSocketHandshake::host() const > { >- return m_url.host().toString().convertToASCIILowercase(); >+ return m_url.host().convertToASCIILowercase(); > } > > const String& WebSocketHandshake::clientProtocol() const >Index: Source/WebCore/css/parser/CSSSelectorParser.cpp >=================================================================== >--- Source/WebCore/css/parser/CSSSelectorParser.cpp (revision 232267) >+++ Source/WebCore/css/parser/CSSSelectorParser.cpp (working copy) >@@ -494,7 +494,7 @@ std::unique_ptr<CSSParserSelector> CSSSe > > std::unique_ptr<CSSParserSelector> selector; > >- auto lowercasedValue = token.value().toString().convertToASCIILowercase(); >+ auto lowercasedValue = token.value().convertToASCIILowercase(); > auto value = StringView { lowercasedValue }; > > if (colons == 1) >@@ -735,7 +735,7 @@ bool CSSSelectorParser::consumeANPlusB(C > } else if (token.type() == IdentToken) { > if (token.value()[0] == '-') { > result.first = -1; >- nString = token.value().toString().substring(1); >+ nString = token.value().substring(1).toString(); > } else { > result.first = 1; > nString = token.value().toString(); >Index: Source/WebCore/loader/mac/LoaderNSURLExtras.mm >=================================================================== >--- Source/WebCore/loader/mac/LoaderNSURLExtras.mm (revision 232267) >+++ Source/WebCore/loader/mac/LoaderNSURLExtras.mm (working copy) >@@ -48,8 +48,8 @@ NSString *suggestedFilenameWithMIMEType( > > if ([filename length] == 0 || [lastPathComponent isEqualToString:@"/"]) { > // lastPathComponent is no good, try the host. >- NSString *host = URL(url).host().toString(); >- filename = filenameByFixingIllegalCharacters(host); >+ auto host = URL(url).host().createNSString(); >+ filename = filenameByFixingIllegalCharacters(host.get()); > if ([filename length] == 0) { > // Can't make a filename using this URL, use "unknown". > filename = copyImageUnknownFileLabel(); >Index: Source/WebCore/page/SecurityOriginData.h >=================================================================== >--- Source/WebCore/page/SecurityOriginData.h (revision 232267) >+++ Source/WebCore/page/SecurityOriginData.h (working copy) >@@ -49,8 +49,8 @@ struct SecurityOriginData { > static SecurityOriginData fromURL(const URL& url) > { > return SecurityOriginData { >- url.protocol().isNull() ? emptyString() : url.protocol().toString().convertToASCIILowercase(), >- url.host().isNull() ? emptyString() : url.host().toString().convertToASCIILowercase(), >+ url.protocol().isNull() ? emptyString() : url.protocol().convertToASCIILowercase(), >+ url.host().isNull() ? emptyString() : url.host().convertToASCIILowercase(), > url.port() > }; > } >Index: Source/WebCore/page/csp/ContentSecurityPolicySource.cpp >=================================================================== >--- Source/WebCore/page/csp/ContentSecurityPolicySource.cpp (revision 232267) >+++ Source/WebCore/page/csp/ContentSecurityPolicySource.cpp (working copy) >@@ -62,11 +62,19 @@ bool ContentSecurityPolicySource::scheme > return equalIgnoringASCIICase(url.protocol(), m_scheme); > } > >+static bool wildcardMatches(StringView host, const String& hostWithWildcard) >+{ >+ auto hostLength = host.length(); >+ auto hostWithWildcardLength = hostWithWildcard.length(); >+ return host.endsWithIgnoringASCIICase(hostWithWildcard) >+ && hostLength > hostWithWildcardLength >+ && host[hostLength - hostWithWildcardLength - 1] == '.'; >+} >+ > bool ContentSecurityPolicySource::hostMatches(const URL& url) const > { > auto host = url.host(); >- return equalIgnoringASCIICase(host, m_host) || (m_hostHasWildcard && host.endsWithIgnoringASCIICase(makeString(".", m_host))); >- >+ return equalIgnoringASCIICase(host, m_host) || (m_hostHasWildcard && wildcardMatches(host, m_host)); > } > > bool ContentSecurityPolicySource::pathMatches(const URL& url) const >Index: Source/WebCore/platform/URL.cpp >=================================================================== >--- Source/WebCore/platform/URL.cpp (revision 232267) >+++ Source/WebCore/platform/URL.cpp (working copy) >@@ -39,6 +39,7 @@ > #include <wtf/UUID.h> > #include <wtf/text/CString.h> > #include <wtf/text/StringBuilder.h> >+#include <wtf/text/StringConcatenateNumbers.h> > #include <wtf/text/StringHash.h> > #include <wtf/text/TextStream.h> > >@@ -180,7 +181,7 @@ std::optional<uint16_t> URL::port() cons > String URL::hostAndPort() const > { > if (auto port = this->port()) >- return makeString(host(), ':', String::number(port.value())); >+ return makeString(host(), ':', static_cast<unsigned>(port.value())); > return host().toString(); > } > >Index: Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp >=================================================================== >--- Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp (revision 232267) >+++ Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp (working copy) >@@ -312,7 +312,7 @@ void SocketStreamHandleImpl::createStrea > if (m_connectionType == Unknown) > return; > >- RetainPtr<CFStringRef> host = m_url.host().toString().createCFString(); >+ RetainPtr<CFStringRef> host = m_url.host().createCFString(); > > // Creating streams to final destination, not to proxy. > CFReadStreamRef readStream = 0;
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 186059
:
341512
|
341513
| 341516