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

Unified Diff: src/jsregexp.h

Issue 28184: Avoids allocating a JSArray of capture information on each non-global... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 10 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 | « no previous file | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/jsregexp.h
===================================================================
--- src/jsregexp.h (revision 1374)
+++ src/jsregexp.h (working copy)
@@ -59,13 +59,15 @@
// This function calls the garbage collector if necessary.
static Handle<Object> Exec(Handle<JSRegExp> regexp,
Handle<String> subject,
- Handle<Object> index);
+ Smi* index,
+ Handle<JSArray> lastMatchInfo);
// Call RegExp.prototyp.exec(string) in a loop.
// Used by String.prototype.match and String.prototype.replace.
// This function calls the garbage collector if necessary.
static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp,
- Handle<String> subject);
+ Handle<String> subject,
+ Handle<JSArray> lastMatchInfo);
// Prepares a JSRegExp object with Irregexp-specific data.
static Handle<Object> IrregexpPrepare(Handle<JSRegExp> re,
@@ -79,18 +81,22 @@
Handle<String> match_pattern);
static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
Handle<String> subject,
- Handle<Object> index);
+ Smi* index,
+ Handle<JSArray> lastMatchInfo);
static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp,
- Handle<String> subject);
+ Handle<String> subject,
+ Handle<JSArray> lastMatchInfo);
// Execute an Irregexp bytecode pattern.
static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp,
Handle<String> subject,
- Handle<Object> index);
+ Smi* index,
+ Handle<JSArray> lastMatchInfo);
static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp,
- Handle<String> subject);
+ Handle<String> subject,
+ Handle<JSArray> lastMatchInfo);
static void NewSpaceCollectionPrologue();
static void OldSpaceCollectionPrologue();
@@ -107,6 +113,30 @@
static const int kIrregexpCodeIndex = 3;
static const int kIrregexpDataLength = 4;
+ // Offsets in the lastMatchInfo array.
+ static const int kLastCaptureCount = 0;
+ static const int kLastSubject = 1;
+ static const int kLastInput = 2;
+ static const int kFirstCapture = 1;
+ static const int kLastMatchOverhead = 3;
+ static int GetCapture(FixedArray* array, int index) {
+ return Smi::cast(array->get(index + kFirstCapture))->value();
+ }
+ static void SetLastCaptureCount(FixedArray* array, int to) {
+ array->set(kLastCaptureCount, Smi::FromInt(to));
+ }
+ static void SetLastSubject(FixedArray* array, String* to) {
+ int capture_count = GetLastCaptureCount(array);
+ array->set(capture_count + kLastSubject, to);
+ }
+ static void SetLastInput(FixedArray* array, String* to) {
+ int capture_count = GetLastCaptureCount(array);
+ array->set(capture_count + kLastInput, to);
+ }
+ static void SetCapture(FixedArray* array, int index, int to) {
+ array->set(index + kFirstCapture, Smi::FromInt(to));
+ }
+
private:
static String* last_ascii_string_;
static String* two_byte_cached_string_;
@@ -121,6 +151,7 @@
// Returns an empty handle in case of an exception.
static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp,
int num_captures,
+ Handle<JSArray> lastMatchInfo,
Handle<String> subject16,
int previous_index,
int* ovector,
@@ -134,6 +165,10 @@
int character_position,
int utf8_position);
+ // Used to access the lastMatchInfo array.
+ static int GetLastCaptureCount(FixedArray* array) {
+ return Smi::cast(array->get(kLastCaptureCount))->value();
+ }
// A one element cache of the last utf8_subject string and its length. The
// subject JS String object is cached in the heap. We also cache a
// translation between position and utf8 position.
« no previous file with comments | « no previous file | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698