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

Side by Side Diff: src/jsregexp.cc

Issue 13620: * Addressed review comments (Closed)
Patch Set: Created 12 years 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/regexp-macro-assembler-ia32.cc » ('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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 Handle<Object> index) { 305 Handle<Object> index) {
306 switch (regexp->TypeTag()) { 306 switch (regexp->TypeTag()) {
307 case JSRegExp::ATOM: 307 case JSRegExp::ATOM:
308 return AtomExec(regexp, subject, index); 308 return AtomExec(regexp, subject, index);
309 case JSRegExp::IRREGEXP: { 309 case JSRegExp::IRREGEXP: {
310 Handle<Object> result = IrregexpExec(regexp, subject, index); 310 Handle<Object> result = IrregexpExec(regexp, subject, index);
311 if (!result.is_null()) { 311 if (!result.is_null()) {
312 return result; 312 return result;
313 } 313 }
314 // We couldn't handle the regexp using Irregexp, so fall back 314 // We couldn't handle the regexp using Irregexp, so fall back
315 // on JSCRE. We rejoice at the though of the day when this is 315 // on JSCRE.
316 // no longer needed.
317 // Reset the JSRegExp to use JSCRE. 316 // Reset the JSRegExp to use JSCRE.
318 JscrePrepare(regexp, 317 JscrePrepare(regexp,
319 Handle<String>(regexp->Pattern()), 318 Handle<String>(regexp->Pattern()),
320 regexp->GetFlags()); 319 regexp->GetFlags());
321 // Fall-through to JSCRE. 320 // Fall-through to JSCRE.
322 } 321 }
323 case JSRegExp::JSCRE: 322 case JSRegExp::JSCRE:
324 if (FLAG_disable_jscre) { 323 if (FLAG_disable_jscre) {
325 UNIMPLEMENTED(); 324 UNIMPLEMENTED();
326 } 325 }
327 return JscreExec(regexp, subject, index); 326 return JscreExec(regexp, subject, index);
328 default: 327 default:
329 UNREACHABLE(); 328 UNREACHABLE();
330 return Handle<Object>::null(); 329 return Handle<Object>::null();
331 } 330 }
332 } 331 }
333 332
334 333
335 Handle<Object> RegExpImpl::ExecGlobal(Handle<JSRegExp> regexp, 334 Handle<Object> RegExpImpl::ExecGlobal(Handle<JSRegExp> regexp,
336 Handle<String> subject) { 335 Handle<String> subject) {
337 switch (regexp->TypeTag()) { 336 switch (regexp->TypeTag()) {
338 case JSRegExp::ATOM: 337 case JSRegExp::ATOM:
339 return AtomExecGlobal(regexp, subject); 338 return AtomExecGlobal(regexp, subject);
340 case JSRegExp::IRREGEXP: { 339 case JSRegExp::IRREGEXP: {
341 Handle<Object> result = IrregexpExecGlobal(regexp, subject); 340 Handle<Object> result = IrregexpExecGlobal(regexp, subject);
342 if (!result.is_null()) { 341 if (!result.is_null()) {
343 return result; 342 return result;
344 } 343 }
345 // We couldn't handle the regexp using Irregexp, so fall back 344 // We couldn't handle the regexp using Irregexp, so fall back
346 // on JSCRE. We rejoice at the though of the day when this is 345 // on JSCRE.
347 // no longer needed.
348 // Reset the JSRegExp to use JSCRE. 346 // Reset the JSRegExp to use JSCRE.
349 JscrePrepare(regexp, 347 JscrePrepare(regexp,
350 Handle<String>(regexp->Pattern()), 348 Handle<String>(regexp->Pattern()),
351 regexp->GetFlags()); 349 regexp->GetFlags());
352 // Fall-through to JSCRE. 350 // Fall-through to JSCRE.
353 } 351 }
354 case JSRegExp::JSCRE: 352 case JSRegExp::JSCRE:
355 if (FLAG_disable_jscre) { 353 if (FLAG_disable_jscre) {
356 UNIMPLEMENTED(); 354 UNIMPLEMENTED();
357 } 355 }
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 } else if (shape.IsSliced()) { 902 } else if (shape.IsSliced()) {
905 SlicedString* slice = SlicedString::cast(*subject); 903 SlicedString* slice = SlicedString::cast(*subject);
906 start_offset += slice->start(); 904 start_offset += slice->start();
907 end_offset += slice->start(); 905 end_offset += slice->start();
908 subject = Handle<String>(slice->buffer()); 906 subject = Handle<String>(slice->buffer());
909 } 907 }
910 908
911 // String is now either Sequential or External 909 // String is now either Sequential or External
912 StringShape flatshape(*subject); 910 StringShape flatshape(*subject);
913 bool is_ascii = flatshape.IsAsciiRepresentation(); 911 bool is_ascii = flatshape.IsAsciiRepresentation();
914 int char_size = is_ascii ? sizeof(char) : sizeof(uc16); // NOLINT 912 int char_size_shift = is_ascii ? 0 : 1;
915 913
916 if (flatshape.IsExternal()) { 914 if (flatshape.IsExternal()) {
917 const byte* address; 915 const byte* address;
918 if (is_ascii) { 916 if (is_ascii) {
919 ExternalAsciiString* ext = ExternalAsciiString::cast(*subject); 917 ExternalAsciiString* ext = ExternalAsciiString::cast(*subject);
920 address = reinterpret_cast<const byte*>(ext->resource()->data()); 918 address = reinterpret_cast<const byte*>(ext->resource()->data());
921 } else { 919 } else {
922 ExternalTwoByteString* ext = ExternalTwoByteString::cast(*subject); 920 ExternalTwoByteString* ext = ExternalTwoByteString::cast(*subject);
923 address = reinterpret_cast<const byte*>(ext->resource()->data()); 921 address = reinterpret_cast<const byte*>(ext->resource()->data());
924 } 922 }
925 rc = RegExpMacroAssemblerIA32::Execute( 923 rc = RegExpMacroAssemblerIA32::Execute(
926 *code, 924 *code,
927 &address, 925 &address,
928 start_offset * char_size, 926 start_offset << char_size_shift,
929 end_offset * char_size, 927 end_offset << char_size_shift,
930 offsets_vector, 928 offsets_vector,
931 previous_index == 0); 929 previous_index == 0);
932 } else { // Sequential string 930 } else { // Sequential string
933 int byte_offset = 931 Address char_address =
934 is_ascii ? SeqAsciiString::kHeaderSize - kHeapObjectTag: 932 is_ascii ? SeqAsciiString::cast(*subject)->GetCharsAddress()
935 SeqTwoByteString::kHeaderSize - kHeapObjectTag; 933 : SeqTwoByteString::cast(*subject)->GetCharsAddress();
934 int byte_offset = char_address - reinterpret_cast<Address>(*subject);
936 rc = RegExpMacroAssemblerIA32::Execute( 935 rc = RegExpMacroAssemblerIA32::Execute(
937 *code, 936 *code,
938 subject.location(), 937 subject.location(),
939 byte_offset + start_offset * char_size, 938 byte_offset + (start_offset << char_size_shift),
940 byte_offset + end_offset * char_size, 939 byte_offset + (end_offset << char_size_shift),
941 offsets_vector, 940 offsets_vector,
942 previous_index == 0); 941 previous_index == 0);
943 } 942 }
944 943
945 if (rc) { 944 if (rc) {
946 // Capture values are relative to start_offset only. 945 // Capture values are relative to start_offset only.
947 for (int i = 0; i < offsets_vector_length; i++) { 946 for (int i = 0; i < offsets_vector_length; i++) {
948 if (offsets_vector[i] >= 0) { 947 if (offsets_vector[i] >= 0) {
949 offsets_vector[i] += previous_index; 948 offsets_vector[i] += previous_index;
950 } 949 }
(...skipping 2710 matching lines...) Expand 10 before | Expand all | Expand 10 after
3661 EmbeddedVector<byte, 1024> codes; 3660 EmbeddedVector<byte, 1024> codes;
3662 RegExpMacroAssemblerIrregexp macro_assembler(codes); 3661 RegExpMacroAssemblerIrregexp macro_assembler(codes);
3663 return compiler.Assemble(&macro_assembler, 3662 return compiler.Assemble(&macro_assembler,
3664 node, 3663 node,
3665 input->capture_count, 3664 input->capture_count,
3666 pattern); 3665 pattern);
3667 } 3666 }
3668 3667
3669 3668
3670 }} // namespace v8::internal 3669 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/regexp-macro-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698