Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: src/jsregexp.cc

Issue 6533: * Added simplified Boyer-Moore-Horspool text search. (Closed)
Patch Set: Included comments from review Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 Handle<String> subject, 211 Handle<String> subject,
212 Handle<Object> index) { 212 Handle<Object> index) {
213 Handle<String> needle(String::cast(re->data())); 213 Handle<String> needle(String::cast(re->data()));
214 214
215 uint32_t start_index; 215 uint32_t start_index;
216 if (!Array::IndexFromObject(*index, &start_index)) { 216 if (!Array::IndexFromObject(*index, &start_index)) {
217 return Handle<Smi>(Smi::FromInt(-1)); 217 return Handle<Smi>(Smi::FromInt(-1));
218 } 218 }
219 219
220 LOG(RegExpExecEvent(re, start_index, subject)); 220 LOG(RegExpExecEvent(re, start_index, subject));
221 int value = Runtime::StringMatchKmp(subject, needle, start_index); 221 int value = Runtime::StringMatch(subject, needle, start_index);
222 if (value == -1) return Factory::null_value(); 222 if (value == -1) return Factory::null_value();
223 Handle<JSArray> result = Factory::NewJSArray(2); 223 Handle<JSArray> result = Factory::NewJSArray(2);
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 int index = 0; 234 int index = 0;
235 int match_count = 0; 235 int match_count = 0;
236 int subject_length = subject->length(); 236 int subject_length = subject->length();
237 int needle_length = needle->length(); 237 int needle_length = needle->length();
238 while (true) { 238 while (true) {
239 LOG(RegExpExecEvent(re, index, subject)); 239 LOG(RegExpExecEvent(re, index, subject));
240 int value = -1; 240 int value = -1;
241 if (index + needle_length <= subject_length) { 241 if (index + needle_length <= subject_length) {
242 value = Runtime::StringMatchKmp(subject, needle, index); 242 value = Runtime::StringMatch(subject, needle, index);
243 } 243 }
244 if (value == -1) break; 244 if (value == -1) break;
245 HandleScope scope; 245 HandleScope scope;
246 int end = value + needle_length; 246 int end = value + needle_length;
247 Handle<JSArray> pair = Factory::NewJSArray(2); 247 Handle<JSArray> pair = Factory::NewJSArray(2);
248 SetElement(pair, 0, Handle<Smi>(Smi::FromInt(value))); 248 SetElement(pair, 0, Handle<Smi>(Smi::FromInt(value)));
249 SetElement(pair, 1, Handle<Smi>(Smi::FromInt(end))); 249 SetElement(pair, 1, Handle<Smi>(Smi::FromInt(end)));
250 SetElement(result, match_count, pair); 250 SetElement(result, match_count, pair);
251 match_count++; 251 match_count++;
252 index = end; 252 index = end;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 491 }
492 492
493 493
494 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) { 494 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) {
495 Object* value = re->data(); 495 Object* value = re->data();
496 ASSERT(value->IsFixedArray()); 496 ASSERT(value->IsFixedArray());
497 return ByteArray::cast(FixedArray::cast(value)->get(INTERNAL_INDEX)); 497 return ByteArray::cast(FixedArray::cast(value)->get(INTERNAL_INDEX));
498 } 498 }
499 499
500 }} // namespace v8::internal 500 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698