From: benjamin@webkit.org Date: Fri, 13 Apr 2012 02:25:32 +0000 (+0000) Subject: Inline StringImpl::find(UChar, ...) X-Git-Tag: 070512121124~7102 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19569d2bde526c89fa2c60751ac9b244aeecb77f;p=profile%2Fivi%2Fwebkit-efl.git Inline StringImpl::find(UChar, ...) https://bugs.webkit.org/show_bug.cgi?id=83737 Patch by Benjamin Poulain on 2012-04-12 Reviewed by Geoffrey Garen. The implementation of StringImpl::find() is a simple branch before invoking one of two inline functions. The overhead of having a function for StringImpl::find() is significant. It is better to let the compiler decide if that should be inlined or not. * wtf/text/StringImpl.cpp: * wtf/text/StringImpl.h: (StringImpl): (WTF::find): (WTF): (WTF::reverseFind): (WTF::StringImpl::find): * wtf/text/WTFString.h: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114071 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog index d7a4d34..6a3c15f 100644 --- a/Source/WTF/ChangeLog +++ b/Source/WTF/ChangeLog @@ -1,3 +1,24 @@ +2012-04-12 Benjamin Poulain + + Inline StringImpl::find(UChar, ...) + https://bugs.webkit.org/show_bug.cgi?id=83737 + + Reviewed by Geoffrey Garen. + + The implementation of StringImpl::find() is a simple branch before invoking one of + two inline functions. The overhead of having a function for StringImpl::find() is significant. + + It is better to let the compiler decide if that should be inlined or not. + + * wtf/text/StringImpl.cpp: + * wtf/text/StringImpl.h: + (StringImpl): + (WTF::find): + (WTF): + (WTF::reverseFind): + (WTF::StringImpl::find): + * wtf/text/WTFString.h: + 2012-04-12 Balazs Kelemen [Qt] Fix WebKit1 build with V8 diff --git a/Source/WTF/wtf/text/StringImpl.cpp b/Source/WTF/wtf/text/StringImpl.cpp index d933817..ae501b9 100644 --- a/Source/WTF/wtf/text/StringImpl.cpp +++ b/Source/WTF/wtf/text/StringImpl.cpp @@ -777,13 +777,6 @@ static inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length) return umemcasecmp(a, b, length) == 0; } -size_t StringImpl::find(UChar c, unsigned start) -{ - if (is8Bit()) - return WTF::find(characters8(), m_length, c, start); - return WTF::find(characters16(), m_length, c, start); -} - size_t StringImpl::find(CharacterMatchFunctionPtr matchFunction, unsigned start) { if (is8Bit()) diff --git a/Source/WTF/wtf/text/StringImpl.h b/Source/WTF/wtf/text/StringImpl.h index db322fc..ea82bb6 100644 --- a/Source/WTF/wtf/text/StringImpl.h +++ b/Source/WTF/wtf/text/StringImpl.h @@ -481,7 +481,7 @@ public: template ALWAYS_INLINE PassRefPtr removeCharacters(const CharType* characters, CharacterMatchFunctionPtr); - WTF_EXPORT_PRIVATE size_t find(UChar, unsigned index = 0); + size_t find(UChar character, unsigned start = 0); WTF_EXPORT_PRIVATE size_t find(CharacterMatchFunctionPtr, unsigned index = 0); size_t find(const LChar*, unsigned index = 0); ALWAYS_INLINE size_t find(const char* s, unsigned index = 0) { return find(reinterpret_cast(s), index); }; @@ -735,6 +735,79 @@ inline bool equalIgnoringCase(const char* a, const UChar* b, unsigned length) { WTF_EXPORT_PRIVATE bool equalIgnoringNullity(StringImpl*, StringImpl*); +inline size_t find(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = 0) +{ + while (index < length) { + if (characters[index] == matchCharacter) + return index; + ++index; + } + return notFound; +} + +inline size_t find(const UChar* characters, unsigned length, UChar matchCharacter, unsigned index = 0) +{ + while (index < length) { + if (characters[index] == matchCharacter) + return index; + ++index; + } + return notFound; +} + +inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunctionPtr matchFunction, unsigned index = 0) +{ + while (index < length) { + if (matchFunction(characters[index])) + return index; + ++index; + } + return notFound; +} + +inline size_t find(const UChar* characters, unsigned length, CharacterMatchFunctionPtr matchFunction, unsigned index = 0) +{ + while (index < length) { + if (matchFunction(characters[index])) + return index; + ++index; + } + return notFound; +} + +inline size_t reverseFind(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = UINT_MAX) +{ + if (!length) + return notFound; + if (index >= length) + index = length - 1; + while (characters[index] != matchCharacter) { + if (!index--) + return notFound; + } + return index; +} + +inline size_t reverseFind(const UChar* characters, unsigned length, UChar matchCharacter, unsigned index = UINT_MAX) +{ + if (!length) + return notFound; + if (index >= length) + index = length - 1; + while (characters[index] != matchCharacter) { + if (!index--) + return notFound; + } + return index; +} + +inline size_t StringImpl::find(UChar character, unsigned start) +{ + if (is8Bit()) + return WTF::find(characters8(), m_length, character, start); + return WTF::find(characters16(), m_length, character, start); +} + template bool equalIgnoringNullity(const Vector& a, StringImpl* b) { diff --git a/Source/WTF/wtf/text/WTFString.h b/Source/WTF/wtf/text/WTFString.h index f1ff363..90cf377 100644 --- a/Source/WTF/wtf/text/WTFString.h +++ b/Source/WTF/wtf/text/WTFString.h @@ -509,72 +509,6 @@ inline bool codePointCompareLessThan(const String& a, const String& b) return codePointCompare(a.impl(), b.impl()) < 0; } -inline size_t find(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = 0) -{ - while (index < length) { - if (characters[index] == matchCharacter) - return index; - ++index; - } - return notFound; -} - -inline size_t find(const UChar* characters, unsigned length, UChar matchCharacter, unsigned index = 0) -{ - while (index < length) { - if (characters[index] == matchCharacter) - return index; - ++index; - } - return notFound; -} - -inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunctionPtr matchFunction, unsigned index = 0) -{ - while (index < length) { - if (matchFunction(characters[index])) - return index; - ++index; - } - return notFound; -} - -inline size_t find(const UChar* characters, unsigned length, CharacterMatchFunctionPtr matchFunction, unsigned index = 0) -{ - while (index < length) { - if (matchFunction(characters[index])) - return index; - ++index; - } - return notFound; -} - -inline size_t reverseFind(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = UINT_MAX) -{ - if (!length) - return notFound; - if (index >= length) - index = length - 1; - while (characters[index] != matchCharacter) { - if (!index--) - return notFound; - } - return index; -} - -inline size_t reverseFind(const UChar* characters, unsigned length, UChar matchCharacter, unsigned index = UINT_MAX) -{ - if (!length) - return notFound; - if (index >= length) - index = length - 1; - while (characters[index] != matchCharacter) { - if (!index--) - return notFound; - } - return index; -} - inline void append(Vector& vector, const String& string) { vector.append(string.characters(), string.length());