OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_STRING_SEARCH_H_ | 5 #ifndef V8_STRING_SEARCH_H_ |
6 #define V8_STRING_SEARCH_H_ | 6 #define V8_STRING_SEARCH_H_ |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 // of the string, but it is a safe approximation. | 23 // of the string, but it is a safe approximation. |
24 static const int kBMMaxShift = Isolate::kBMMaxShift; | 24 static const int kBMMaxShift = Isolate::kBMMaxShift; |
25 | 25 |
26 // Reduce alphabet to this size. | 26 // Reduce alphabet to this size. |
27 // One of the tables used by Boyer-Moore and Boyer-Moore-Horspool has size | 27 // One of the tables used by Boyer-Moore and Boyer-Moore-Horspool has size |
28 // proportional to the input alphabet. We reduce the alphabet size by | 28 // proportional to the input alphabet. We reduce the alphabet size by |
29 // equating input characters modulo a smaller alphabet size. This gives | 29 // equating input characters modulo a smaller alphabet size. This gives |
30 // a potentially less efficient searching, but is a safe approximation. | 30 // a potentially less efficient searching, but is a safe approximation. |
31 // For needles using only characters in the same Unicode 256-code point page, | 31 // For needles using only characters in the same Unicode 256-code point page, |
32 // there is no search speed degradation. | 32 // there is no search speed degradation. |
33 static const int kAsciiAlphabetSize = 256; | 33 static const int kLatin1AlphabetSize = 256; |
34 static const int kUC16AlphabetSize = Isolate::kUC16AlphabetSize; | 34 static const int kUC16AlphabetSize = Isolate::kUC16AlphabetSize; |
35 | 35 |
36 // Bad-char shift table stored in the state. It's length is the alphabet size. | 36 // Bad-char shift table stored in the state. It's length is the alphabet size. |
37 // For patterns below this length, the skip length of Boyer-Moore is too short | 37 // For patterns below this length, the skip length of Boyer-Moore is too short |
38 // to compensate for the algorithmic overhead compared to simple brute force. | 38 // to compensate for the algorithmic overhead compared to simple brute force. |
39 static const int kBMMinPatternLength = 7; | 39 static const int kBMMinPatternLength = 7; |
40 | 40 |
41 static inline bool IsOneByteString(Vector<const uint8_t> string) { | 41 static inline bool IsOneByteString(Vector<const uint8_t> string) { |
42 return true; | 42 return true; |
43 } | 43 } |
(...skipping 30 matching lines...) Expand all Loading... |
74 } | 74 } |
75 strategy_ = &InitialSearch; | 75 strategy_ = &InitialSearch; |
76 } | 76 } |
77 | 77 |
78 int Search(Vector<const SubjectChar> subject, int index) { | 78 int Search(Vector<const SubjectChar> subject, int index) { |
79 return strategy_(this, subject, index); | 79 return strategy_(this, subject, index); |
80 } | 80 } |
81 | 81 |
82 static inline int AlphabetSize() { | 82 static inline int AlphabetSize() { |
83 if (sizeof(PatternChar) == 1) { | 83 if (sizeof(PatternChar) == 1) { |
84 // ASCII needle. | 84 // Latin1 needle. |
85 return kAsciiAlphabetSize; | 85 return kLatin1AlphabetSize; |
86 } else { | 86 } else { |
87 DCHECK(sizeof(PatternChar) == 2); | 87 DCHECK(sizeof(PatternChar) == 2); |
88 // UC16 needle. | 88 // UC16 needle. |
89 return kUC16AlphabetSize; | 89 return kUC16AlphabetSize; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 private: | 93 private: |
94 typedef int (*SearchFunction)( // NOLINT - it's not a cast! | 94 typedef int (*SearchFunction)( // NOLINT - it's not a cast! |
95 StringSearch<PatternChar, SubjectChar>*, | 95 StringSearch<PatternChar, SubjectChar>*, |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 Vector<const SubjectChar> subject, | 548 Vector<const SubjectChar> subject, |
549 Vector<const PatternChar> pattern, | 549 Vector<const PatternChar> pattern, |
550 int start_index) { | 550 int start_index) { |
551 StringSearch<PatternChar, SubjectChar> search(isolate, pattern); | 551 StringSearch<PatternChar, SubjectChar> search(isolate, pattern); |
552 return search.Search(subject, start_index); | 552 return search.Search(subject, start_index); |
553 } | 553 } |
554 | 554 |
555 }} // namespace v8::internal | 555 }} // namespace v8::internal |
556 | 556 |
557 #endif // V8_STRING_SEARCH_H_ | 557 #endif // V8_STRING_SEARCH_H_ |
OLD | NEW |