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

Side by Side Diff: src/regexp-macro-assembler-ia32.cc

Issue 42115: Faster string.replace with regexp pattern. (Closed)
Patch Set: Addressed review comments Created 11 years, 9 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
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 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 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 } 971 }
972 972
973 973
974 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) { 974 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) {
975 __ mov(eax, backtrack_stackpointer()); 975 __ mov(eax, backtrack_stackpointer());
976 __ sub(eax, Operand(ebp, kStackHighEnd)); 976 __ sub(eax, Operand(ebp, kStackHighEnd));
977 __ mov(register_location(reg), eax); 977 __ mov(register_location(reg), eax);
978 } 978 }
979 979
980 980
981
982 RegExpMacroAssemblerIA32::Result RegExpMacroAssemblerIA32::Match(
983 Handle<Code> regexp_code,
984 Handle<String> subject,
985 int* offsets_vector,
986 int offsets_vector_length,
987 int previous_index) {
988 StringShape shape(*subject);
989
990 // Character offsets into string.
991 int start_offset = previous_index;
992 int end_offset = subject->length(shape);
993
994 if (shape.IsCons()) {
995 subject =
996 Handle<String>(String::cast(ConsString::cast(*subject)->first()));
997 } else if (shape.IsSliced()) {
998 SlicedString* slice = SlicedString::cast(*subject);
999 start_offset += slice->start();
1000 end_offset += slice->start();
1001 subject = Handle<String>(String::cast(slice->buffer()));
1002 }
1003
1004 // String is now either Sequential or External
1005 StringShape flatshape(*subject);
1006 bool is_ascii = flatshape.IsAsciiRepresentation();
1007 int char_size_shift = is_ascii ? 0 : 1;
1008
1009 RegExpMacroAssemblerIA32::Result res;
1010
1011 if (flatshape.IsExternal()) {
1012 const byte* address;
1013 if (is_ascii) {
1014 ExternalAsciiString* ext = ExternalAsciiString::cast(*subject);
1015 address = reinterpret_cast<const byte*>(ext->resource()->data());
1016 } else {
1017 ExternalTwoByteString* ext = ExternalTwoByteString::cast(*subject);
1018 address = reinterpret_cast<const byte*>(ext->resource()->data());
1019 }
1020
1021 res = Execute(*regexp_code,
1022 const_cast<Address*>(&address),
1023 start_offset << char_size_shift,
1024 end_offset << char_size_shift,
1025 offsets_vector,
1026 previous_index == 0);
1027 } else { // Sequential string
1028 ASSERT(StringShape(*subject).IsSequential());
1029 Address char_address =
1030 is_ascii ? SeqAsciiString::cast(*subject)->GetCharsAddress()
1031 : SeqTwoByteString::cast(*subject)->GetCharsAddress();
1032 int byte_offset = char_address - reinterpret_cast<Address>(*subject);
1033 res = Execute(*regexp_code,
1034 reinterpret_cast<Address*>(subject.location()),
1035 byte_offset + (start_offset << char_size_shift),
1036 byte_offset + (end_offset << char_size_shift),
1037 offsets_vector,
1038 previous_index == 0);
1039 }
1040
1041 if (res == RegExpMacroAssemblerIA32::SUCCESS) {
1042 // Capture values are relative to start_offset only.
1043 for (int i = 0; i < offsets_vector_length; i++) {
1044 if (offsets_vector[i] >= 0) {
1045 offsets_vector[i] += previous_index;
1046 }
1047 }
1048 }
1049
1050 return res;
1051 }
1052
1053
981 // Private methods: 1054 // Private methods:
982 1055
983 1056
984 static unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize; 1057 static unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize;
985 1058
986 RegExpMacroAssemblerIA32::Result RegExpMacroAssemblerIA32::Execute( 1059 RegExpMacroAssemblerIA32::Result RegExpMacroAssemblerIA32::Execute(
987 Code* code, 1060 Code* code,
988 Address* input, 1061 Address* input,
989 int start_offset, 1062 int start_offset,
990 int end_offset, 1063 int end_offset,
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 1325
1253 1326
1254 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, 1327 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg,
1255 ArraySlice* buffer) { 1328 ArraySlice* buffer) {
1256 __ mov(reg, buffer->array()); 1329 __ mov(reg, buffer->array());
1257 __ add(Operand(reg), Immediate(buffer->base_offset())); 1330 __ add(Operand(reg), Immediate(buffer->base_offset()));
1258 } 1331 }
1259 1332
1260 #undef __ 1333 #undef __
1261 }} // namespace v8::internal 1334 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler-ia32.h ('k') | src/runtime.h » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698