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 1948543004: Switch WTF::find on LChar to use memchr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 return false; 512 return false;
512 } 513 }
513 return true; 514 return true;
514 } 515 }
515 516
516 WTF_EXPORT bool equalIgnoringASCIICase(const StringImpl*, const StringImpl*); 517 WTF_EXPORT bool equalIgnoringASCIICase(const StringImpl*, const StringImpl*);
517 WTF_EXPORT bool equalIgnoringASCIICase(const StringImpl*, const LChar*); 518 WTF_EXPORT bool equalIgnoringASCIICase(const StringImpl*, const LChar*);
518 519
519 WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar* ); 520 WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar* );
520 521
521 template<typename CharacterType> 522 inline size_t find(const LChar* characters, unsigned length, LChar matchCharacte r, unsigned index = 0)
522 inline size_t find(const CharacterType* characters, unsigned length, CharacterTy pe matchCharacter, unsigned index = 0) 523 {
524 const LChar* found = static_cast<const LChar*>(
525 memchr(characters + index, matchCharacter, length - index));
Nico 2016/05/10 17:47:06 what if index > length?
jbroman 2016/05/11 17:19:32 I'd expect that to be an error at the call site (i
526 return found ? found - characters : kNotFound;
527 }
528
529 inline size_t find(const UChar* characters, unsigned length, UChar matchCharacte r, unsigned index = 0)
523 { 530 {
524 while (index < length) { 531 while (index < length) {
525 if (characters[index] == matchCharacter) 532 if (characters[index] == matchCharacter)
526 return index; 533 return index;
527 ++index; 534 ++index;
528 } 535 }
529 return kNotFound; 536 return kNotFound;
530 } 537 }
531 538
532 ALWAYS_INLINE size_t find(const UChar* characters, unsigned length, LChar matchC haracter, unsigned index = 0) 539 ALWAYS_INLINE size_t find(const UChar* characters, unsigned length, LChar matchC haracter, unsigned index = 0)
533 { 540 {
534 return find(characters, length, static_cast<UChar>(matchCharacter), index); 541 return find(characters, length, static_cast<UChar>(matchCharacter), index);
535 } 542 }
536 543
537 inline size_t find(const LChar* characters, unsigned length, UChar matchCharacte r, unsigned index = 0) 544 inline size_t find(const LChar* characters, unsigned length, UChar matchCharacte r, unsigned index = 0)
538 { 545 {
539 if (matchCharacter & ~0xFF) 546 if (matchCharacter & ~0xFF)
540 return kNotFound; 547 return kNotFound;
541 return find(characters, length, static_cast<LChar>(matchCharacter), index); 548 return find(characters, length, static_cast<LChar>(matchCharacter), index);
542 } 549 }
543 550
551 template <typename CharacterType>
552 inline size_t find(const CharacterType* characters, unsigned length, char matchC haracter, unsigned index = 0)
553 {
554 return find(characters, length, static_cast<LChar>(matchCharacter), index);
Nico 2016/05/10 17:47:06 why cast matchCharacter to LChar?
jbroman 2016/05/11 17:19:32 To call the actual implementation above. Without t
555 }
556
544 inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunct ionPtr matchFunction, unsigned index = 0) 557 inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunct ionPtr matchFunction, unsigned index = 0)
545 { 558 {
546 while (index < length) { 559 while (index < length) {
547 if (matchFunction(characters[index])) 560 if (matchFunction(characters[index]))
548 return index; 561 return index;
549 ++index; 562 ++index;
550 } 563 }
551 return kNotFound; 564 return kNotFound;
552 } 565 }
553 566
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 775
763 using WTF::StringImpl; 776 using WTF::StringImpl;
764 using WTF::equal; 777 using WTF::equal;
765 using WTF::equalNonNull; 778 using WTF::equalNonNull;
766 using WTF::TextCaseSensitivity; 779 using WTF::TextCaseSensitivity;
767 using WTF::TextCaseSensitive; 780 using WTF::TextCaseSensitive;
768 using WTF::TextCaseASCIIInsensitive; 781 using WTF::TextCaseASCIIInsensitive;
769 using WTF::TextCaseInsensitive; 782 using WTF::TextCaseInsensitive;
770 783
771 #endif 784 #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