Modified: trunk/Source/WTF/ChangeLog (131523 => 131524)
--- trunk/Source/WTF/ChangeLog 2012-10-16 23:06:02 UTC (rev 131523)
+++ trunk/Source/WTF/ChangeLog 2012-10-16 23:07:33 UTC (rev 131524)
@@ -1,3 +1,20 @@
+2012-10-16 Michael Saboff <msab...@apple.com>
+
+ StringImpl::reverseFind() with a single match character isn't optimal for mixed 8/16 bit cases
+ https://bugs.webkit.org/show_bug.cgi?id=99363
+
+ Reviewed by Benjamin Poulain.
+
+ Factored out the 8/16 bitness check of the match character from the subject character bitness
+ check. Did this for both find() and reverseFind(). Added all UChar/LChar combinations to the
+ inline reverseFind().
+
+ * wtf/text/StringImpl.cpp:
+ (WTF::StringImpl::find):
+ (WTF::StringImpl::reverseFind):
+ * wtf/text/StringImpl.h:
+ (WTF::reverseFind):
+
2012-10-16 Dima Gorbik <dgor...@apple.com>
Remove Platform.h include from the header files.
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (131523 => 131524)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-10-16 23:06:02 UTC (rev 131523)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-10-16 23:07:33 UTC (rev 131524)
@@ -1021,14 +1021,9 @@
// Optimization 1: fast case for strings of length 1.
if (matchLength == 1) {
- if (is8Bit()) {
- if (matchString->is8Bit())
- return WTF::find(characters8(), length(), matchString->characters8()[0], index);
- return WTF::find(characters8(), length(), matchString->characters16()[0], index);
- }
- if (matchString->is8Bit())
- return WTF::find(characters16(), length(), matchString->characters8()[0], index);
- return WTF::find(characters16(), length(), matchString->characters16()[0], index);
+ if (is8Bit())
+ return WTF::find(characters8(), length(), (*matchString)[0], index);
+ return WTF::find(characters16(), length(), (*matchString)[0], index);
}
if (UNLIKELY(!matchLength))
@@ -1130,9 +1125,9 @@
// Optimization 1: fast case for strings of length 1.
if (matchLength == 1) {
- if (is8Bit() && matchString->is8Bit())
- return WTF::reverseFind(characters8(), ourLength, matchString->characters8()[0], index);
- return WTF::reverseFind(characters(), ourLength, matchString->characters()[0], index);
+ if (is8Bit())
+ return WTF::reverseFind(characters8(), ourLength, (*matchString)[0], index);
+ return WTF::reverseFind(characters16(), ourLength, (*matchString)[0], index);
}
// Check index & matchLength are in range.
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (131523 => 131524)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2012-10-16 23:06:02 UTC (rev 131523)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2012-10-16 23:07:33 UTC (rev 131524)
@@ -1002,7 +1002,8 @@
return notFound;
}
-inline size_t reverseFind(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = UINT_MAX)
+template <typename CharacterType>
+inline size_t reverseFind(const CharacterType* characters, unsigned length, CharacterType matchCharacter, unsigned index = UINT_MAX)
{
if (!length)
return notFound;
@@ -1015,17 +1016,16 @@
return index;
}
-inline size_t reverseFind(const UChar* characters, unsigned length, UChar matchCharacter, unsigned index = UINT_MAX)
+ALWAYS_INLINE size_t reverseFind(const UChar* characters, unsigned length, LChar matchCharacter, unsigned index = UINT_MAX)
{
- if (!length)
+ return reverseFind(characters, length, static_cast<UChar>(matchCharacter), index);
+}
+
+inline size_t reverseFind(const LChar* characters, unsigned length, UChar matchCharacter, unsigned index = UINT_MAX)
+{
+ if (matchCharacter & ~0xFF)
return notFound;
- if (index >= length)
- index = length - 1;
- while (characters[index] != matchCharacter) {
- if (!index--)
- return notFound;
- }
- return index;
+ return reverseFind(characters, length, static_cast<LChar>(matchCharacter), index);
}
inline size_t StringImpl::find(LChar character, unsigned start)