OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (index > subject_length - pattern_length) { | 327 if (index > subject_length - pattern_length) { |
328 return -1; | 328 return -1; |
329 } | 329 } |
330 } | 330 } |
331 while (j >= 0 && pattern[j] == (c = subject[index + j])) j--; | 331 while (j >= 0 && pattern[j] == (c = subject[index + j])) j--; |
332 if (j < 0) { | 332 if (j < 0) { |
333 return index; | 333 return index; |
334 } else if (j < start) { | 334 } else if (j < start) { |
335 // we have matched more than our tables allow us to be smart about. | 335 // we have matched more than our tables allow us to be smart about. |
336 // Fall back on BMH shift. | 336 // Fall back on BMH shift. |
337 index += | 337 index += pattern_length - 1 |
338 pattern_length - 1 - CharOccurrence(bad_char_occurence, last_char); | 338 - CharOccurrence(bad_char_occurence, |
| 339 static_cast<SubjectChar>(last_char)); |
339 } else { | 340 } else { |
340 int gs_shift = good_suffix_shift[j + 1]; | 341 int gs_shift = good_suffix_shift[j + 1]; |
341 int bc_occ = | 342 int bc_occ = |
342 CharOccurrence(bad_char_occurence, c); | 343 CharOccurrence(bad_char_occurence, c); |
343 int shift = j - bc_occ; | 344 int shift = j - bc_occ; |
344 if (gs_shift > shift) { | 345 if (gs_shift > shift) { |
345 shift = gs_shift; | 346 shift = gs_shift; |
346 } | 347 } |
347 index += shift; | 348 index += shift; |
348 } | 349 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 int start_index) { | 426 int start_index) { |
426 Vector<const PatternChar> pattern = search->pattern_; | 427 Vector<const PatternChar> pattern = search->pattern_; |
427 int subject_length = subject.length(); | 428 int subject_length = subject.length(); |
428 int pattern_length = pattern.length(); | 429 int pattern_length = pattern.length(); |
429 int* char_occurrences = search->bad_char_table(); | 430 int* char_occurrences = search->bad_char_table(); |
430 int badness = -pattern_length; | 431 int badness = -pattern_length; |
431 | 432 |
432 // How bad we are doing without a good-suffix table. | 433 // How bad we are doing without a good-suffix table. |
433 PatternChar last_char = pattern[pattern_length - 1]; | 434 PatternChar last_char = pattern[pattern_length - 1]; |
434 int last_char_shift = pattern_length - 1 - | 435 int last_char_shift = pattern_length - 1 - |
435 CharOccurrence(char_occurrences, last_char); | 436 CharOccurrence(char_occurrences, static_cast<SubjectChar>(last_char)); |
436 // Perform search | 437 // Perform search |
437 int index = start_index; // No matches found prior to this index. | 438 int index = start_index; // No matches found prior to this index. |
438 while (index <= subject_length - pattern_length) { | 439 while (index <= subject_length - pattern_length) { |
439 int j = pattern_length - 1; | 440 int j = pattern_length - 1; |
440 int subject_char; | 441 int subject_char; |
441 while (last_char != (subject_char = subject[index + j])) { | 442 while (last_char != (subject_char = subject[index + j])) { |
442 int bc_occ = CharOccurrence(char_occurrences, subject_char); | 443 int bc_occ = CharOccurrence(char_occurrences, subject_char); |
443 int shift = j - bc_occ; | 444 int shift = j - bc_occ; |
444 index += shift; | 445 index += shift; |
445 badness += 1 - shift; // at most zero, so badness cannot increase. | 446 badness += 1 - shift; // at most zero, so badness cannot increase. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 static int SearchString(Vector<const SubjectChar> subject, | 563 static int SearchString(Vector<const SubjectChar> subject, |
563 Vector<const PatternChar> pattern, | 564 Vector<const PatternChar> pattern, |
564 int start_index) { | 565 int start_index) { |
565 StringSearch<PatternChar, SubjectChar> search(pattern); | 566 StringSearch<PatternChar, SubjectChar> search(pattern); |
566 return search.Search(subject, start_index); | 567 return search.Search(subject, start_index); |
567 } | 568 } |
568 | 569 |
569 }} // namespace v8::internal | 570 }} // namespace v8::internal |
570 | 571 |
571 #endif // V8_STRING_SEARCH_H_ | 572 #endif // V8_STRING_SEARCH_H_ |
OLD | NEW |