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

Unified Diff: src/jsregexp.cc

Issue 48061: Remapped regexp last-match-info to put subject and index before match indices. (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
« no previous file with comments | « src/jsregexp.h ('k') | src/macros.py » ('j') | src/regexp-delay.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/jsregexp.cc
diff --git a/src/jsregexp.cc b/src/jsregexp.cc
index 7acf639b524c40d4e787b7956b9447a25071efb9..068b0a7549ef99e1b996c88c4550011308c20b84 100644
--- a/src/jsregexp.cc
+++ b/src/jsregexp.cc
@@ -307,9 +307,10 @@ Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re,
// that is attached to the global RegExp object. We will be returning
// an array of these.
Handle<FixedArray> array = Factory::NewFixedArray(kFirstCapture + 2);
+ SetLastCaptureCount(*array, 2);
+ // Ignore subject and input fields.
SetCapture(*array, 0, value);
SetCapture(*array, 1, end);
- SetLastCaptureCount(*array, 2);
Handle<JSArray> pair = Factory::NewJSArrayWithElements(array);
SetElement(result, match_count, pair);
match_count++;
@@ -561,22 +562,22 @@ Handle<Object> RegExpImpl::IrregexpExecGlobal(Handle<JSRegExp> regexp,
// Create an array that looks like the static last_match_info array
// that is attached to the global RegExp object. We will be returning
// an array of these.
- Handle<FixedArray> matches_array(JSArray::cast(*matches)->elements());
+ int match_length = kFirstCapture + number_of_capture_registers;
Handle<JSArray> latest_match =
- Factory::NewJSArray(kFirstCapture + number_of_capture_registers);
- Handle<FixedArray> latest_match_array(latest_match->elements());
-
- for (int i = 0; i < number_of_capture_registers; i++) {
- SetCapture(*latest_match_array, i, GetCapture(*matches_array, i));
- }
- SetLastCaptureCount(*latest_match_array, number_of_capture_registers);
-
+ Factory::NewJSArray(match_length);
+
+ AssertNoAllocation no_allocation;
+ FixedArray* match_array = JSArray::cast(*matches)->elements();
+ match_array->CopyTo(0,
+ latest_match->elements(),
+ 0,
+ match_length);
SetElement(result, result_length, latest_match);
result_length++;
- previous_index = GetCapture(*matches_array, 1);
- if (GetCapture(*matches_array, 0) == previous_index)
+ previous_index = GetCapture(match_array, 1);
+ if (GetCapture(match_array, 0) == previous_index) {
previous_index++;
-
+ }
} else {
ASSERT(matches->IsNull());
return result;
@@ -636,18 +637,15 @@ Handle<Object> RegExpImpl::IrregexpExecOnce(Handle<FixedArray> regexp,
}
FixedArray* array = last_match_info->elements();
- // Clear previous input/string values to avoid potential memory leak.
- SetLastSubject(array, Heap::empty_string());
- SetLastInput(array, Heap::empty_string());
ASSERT(array->length() >= number_of_capture_registers + kLastMatchOverhead);
// The captures come in (start, end+1) pairs.
- for (int i = 0; i < number_of_capture_registers; i += 2) {
- SetCapture(array, i, offsets_vector[i]);
- SetCapture(array, i + 1, offsets_vector[i + 1]);
- }
SetLastCaptureCount(array, number_of_capture_registers);
SetLastSubject(array, *original_subject);
SetLastInput(array, *original_subject);
+ for (int i = 0; i < number_of_capture_registers; i+=2) {
+ SetCapture(array, i, offsets_vector[i]);
+ SetCapture(array, i + 1, offsets_vector[i + 1]);
+ }
return last_match_info;
}
« no previous file with comments | « src/jsregexp.h ('k') | src/macros.py » ('j') | src/regexp-delay.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698