Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1092)

Unified Diff: third_party/WebKit/Source/wtf/text/StringImpl.cpp

Issue 2226363003: Use StringView for String::reverseFind. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/StringImpl.cpp
diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.cpp b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
index e05c0317396b063a0b17ba5ae6e8708e269067f1..850f9865ac606198c28768a81febec66f40264c6 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
@@ -1317,7 +1317,7 @@ size_t StringImpl::reverseFind(UChar c, unsigned index)
}
template <typename SearchCharacterType, typename MatchCharacterType>
-ALWAYS_INLINE static size_t reverseFindInner(const SearchCharacterType* searchCharacters, const MatchCharacterType* matchCharacters, unsigned index, unsigned length, unsigned matchLength)
+ALWAYS_INLINE static size_t reverseFindInternal(const SearchCharacterType* searchCharacters, const MatchCharacterType* matchCharacters, unsigned index, unsigned length, unsigned matchLength)
{
// Optimization: keep a running hash of the strings,
// only call equal if the hashes match.
@@ -1343,12 +1343,12 @@ ALWAYS_INLINE static size_t reverseFindInner(const SearchCharacterType* searchCh
return delta;
}
-size_t StringImpl::reverseFind(StringImpl* matchString, unsigned index)
+size_t StringImpl::reverseFind(const StringView& matchString, unsigned index)
{
- // Check for null or empty string to match against
- if (!matchString)
+ if (UNLIKELY(matchString.isNull()))
return kNotFound;
- unsigned matchLength = matchString->length();
+
+ unsigned matchLength = matchString.length();
unsigned ourLength = length();
if (!matchLength)
return min(index, ourLength);
@@ -1356,8 +1356,8 @@ size_t StringImpl::reverseFind(StringImpl* matchString, unsigned index)
// Optimization 1: fast case for strings of length 1.
if (matchLength == 1) {
if (is8Bit())
- return WTF::reverseFind(characters8(), ourLength, (*matchString)[0], index);
- return WTF::reverseFind(characters16(), ourLength, (*matchString)[0], index);
+ return WTF::reverseFind(characters8(), ourLength, matchString[0], index);
+ return WTF::reverseFind(characters16(), ourLength, matchString[0], index);
}
// Check index & matchLength are in range.
@@ -1365,15 +1365,13 @@ size_t StringImpl::reverseFind(StringImpl* matchString, unsigned index)
return kNotFound;
if (is8Bit()) {
- if (matchString->is8Bit())
- return reverseFindInner(characters8(), matchString->characters8(), index, ourLength, matchLength);
- return reverseFindInner(characters8(), matchString->characters16(), index, ourLength, matchLength);
+ if (matchString.is8Bit())
+ return reverseFindInternal(characters8(), matchString.characters8(), index, ourLength, matchLength);
+ return reverseFindInternal(characters8(), matchString.characters16(), index, ourLength, matchLength);
}
-
- if (matchString->is8Bit())
- return reverseFindInner(characters16(), matchString->characters8(), index, ourLength, matchLength);
-
- return reverseFindInner(characters16(), matchString->characters16(), index, ourLength, matchLength);
+ if (matchString.is8Bit())
+ return reverseFindInternal(characters16(), matchString.characters8(), index, ourLength, matchLength);
+ return reverseFindInternal(characters16(), matchString.characters16(), index, ourLength, matchLength);
}
bool StringImpl::startsWith(UChar character) const
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698