Chromium Code Reviews| Index: src/runtime.cc |
| diff --git a/src/runtime.cc b/src/runtime.cc |
| index a15e1f50539de0b18ac3d4526f83d63cb1076eb5..ba41459d02707ef4ec1ee43a4aeaac0fe27f9ed4 100644 |
| --- a/src/runtime.cc |
| +++ b/src/runtime.cc |
| @@ -2762,6 +2762,23 @@ void FindAsciiStringIndices(Vector<const char> subject, |
| } |
| +void FindTwoByteStringIndices(const Vector<const uc16> subject, |
| + uc16 pattern, |
| + ZoneList<int>* indices, |
| + unsigned int limit, |
| + Zone* zone) { |
| + ASSERT(limit > 0); |
| + const uc16* subject_start = subject.start(); |
| + const uc16* subject_end = subject_start + subject.length(); |
| + for (const uc16* pos = subject_start; pos < subject_end && limit > 0; pos++) { |
| + if (*pos == pattern) { |
| + indices->Add(static_cast<int>(pos - subject_start), zone); |
| + limit--; |
| + } |
| + } |
| +} |
| + |
| + |
| template <typename SubjectChar, typename PatternChar> |
| void FindStringIndices(Isolate* isolate, |
| Vector<const SubjectChar> subject, |
| @@ -2825,13 +2842,22 @@ void FindStringIndicesDispatch(Isolate* isolate, |
| } |
| } else { |
| Vector<const uc16> subject_vector = subject_content.ToUC16Vector(); |
| - if (pattern_content.IsAscii()) { |
| - FindStringIndices(isolate, |
| - subject_vector, |
| - pattern_content.ToAsciiVector(), |
| - indices, |
| - limit, |
| - zone); |
| + if (pattern_content.Length() == 1) { |
| + uc16 pattern_char = pattern_content.IsAscii() ? |
| + pattern_content.ToAsciiVector()[0] : |
| + pattern_content.ToUC16Vector()[0]; |
| + FindTwoByteStringIndices(subject_vector, |
| + pattern_char, |
| + indices, |
| + limit, |
| + zone); |
| + } else if (pattern_content.IsAscii()) { |
| + FindStringIndices(isolate, |
| + subject_vector, |
| + pattern_content.ToAsciiVector(), |
| + indices, |
| + limit, |
| + zone); |
|
Yang
2012/11/26 08:45:30
Since we are doing the IsAscii() check (implied in
|
| } else { |
| FindStringIndices(isolate, |
| subject_vector, |