Changeset 115290 in webkit
- Timestamp:
- Apr 25, 2012, 10:27:52 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r115288 r115290 1 2012-04-25 Benjamin Poulain <benjamin@webkit.org> 2 3 Add a version of StringImpl::find() without offset 4 https://bugs.webkit.org/show_bug.cgi?id=83968 5 6 Reviewed by Sam Weinig. 7 8 Add support for the new StringImpl::find() to UString. 9 10 Change stringProtoFuncIndexOf() to specifically take advatage of the feature. 11 This gives a 12% gains on a distribution of strings between 30 and 100 characters. 12 13 * runtime/StringPrototype.cpp: 14 (JSC::substituteBackreferences): 15 (JSC::stringProtoFuncIndexOf): 16 * runtime/UString.h: 17 (UString): 18 (JSC::UString::find): 19 1 20 2012-04-25 Mark Hahnenberg <mhahnenberg@apple.com> 2 21 -
trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp
r115132 r115290 241 241 static inline UString substituteBackreferences(const UString& replacement, const UString& source, const int* ovector, RegExp* reg) 242 242 { 243 size_t i = replacement.find('$' , 0);243 size_t i = replacement.find('$'); 244 244 if (UNLIKELY(i != notFound)) { 245 245 if (replacement.is8Bit() && source.is8Bit()) … … 755 755 return throwVMTypeError(exec); 756 756 UString s = thisValue.toString(exec)->value(exec); 757 int len = s.length();758 757 759 758 JSValue a0 = exec->argument(0); 760 759 JSValue a1 = exec->argument(1); 761 760 UString u2 = a0.toString(exec)->value(exec); 762 int pos; 761 762 size_t result; 763 763 if (a1.isUndefined()) 764 pos = 0; 765 else if (a1.isUInt32()) 766 pos = min<uint32_t>(a1.asUInt32(), len); 764 result = s.find(u2); 767 765 else { 768 double dpos = a1.toInteger(exec); 769 if (dpos < 0) 770 dpos = 0; 771 else if (dpos > len) 772 dpos = len; 773 pos = static_cast<int>(dpos); 774 } 775 776 size_t result = s.find(u2, pos); 766 unsigned pos; 767 int len = s.length(); 768 if (a1.isUInt32()) 769 pos = min<uint32_t>(a1.asUInt32(), len); 770 else { 771 double dpos = a1.toInteger(exec); 772 if (dpos < 0) 773 dpos = 0; 774 else if (dpos > len) 775 dpos = len; 776 pos = static_cast<unsigned>(dpos); 777 } 778 result = s.find(u2, pos); 779 } 780 777 781 if (result == notFound) 778 782 return JSValue::encode(jsNumber(-1)); -
trunk/Source/JavaScriptCore/runtime/UString.h
r106257 r115290 122 122 size_t find(UChar c, unsigned start = 0) const 123 123 { return m_impl ? m_impl->find(c, start) : notFound; } 124 size_t find(const UString& str, unsigned start = 0) const 124 125 size_t find(const UString& str) const 126 { return m_impl ? m_impl->find(str.impl()) : notFound; } 127 size_t find(const UString& str, unsigned start) const 125 128 { return m_impl ? m_impl->find(str.impl(), start) : notFound; } 129 126 130 size_t find(const LChar* str, unsigned start = 0) const 127 131 { return m_impl ? m_impl->find(str, start) : notFound; } -
trunk/Source/WTF/ChangeLog
r115272 r115290 1 2012-04-25 Benjamin Poulain <benjamin@webkit.org> 2 3 Add a version of StringImpl::find() without offset 4 https://bugs.webkit.org/show_bug.cgi?id=83968 5 6 Reviewed by Sam Weinig. 7 8 This patch add a version of StringImpl::find() without offset, Instead of using the default 9 value for the index. 10 11 By not having the index, we can skip a couple of branches and a few instructions. This gives 12 significant gains when the strings are short-ish. 13 14 The case of empty string is moved below (matchLength == 1) since it is a less common operation. 15 16 * wtf/text/StringImpl.cpp: 17 (WTF::StringImpl::find): 18 (WTF): 19 * wtf/text/StringImpl.h: 20 (StringImpl): 21 * wtf/text/WTFString.h: 22 (String): 23 (WTF::String::find): 24 1 25 2012-04-25 Darin Adler <darin@apple.com> 2 26 -
trunk/Source/WTF/wtf/text/StringImpl.cpp
r115132 r115290 895 895 } 896 896 897 size_t StringImpl::find(StringImpl* matchString) 898 { 899 // Check for null string to match against 900 if (UNLIKELY(!matchString)) 901 return notFound; 902 unsigned matchLength = matchString->length(); 903 904 // Optimization 1: fast case for strings of length 1. 905 if (matchLength == 1) { 906 if (is8Bit()) { 907 if (matchString->is8Bit()) 908 return WTF::find(characters8(), length(), matchString->characters8()[0]); 909 return WTF::find(characters8(), length(), matchString->characters16()[0]); 910 } 911 if (matchString->is8Bit()) 912 return WTF::find(characters16(), length(), matchString->characters8()[0]); 913 return WTF::find(characters16(), length(), matchString->characters16()[0]); 914 } 915 916 // Check matchLength is in range. 917 if (matchLength > length()) 918 return notFound; 919 920 // Check for empty string to match against 921 if (UNLIKELY(!matchLength)) 922 return 0; 923 924 if (is8Bit() && matchString->is8Bit()) 925 return findInner(characters8(), matchString->characters8(), 0, length(), matchLength); 926 927 return findInner(characters(), matchString->characters(), 0, length(), matchLength); 928 } 929 897 930 size_t StringImpl::find(StringImpl* matchString, unsigned index) 898 931 { 899 932 // Check for null or empty string to match against 900 if (!matchString) 901 return notFound; 933 if (UNLIKELY(!matchString)) 934 return notFound; 935 902 936 unsigned matchLength = matchString->length(); 903 if (!matchLength)904 return min(index, length());905 937 906 938 // Optimization 1: fast case for strings of length 1. … … 916 948 } 917 949 950 if (UNLIKELY(!matchLength)) 951 return min(index, length()); 952 918 953 // Check index & matchLength are in range. 919 954 if (index > length()) … … 927 962 928 963 return findInner(characters() + index, matchString->characters(), index, searchLength, matchLength); 929 930 964 } 931 965 -
trunk/Source/WTF/wtf/text/StringImpl.h
r115132 r115290 488 488 size_t find(const LChar*, unsigned index = 0); 489 489 ALWAYS_INLINE size_t find(const char* s, unsigned index = 0) { return find(reinterpret_cast<const LChar*>(s), index); }; 490 WTF_EXPORT_PRIVATE size_t find(StringImpl*, unsigned index = 0); 490 WTF_EXPORT_PRIVATE size_t find(StringImpl*); 491 WTF_EXPORT_PRIVATE size_t find(StringImpl*, unsigned index); 491 492 size_t findIgnoringCase(const LChar*, unsigned index = 0); 492 493 ALWAYS_INLINE size_t findIgnoringCase(const char* s, unsigned index = 0) { return findIgnoringCase(reinterpret_cast<const LChar*>(s), index); }; -
trunk/Source/WTF/wtf/text/WTFString.h
r114071 r115290 206 206 size_t find(UChar c, unsigned start = 0) const 207 207 { return m_impl ? m_impl->find(c, start) : notFound; } 208 size_t find(const String& str, unsigned start = 0) const 208 209 size_t find(const String& str) const 210 { return m_impl ? m_impl->find(str.impl()) : notFound; } 211 size_t find(const String& str, unsigned start) const 209 212 { return m_impl ? m_impl->find(str.impl(), start) : notFound; } 213 210 214 size_t find(CharacterMatchFunctionPtr matchFunction, unsigned start = 0) const 211 215 { return m_impl ? m_impl->find(matchFunction, start) : notFound; } -
trunk/Source/WebCore/ChangeLog
r115288 r115290 1 2012-04-25 Benjamin Poulain <benjamin@webkit.org> 2 3 Add a version of StringImpl::find() without offset 4 https://bugs.webkit.org/show_bug.cgi?id=83968 5 6 Reviewed by Sam Weinig. 7 8 Remove the zero offset of the find() functions on strings. 9 10 * html/parser/XSSAuditor.cpp: 11 (WebCore::XSSAuditor::init): 12 * platform/network/ResourceResponseBase.cpp: 13 (WebCore::trimToNextSeparator): 14 (WebCore::parseCacheHeader): 15 1 16 2012-04-25 Mark Hahnenberg <mhahnenberg@apple.com> 2 17 -
trunk/Source/WebCore/html/parser/XSSAuditor.cpp
r113286 r115290 212 212 TextResourceDecoder* decoder = m_parser->document()->decoder(); 213 213 m_decodedURL = fullyDecodeString(url.string(), decoder); 214 if (m_decodedURL.find(isRequiredForInjection , 0) == notFound)214 if (m_decodedURL.find(isRequiredForInjection) == notFound) 215 215 m_decodedURL = String(); 216 216 … … 224 224 if (!httpBodyAsString.isEmpty()) { 225 225 m_decodedHTTPBody = fullyDecodeString(httpBodyAsString, decoder); 226 if (m_decodedHTTPBody.find(isRequiredForInjection , 0) == notFound)226 if (m_decodedHTTPBody.find(isRequiredForInjection) == notFound) 227 227 m_decodedHTTPBody = String(); 228 228 if (m_decodedHTTPBody.length() >= miniumLengthForSuffixTree) -
trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp
r114165 r115290 631 631 static inline String trimToNextSeparator(const String& str) 632 632 { 633 return str.substring(0, str.find(isCacheHeaderSeparator , 0));633 return str.substring(0, str.find(isCacheHeaderSeparator)); 634 634 } 635 635 … … 667 667 } else { 668 668 // The value is a token until the next comma 669 size_t nextCommaPosition2 = value.find(',' , 0);669 size_t nextCommaPosition2 = value.find(','); 670 670 if (nextCommaPosition2 != notFound) { 671 671 // The value is delimited by the next comma -
trunk/Source/WebKit2/ChangeLog
r115288 r115290 1 2012-04-25 Benjamin Poulain <benjamin@webkit.org> 2 3 Add a version of StringImpl::find() without offset 4 https://bugs.webkit.org/show_bug.cgi?id=83968 5 6 Update the symbols files. 7 8 * win/WebKit2.def: 9 * win/WebKit2CFLite.def: 10 1 11 2012-04-25 Mark Hahnenberg <mhahnenberg@apple.com> 2 12 -
trunk/Source/WebKit2/win/WebKit2.def
r114877 r115290 169 169 ?externalRepresentation@WebCore@@YA?AVString@WTF@@PAVElement@1@I@Z 170 170 ?find@StringImpl@WTF@@QAEIPAV12@I@Z 171 ?find@StringImpl@WTF@@QAEIPAV12@@Z 171 172 ?frameDestroyed@FrameDestructionObserver@WebCore@@UAEXXZ 172 173 ?fromUTF8WithLatin1Fallback@String@WTF@@SA?AV12@PBEI@Z -
trunk/Source/WebKit2/win/WebKit2CFLite.def
r114877 r115290 162 162 ?externalRepresentation@WebCore@@YA?AVString@WTF@@PAVElement@1@I@Z 163 163 ?find@StringImpl@WTF@@QAEIPAV12@I@Z 164 ?find@StringImpl@WTF@@QAEIPAV12@@Z 164 165 ?frameDestroyed@FrameDestructionObserver@WebCore@@UAEXXZ 165 166 ?fromUTF8WithLatin1Fallback@String@WTF@@SA?AV12@PBEI@Z
Note:
See TracChangeset
for help on using the changeset viewer.