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

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

Issue 2043063003: Reland: Switch WTF::find on LChar to use memchr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/StringImpl.h
diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.h b/third_party/WebKit/Source/wtf/text/StringImpl.h
index 49c950eba9e480fbc88facdc5565a5b7dfd4e510..22897f18998bd09c2e5588c9f36090b7af8920bc 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.h
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.h
@@ -31,6 +31,7 @@
#include "wtf/WTFExport.h"
#include "wtf/text/Unicode.h"
#include <limits.h>
+#include <string.h>
#if OS(MACOSX)
typedef const struct __CFString * CFStringRef;
@@ -526,8 +527,17 @@ inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b) { return
WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar*);
-template<typename CharacterType>
-inline size_t find(const CharacterType* characters, unsigned length, CharacterType matchCharacter, unsigned index = 0)
+inline size_t find(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = 0)
+{
+ // Some clients rely on being able to pass index >= length.
Nico 2016/06/10 19:09:14 should the clients be fixed instead?
jbroman 2016/06/10 19:15:13 In my ideal world (in which nobody passes out-of-r
+ if (index >= length)
+ return kNotFound;
+ const LChar* found = static_cast<const LChar*>(
+ memchr(characters + index, matchCharacter, length - index));
+ return found ? found - characters : kNotFound;
+}
+
+inline size_t find(const UChar* characters, unsigned length, UChar matchCharacter, unsigned index = 0)
{
while (index < length) {
if (characters[index] == matchCharacter)
@@ -549,6 +559,12 @@ inline size_t find(const LChar* characters, unsigned length, UChar matchCharacte
return find(characters, length, static_cast<LChar>(matchCharacter), index);
}
+template <typename CharacterType>
+inline size_t find(const CharacterType* characters, unsigned length, char matchCharacter, unsigned index = 0)
+{
+ return find(characters, length, static_cast<LChar>(matchCharacter), index);
+}
+
inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunctionPtr matchFunction, unsigned index = 0)
{
while (index < length) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698