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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 13 matching lines...) Expand all
24 #define StringImpl_h 24 #define StringImpl_h
25 25
26 #include "wtf/ASCIICType.h" 26 #include "wtf/ASCIICType.h"
27 #include "wtf/Forward.h" 27 #include "wtf/Forward.h"
28 #include "wtf/HashMap.h" 28 #include "wtf/HashMap.h"
29 #include "wtf/StringHasher.h" 29 #include "wtf/StringHasher.h"
30 #include "wtf/Vector.h" 30 #include "wtf/Vector.h"
31 #include "wtf/WTFExport.h" 31 #include "wtf/WTFExport.h"
32 #include "wtf/text/Unicode.h" 32 #include "wtf/text/Unicode.h"
33 #include <limits.h> 33 #include <limits.h>
34 #include <string.h>
34 35
35 #if OS(MACOSX) 36 #if OS(MACOSX)
36 typedef const struct __CFString * CFStringRef; 37 typedef const struct __CFString * CFStringRef;
37 #endif 38 #endif
38 39
39 #ifdef __OBJC__ 40 #ifdef __OBJC__
40 @class NSString; 41 @class NSString;
41 #endif 42 #endif
42 43
43 namespace WTF { 44 namespace WTF {
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b, unsigned length) { return equalIgnoringASCIICase(a, reinterpret_cast<const LChar*>(b), le ngth); } 520 inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b, unsigned length) { return equalIgnoringASCIICase(a, reinterpret_cast<const LChar*>(b), le ngth); }
520 inline bool equalIgnoringASCIICase(const StringImpl* a, const LChar* b) 521 inline bool equalIgnoringASCIICase(const StringImpl* a, const LChar* b)
521 { 522 {
522 size_t length = b ? strlen(reinterpret_cast<const char*>(b)) : 0; 523 size_t length = b ? strlen(reinterpret_cast<const char*>(b)) : 0;
523 return equalIgnoringASCIICase(a, b, length); 524 return equalIgnoringASCIICase(a, b, length);
524 } 525 }
525 inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b) { return equalIgnoringASCIICase(a, reinterpret_cast<const LChar*>(b)); } 526 inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b) { return equalIgnoringASCIICase(a, reinterpret_cast<const LChar*>(b)); }
526 527
527 WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar* ); 528 WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar* );
528 529
529 template<typename CharacterType> 530 inline size_t find(const LChar* characters, unsigned length, LChar matchCharacte r, unsigned index = 0)
530 inline size_t find(const CharacterType* characters, unsigned length, CharacterTy pe matchCharacter, unsigned index = 0) 531 {
532 // 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
533 if (index >= length)
534 return kNotFound;
535 const LChar* found = static_cast<const LChar*>(
536 memchr(characters + index, matchCharacter, length - index));
537 return found ? found - characters : kNotFound;
538 }
539
540 inline size_t find(const UChar* characters, unsigned length, UChar matchCharacte r, unsigned index = 0)
531 { 541 {
532 while (index < length) { 542 while (index < length) {
533 if (characters[index] == matchCharacter) 543 if (characters[index] == matchCharacter)
534 return index; 544 return index;
535 ++index; 545 ++index;
536 } 546 }
537 return kNotFound; 547 return kNotFound;
538 } 548 }
539 549
540 ALWAYS_INLINE size_t find(const UChar* characters, unsigned length, LChar matchC haracter, unsigned index = 0) 550 ALWAYS_INLINE size_t find(const UChar* characters, unsigned length, LChar matchC haracter, unsigned index = 0)
541 { 551 {
542 return find(characters, length, static_cast<UChar>(matchCharacter), index); 552 return find(characters, length, static_cast<UChar>(matchCharacter), index);
543 } 553 }
544 554
545 inline size_t find(const LChar* characters, unsigned length, UChar matchCharacte r, unsigned index = 0) 555 inline size_t find(const LChar* characters, unsigned length, UChar matchCharacte r, unsigned index = 0)
546 { 556 {
547 if (matchCharacter & ~0xFF) 557 if (matchCharacter & ~0xFF)
548 return kNotFound; 558 return kNotFound;
549 return find(characters, length, static_cast<LChar>(matchCharacter), index); 559 return find(characters, length, static_cast<LChar>(matchCharacter), index);
550 } 560 }
551 561
562 template <typename CharacterType>
563 inline size_t find(const CharacterType* characters, unsigned length, char matchC haracter, unsigned index = 0)
564 {
565 return find(characters, length, static_cast<LChar>(matchCharacter), index);
566 }
567
552 inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunct ionPtr matchFunction, unsigned index = 0) 568 inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunct ionPtr matchFunction, unsigned index = 0)
553 { 569 {
554 while (index < length) { 570 while (index < length) {
555 if (matchFunction(characters[index])) 571 if (matchFunction(characters[index]))
556 return index; 572 return index;
557 ++index; 573 ++index;
558 } 574 }
559 return kNotFound; 575 return kNotFound;
560 } 576 }
561 577
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 786
771 using WTF::StringImpl; 787 using WTF::StringImpl;
772 using WTF::equal; 788 using WTF::equal;
773 using WTF::equalNonNull; 789 using WTF::equalNonNull;
774 using WTF::TextCaseSensitivity; 790 using WTF::TextCaseSensitivity;
775 using WTF::TextCaseSensitive; 791 using WTF::TextCaseSensitive;
776 using WTF::TextCaseASCIIInsensitive; 792 using WTF::TextCaseASCIIInsensitive;
777 using WTF::TextCaseInsensitive; 793 using WTF::TextCaseInsensitive;
778 794
779 #endif 795 #endif
OLDNEW
« 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