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

Unified Diff: src/regexp-macro-assembler-ia32.cc

Issue 42115: Faster string.replace with regexp pattern. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: src/regexp-macro-assembler-ia32.cc
diff --git a/src/regexp-macro-assembler-ia32.cc b/src/regexp-macro-assembler-ia32.cc
index 34834608360fe8bb18d5a3b287210a9dcf8ef26d..07b91c029ea4dc0fe0aaefe8b746eb95b26d3b8c 100644
--- a/src/regexp-macro-assembler-ia32.cc
+++ b/src/regexp-macro-assembler-ia32.cc
@@ -978,6 +978,84 @@ void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) {
}
+
+RegExpMacroAssemblerIA32::Result RegExpMacroAssemblerIA32::Match(
+ Handle<Code> regexp_code,
+ Handle<String> subject,
+ int* offsets_vector,
+ int offsets_vector_length,
+ int previous_index) {
+ StringShape shape(*subject);
+
+ // Character offsets into string.
+ int start_offset = previous_index;
+ int end_offset = subject->length(shape);
+
+ String* subject_ptr = *subject;
Erik Corry 2009/03/12 10:13:00 Please add an AssertNoAllocation object here.
Lasse Reichstein 2009/03/13 08:36:51 Rewritten to use handles everywhere.
+ if (shape.IsCons()) {
+ subject_ptr = String::cast(ConsString::cast(subject_ptr)->first());
+ } else if (shape.IsSliced()) {
+ SlicedString* slice = SlicedString::cast(subject_ptr);
+ start_offset += slice->start();
+ end_offset += slice->start();
+ subject_ptr = String::cast(slice->buffer());
+ }
+
+ // String is now either Sequential or External
+ StringShape flatshape(subject_ptr);
+ bool is_ascii = flatshape.IsAsciiRepresentation();
+ int char_size_shift = is_ascii ? 0 : 1;
+
+ RegExpMacroAssemblerIA32::Result res;
+
+ if (flatshape.IsExternal()) {
+ const byte* address;
+ if (is_ascii) {
+ ExternalAsciiString* ext = ExternalAsciiString::cast(subject_ptr);
+ address = reinterpret_cast<const byte*>(ext->resource()->data());
+ } else {
+ ExternalTwoByteString* ext = ExternalTwoByteString::cast(subject_ptr);
+ address = reinterpret_cast<const byte*>(ext->resource()->data());
+ }
+ res = Execute(*regexp_code,
+ const_cast<Address*>(&address),
+ start_offset << char_size_shift,
+ end_offset << char_size_shift,
+ offsets_vector,
+ previous_index == 0);
+ } else { // Sequential string
+ ASSERT(StringShape(subject_ptr).IsSequential());
+ Address char_address =
+ is_ascii ? SeqAsciiString::cast(subject_ptr)->GetCharsAddress()
+ : SeqTwoByteString::cast(subject_ptr)->GetCharsAddress();
+ int byte_offset = char_address - reinterpret_cast<Address>(subject_ptr);
+ Handle<String> flat_subject_handle;
+ if (*subject == subject_ptr) {
+ flat_subject_handle = subject;
+ } else {
+ flat_subject_handle = Handle<String>(subject_ptr);
+ }
+ res = Execute(*regexp_code,
+ reinterpret_cast<Address*>(flat_subject_handle.location()),
+ byte_offset + (start_offset << char_size_shift),
+ byte_offset + (end_offset << char_size_shift),
+ offsets_vector,
+ previous_index == 0);
+ }
+
+ if (res == RegExpMacroAssemblerIA32::SUCCESS) {
+ // Capture values are relative to start_offset only.
+ for (int i = 0; i < offsets_vector_length; i++) {
+ if (offsets_vector[i] >= 0) {
+ offsets_vector[i] += previous_index;
+ }
+ }
+ }
+
+ return res;
+}
+
+
// Private methods:

Powered by Google App Engine
This is Rietveld 408576698