Changeset 206076 in webkit
- Timestamp:
- Sep 18, 2016 1:01:11 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r206075 r206076 1 2016-09-18 Alex Christensen <achristensen@webkit.org> 2 3 Remove unnecessary String allocations in URLParser 4 https://bugs.webkit.org/show_bug.cgi?id=162089 5 6 Reviewed by Chris Dumez. 7 8 No change in behavior except a performance improvement. 9 10 * platform/URL.cpp: 11 (WebCore::assertProtocolIsGood): 12 (WebCore::URL::protocolIs): 13 (WebCore::protocolIs): 14 * platform/URL.h: 15 Added a new protocolIs for non-null-terminated strings from user input. 16 * platform/URLParser.cpp: 17 (WebCore::URLParser::parse): 18 Don't make a String to compare protocols. 19 1 20 2016-09-17 Alex Christensen <achristensen@webkit.org> 2 21 -
trunk/Source/WebCore/platform/URL.cpp
r205782 r206076 791 791 #ifdef NDEBUG 792 792 793 static inline void assertProtocolIsGood(const char* )793 static inline void assertProtocolIsGood(const char*, size_t) 794 794 { 795 795 } … … 797 797 #else 798 798 799 static void assertProtocolIsGood(const char* protocol) 800 { 801 const char* p = protocol; 802 while (*p) { 803 ASSERT(*p > ' ' && *p < 0x7F && !(*p >= 'A' && *p <= 'Z')); 804 ++p; 799 static void assertProtocolIsGood(const char* protocol, size_t length) 800 { 801 for (size_t i = 0; i < length; ++i) { 802 const char c = protocol[i]; 803 ASSERT(c > ' ' && c < 0x7F && !(c >= 'A' && c <= 'Z')); 805 804 } 806 805 } … … 810 809 bool URL::protocolIs(const char* protocol) const 811 810 { 812 assertProtocolIsGood(protocol );811 assertProtocolIsGood(protocol, strlen(protocol)); 813 812 814 813 // JavaScript URLs are "valid" and should be executed even if URL decides they are invalid. … … 825 824 } 826 825 return !protocol[m_schemeEnd]; // We should have consumed all characters in the argument. 826 } 827 828 bool URL::protocolIs(const LChar* protocol, size_t length) const 829 { 830 assertProtocolIsGood(reinterpret_cast<const char*>(protocol), length); 831 832 if (!m_isValid) 833 return false; 834 835 if (m_schemeEnd != length) 836 return false; 837 838 // Do the comparison without making a new string object. 839 for (unsigned i = 0; i < m_schemeEnd; ++i) { 840 if (!isSchemeCharacterMatchIgnoringCase(m_string[i], protocol[i])) 841 return false; 842 } 843 return true; 827 844 } 828 845 … … 1900 1917 static bool protocolIs(StringView stringURL, const char* protocol) 1901 1918 { 1902 assertProtocolIsGood(protocol );1919 assertProtocolIsGood(protocol, strlen(protocol)); 1903 1920 unsigned length = stringURL.length(); 1904 1921 for (unsigned i = 0; i < length; ++i) { … … 2123 2140 } 2124 2141 2142 // FIXME: Why is this different than protocolIs(StringView, const char*)? 2125 2143 bool protocolIs(const String& url, const char* protocol) 2126 2144 { 2127 2145 // Do the comparison without making a new string object. 2128 assertProtocolIsGood(protocol );2146 assertProtocolIsGood(protocol, strlen(protocol)); 2129 2147 bool isLeading = true; 2130 2148 for (unsigned i = 0, j = 0; url[i]; ++i) { -
trunk/Source/WebCore/platform/URL.h
r205782 r206076 24 24 */ 25 25 26 #ifndef URL_h 27 #define URL_h 26 #pragma once 28 27 29 28 #include "PlatformExportMacros.h" … … 131 130 // terminated ASCII argument. The argument must be lower-case. 132 131 WEBCORE_EXPORT bool protocolIs(const char*) const; 132 bool protocolIs(const LChar*, size_t) const; 133 133 bool protocolIsBlob() const { return protocolIs("blob"); } 134 134 bool protocolIsData() const { return protocolIs("data"); } … … 456 456 457 457 } // namespace WTF 458 459 #endif // URL_h -
trunk/Source/WebCore/platform/URLParser.cpp
r206075 r206076 950 950 if (isSpecialScheme(urlScheme)) { 951 951 m_urlIsSpecial = true; 952 // FIXME: This is unnecessarily allocating a String. 953 // This should be easy to optimize once https://bugs.webkit.org/show_bug.cgi?id=162035 lands. 954 if (base.protocol() == urlScheme) 952 if (base.protocolIs(m_asciiBuffer.data(), m_asciiBuffer.size() - 1)) 955 953 state = State::SpecialRelativeOrAuthority; 956 954 else … … 1006 1004 break; 1007 1005 } 1008 if ( base.protocol() != "file") {1006 if (!base.protocolIs("file")) { 1009 1007 state = State::Relative; 1010 1008 break; … … 1443 1441 case State::File: 1444 1442 LOG_FINAL_STATE("File"); 1445 if (!base.isNull() && base.protocol () == "file") {1443 if (!base.isNull() && base.protocolIs("file")) { 1446 1444 copyURLPartsUntil(base, URLPart::QueryEnd); 1447 1445 m_asciiBuffer.append(':');
Note: See TracChangeset
for help on using the changeset viewer.