OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 int* shift_table = good_suffix_shift_table(); | 362 int* shift_table = good_suffix_shift_table(); |
363 int* suffix_table = this->suffix_table(); | 363 int* suffix_table = this->suffix_table(); |
364 | 364 |
365 // Initialize table. | 365 // Initialize table. |
366 for (int i = start; i < pattern_length; i++) { | 366 for (int i = start; i < pattern_length; i++) { |
367 shift_table[i] = length; | 367 shift_table[i] = length; |
368 } | 368 } |
369 shift_table[pattern_length] = 1; | 369 shift_table[pattern_length] = 1; |
370 suffix_table[pattern_length] = pattern_length + 1; | 370 suffix_table[pattern_length] = pattern_length + 1; |
371 | 371 |
| 372 if (pattern_length <= start) { |
| 373 return; |
| 374 } |
| 375 |
372 // Find suffixes. | 376 // Find suffixes. |
373 PatternChar last_char = pattern[pattern_length - 1]; | 377 PatternChar last_char = pattern[pattern_length - 1]; |
374 int suffix = pattern_length + 1; | 378 int suffix = pattern_length + 1; |
375 { | 379 { |
376 int i = pattern_length; | 380 int i = pattern_length; |
377 while (i > start) { | 381 while (i > start) { |
378 PatternChar c = pattern[i - 1]; | 382 PatternChar c = pattern[i - 1]; |
379 while (suffix <= pattern_length && c != pattern[suffix - 1]) { | 383 while (suffix <= pattern_length && c != pattern[suffix - 1]) { |
380 if (shift_table[suffix] == length) { | 384 if (shift_table[suffix] == length) { |
381 shift_table[suffix] = suffix - i; | 385 shift_table[suffix] = suffix - i; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 Vector<const SubjectChar> subject, | 563 Vector<const SubjectChar> subject, |
560 Vector<const PatternChar> pattern, | 564 Vector<const PatternChar> pattern, |
561 int start_index) { | 565 int start_index) { |
562 StringSearch<PatternChar, SubjectChar> search(isolate, pattern); | 566 StringSearch<PatternChar, SubjectChar> search(isolate, pattern); |
563 return search.Search(subject, start_index); | 567 return search.Search(subject, start_index); |
564 } | 568 } |
565 | 569 |
566 }} // namespace v8::internal | 570 }} // namespace v8::internal |
567 | 571 |
568 #endif // V8_STRING_SEARCH_H_ | 572 #endif // V8_STRING_SEARCH_H_ |
OLD | NEW |