| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 SetElement(result, 0, Handle<Smi>(Smi::FromInt(value))); | 224 SetElement(result, 0, Handle<Smi>(Smi::FromInt(value))); |
| 225 SetElement(result, 1, Handle<Smi>(Smi::FromInt(value + needle->length()))); | 225 SetElement(result, 1, Handle<Smi>(Smi::FromInt(value + needle->length()))); |
| 226 return result; | 226 return result; |
| 227 } | 227 } |
| 228 | 228 |
| 229 | 229 |
| 230 Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re, | 230 Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re, |
| 231 Handle<String> subject) { | 231 Handle<String> subject) { |
| 232 Handle<String> needle(String::cast(re->data())); | 232 Handle<String> needle(String::cast(re->data())); |
| 233 Handle<JSArray> result = Factory::NewJSArray(1); | 233 Handle<JSArray> result = Factory::NewJSArray(1); |
| 234 bool keep_going = true; | |
| 235 int index = 0; | 234 int index = 0; |
| 236 int match_count = 0; | 235 int match_count = 0; |
| 236 int subject_length = subject->length(); |
| 237 int needle_length = needle->length(); | 237 int needle_length = needle->length(); |
| 238 while (keep_going) { | 238 while (true) { |
| 239 LOG(RegExpExecEvent(re, index, subject)); | 239 LOG(RegExpExecEvent(re, index, subject)); |
| 240 int value = Runtime::StringMatchKmp(*subject, *needle, index); | 240 int value = -1; |
| 241 if (index + needle_length <= subject_length) { |
| 242 value = Runtime::StringMatchKmp(*subject, *needle, index); |
| 243 } |
| 241 if (value == -1) break; | 244 if (value == -1) break; |
| 242 HandleScope scope; | 245 HandleScope scope; |
| 243 int end = value + needle_length; | 246 int end = value + needle_length; |
| 244 Handle<JSArray> pair = Factory::NewJSArray(2); | 247 Handle<JSArray> pair = Factory::NewJSArray(2); |
| 245 SetElement(pair, 0, Handle<Smi>(Smi::FromInt(value))); | 248 SetElement(pair, 0, Handle<Smi>(Smi::FromInt(value))); |
| 246 SetElement(pair, 1, Handle<Smi>(Smi::FromInt(end))); | 249 SetElement(pair, 1, Handle<Smi>(Smi::FromInt(end))); |
| 247 SetElement(result, match_count, pair); | 250 SetElement(result, match_count, pair); |
| 248 match_count++; | 251 match_count++; |
| 249 index = end; | 252 index = end; |
| 250 if (needle_length == 0) | 253 if (needle_length == 0) |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 } | 491 } |
| 489 | 492 |
| 490 | 493 |
| 491 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) { | 494 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) { |
| 492 Object* value = re->data(); | 495 Object* value = re->data(); |
| 493 ASSERT(value->IsFixedArray()); | 496 ASSERT(value->IsFixedArray()); |
| 494 return ByteArray::cast(FixedArray::cast(value)->get(INTERNAL_INDEX)); | 497 return ByteArray::cast(FixedArray::cast(value)->get(INTERNAL_INDEX)); |
| 495 } | 498 } |
| 496 | 499 |
| 497 }} // namespace v8::internal | 500 }} // namespace v8::internal |
| OLD | NEW |