| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 memset(bad_char_occurrence, | 178 memset(bad_char_occurrence, |
| 179 -1, | 179 -1, |
| 180 table_size * sizeof(*bad_char_occurrence)); | 180 table_size * sizeof(*bad_char_occurrence)); |
| 181 } else { | 181 } else { |
| 182 for (int i = 0; i < table_size; i++) { | 182 for (int i = 0; i < table_size; i++) { |
| 183 bad_char_occurrence[i] = start - 1; | 183 bad_char_occurrence[i] = start - 1; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 for (int i = start; i < pattern.length() - 1; i++) { | 186 for (int i = start; i < pattern.length() - 1; i++) { |
| 187 PatternChar c = pattern[i]; | 187 PatternChar c = pattern[i]; |
| 188 int bucket = (sizeof(PatternChar) ==1) ? c : c % RuntimeState::kBMAlphabetSi
ze; | 188 int bucket = (sizeof(PatternChar) ==1) |
| 189 ? c : c % RuntimeState::kBMAlphabetSize; |
| 189 bad_char_occurrence[bucket] = i; | 190 bad_char_occurrence[bucket] = i; |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 | 193 |
| 193 | 194 |
| 194 template <typename PatternChar> | 195 template <typename PatternChar> |
| 195 static void BoyerMoorePopulateGoodSuffixTable(RuntimeState* state, | 196 static void BoyerMoorePopulateGoodSuffixTable( |
| 196 Vector<const PatternChar> pattern)
{ | 197 RuntimeState* state, Vector<const PatternChar> pattern) { |
| 197 RuntimeState::BMGoodSuffixBuffers& bmgs_buffers = *state->bmgs_buffers(); | 198 RuntimeState::BMGoodSuffixBuffers& bmgs_buffers = *state->bmgs_buffers(); |
| 198 int m = pattern.length(); | 199 int m = pattern.length(); |
| 199 int start = m < RuntimeState::kBMMaxShift ? 0 : m - RuntimeState::kBMMaxShift; | 200 int start = m < RuntimeState::kBMMaxShift ? 0 : m - RuntimeState::kBMMaxShift; |
| 200 int len = m - start; | 201 int len = m - start; |
| 201 // Compute Good Suffix tables. | 202 // Compute Good Suffix tables. |
| 202 bmgs_buffers.Initialize(m); | 203 bmgs_buffers.Initialize(m); |
| 203 | 204 |
| 204 bmgs_buffers.shift(m-1) = 1; | 205 bmgs_buffers.shift(m-1) = 1; |
| 205 bmgs_buffers.suffix(m) = m + 1; | 206 bmgs_buffers.suffix(m) = m + 1; |
| 206 PatternChar last_char = pattern[m - 1]; | 207 PatternChar last_char = pattern[m - 1]; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 case SEARCH_SHORT: return SimpleIndexOf(sub, pat, start_index); | 527 case SEARCH_SHORT: return SimpleIndexOf(sub, pat, start_index); |
| 527 case SEARCH_LONG: return ComplexIndexOf(state, sub, pat, start_index); | 528 case SEARCH_LONG: return ComplexIndexOf(state, sub, pat, start_index); |
| 528 } | 529 } |
| 529 UNREACHABLE(); | 530 UNREACHABLE(); |
| 530 return -1; | 531 return -1; |
| 531 } | 532 } |
| 532 | 533 |
| 533 }} // namespace v8::internal | 534 }} // namespace v8::internal |
| 534 | 535 |
| 535 #endif // V8_STRING_SEARCH_H_ | 536 #endif // V8_STRING_SEARCH_H_ |
| OLD | NEW |