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

Side by Side 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, 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/jsregexp.cc » ('j') | src/jsregexp.cc » ('J')
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // generic data and choice of implementation - as well as what 52 // generic data and choice of implementation - as well as what
53 // the implementation wants to store in the data field. 53 // the implementation wants to store in the data field.
54 static Handle<Object> Compile(Handle<JSRegExp> re, 54 static Handle<Object> Compile(Handle<JSRegExp> re,
55 Handle<String> pattern, 55 Handle<String> pattern,
56 Handle<String> flags); 56 Handle<String> flags);
57 57
58 // See ECMA-262 section 15.10.6.2. 58 // See ECMA-262 section 15.10.6.2.
59 // This function calls the garbage collector if necessary. 59 // This function calls the garbage collector if necessary.
60 static Handle<Object> Exec(Handle<JSRegExp> regexp, 60 static Handle<Object> Exec(Handle<JSRegExp> regexp,
61 Handle<String> subject, 61 Handle<String> subject,
62 Handle<Object> index); 62 Smi* index,
63 Handle<JSArray> lastMatchInfo);
63 64
64 // Call RegExp.prototyp.exec(string) in a loop. 65 // Call RegExp.prototyp.exec(string) in a loop.
65 // Used by String.prototype.match and String.prototype.replace. 66 // Used by String.prototype.match and String.prototype.replace.
66 // This function calls the garbage collector if necessary. 67 // This function calls the garbage collector if necessary.
67 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp, 68 static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp,
68 Handle<String> subject); 69 Handle<String> subject,
70 Handle<JSArray> lastMatchInfo);
69 71
70 // Prepares a JSRegExp object with Irregexp-specific data. 72 // Prepares a JSRegExp object with Irregexp-specific data.
71 static Handle<Object> IrregexpPrepare(Handle<JSRegExp> re, 73 static Handle<Object> IrregexpPrepare(Handle<JSRegExp> re,
72 Handle<String> pattern, 74 Handle<String> pattern,
73 JSRegExp::Flags flags); 75 JSRegExp::Flags flags);
74 76
75 77
76 static Handle<Object> AtomCompile(Handle<JSRegExp> re, 78 static Handle<Object> AtomCompile(Handle<JSRegExp> re,
77 Handle<String> pattern, 79 Handle<String> pattern,
78 JSRegExp::Flags flags, 80 JSRegExp::Flags flags,
79 Handle<String> match_pattern); 81 Handle<String> match_pattern);
80 static Handle<Object> AtomExec(Handle<JSRegExp> regexp, 82 static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
81 Handle<String> subject, 83 Handle<String> subject,
82 Handle<Object> index); 84 Smi* index,
85 Handle<JSArray> lastMatchInfo);
83 86
84 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp, 87 static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp,
85 Handle<String> subject); 88 Handle<String> subject,
89 Handle<JSArray> lastMatchInfo);
86 90
87 // Execute an Irregexp bytecode pattern. 91 // Execute an Irregexp bytecode pattern.
88 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp, 92 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp,
89 Handle<String> subject, 93 Handle<String> subject,
90 Handle<Object> index); 94 Smi* index,
95 Handle<JSArray> lastMatchInfo);
91 96
92 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp, 97 static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp,
93 Handle<String> subject); 98 Handle<String> subject,
99 Handle<JSArray> lastMatchInfo);
94 100
95 static void NewSpaceCollectionPrologue(); 101 static void NewSpaceCollectionPrologue();
96 static void OldSpaceCollectionPrologue(); 102 static void OldSpaceCollectionPrologue();
97 103
98 // Converts a source string to a 16 bit flat string. The string 104 // Converts a source string to a 16 bit flat string. The string
99 // will be either sequential or it will be a SlicedString backed 105 // will be either sequential or it will be a SlicedString backed
100 // by a flat string. 106 // by a flat string.
101 static Handle<String> StringToTwoByte(Handle<String> pattern); 107 static Handle<String> StringToTwoByte(Handle<String> pattern);
102 static Handle<String> CachedStringToTwoByte(Handle<String> pattern); 108 static Handle<String> CachedStringToTwoByte(Handle<String> pattern);
103 109
104 static const int kIrregexpImplementationIndex = 0; 110 static const int kIrregexpImplementationIndex = 0;
105 static const int kIrregexpNumberOfCapturesIndex = 1; 111 static const int kIrregexpNumberOfCapturesIndex = 1;
106 static const int kIrregexpNumberOfRegistersIndex = 2; 112 static const int kIrregexpNumberOfRegistersIndex = 2;
107 static const int kIrregexpCodeIndex = 3; 113 static const int kIrregexpCodeIndex = 3;
108 static const int kIrregexpDataLength = 4; 114 static const int kIrregexpDataLength = 4;
109 115
116 // Offsets in the lastMatchInfo array.
117 static const int kLastCaptureCount = 0;
118 static const int kLastSubject = 1;
119 static const int kLastInput = 2;
120 static const int kFirstCapture = 1;
121 static const int kLastMatchOverhead = 3;
122 static int GetCapture(FixedArray* array, int index) {
123 return Smi::cast(array->get(index + kFirstCapture))->value();
124 }
125 static void SetLastCaptureCount(FixedArray* array, int to) {
126 array->set(kLastCaptureCount, Smi::FromInt(to));
127 }
128 static void SetLastSubject(FixedArray* array, String* to) {
129 int capture_count = GetLastCaptureCount(array);
130 array->set(capture_count + kLastSubject, to);
131 }
132 static void SetLastInput(FixedArray* array, String* to) {
133 int capture_count = GetLastCaptureCount(array);
134 array->set(capture_count + kLastInput, to);
135 }
136 static void SetCapture(FixedArray* array, int index, int to) {
137 array->set(index + kFirstCapture, Smi::FromInt(to));
138 }
139
110 private: 140 private:
111 static String* last_ascii_string_; 141 static String* last_ascii_string_;
112 static String* two_byte_cached_string_; 142 static String* two_byte_cached_string_;
113 143
114 static int IrregexpNumberOfCaptures(Handle<FixedArray> re); 144 static int IrregexpNumberOfCaptures(Handle<FixedArray> re);
115 static int IrregexpNumberOfRegisters(Handle<FixedArray> re); 145 static int IrregexpNumberOfRegisters(Handle<FixedArray> re);
116 static Handle<ByteArray> IrregexpByteCode(Handle<FixedArray> re); 146 static Handle<ByteArray> IrregexpByteCode(Handle<FixedArray> re);
117 static Handle<Code> IrregexpNativeCode(Handle<FixedArray> re); 147 static Handle<Code> IrregexpNativeCode(Handle<FixedArray> re);
118 148
119 // On a successful match, the result is a JSArray containing 149 // On a successful match, the result is a JSArray containing
120 // captured positions. On a failure, the result is the null value. 150 // captured positions. On a failure, the result is the null value.
121 // Returns an empty handle in case of an exception. 151 // Returns an empty handle in case of an exception.
122 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp, 152 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp,
123 int num_captures, 153 int num_captures,
154 Handle<JSArray> lastMatchInfo,
124 Handle<String> subject16, 155 Handle<String> subject16,
125 int previous_index, 156 int previous_index,
126 int* ovector, 157 int* ovector,
127 int ovector_length); 158 int ovector_length);
128 159
129 // Set the subject cache. The previous string buffer is not deleted, so the 160 // Set the subject cache. The previous string buffer is not deleted, so the
130 // caller should ensure that it doesn't leak. 161 // caller should ensure that it doesn't leak.
131 static void SetSubjectCache(String* subject, 162 static void SetSubjectCache(String* subject,
132 char* utf8_subject, 163 char* utf8_subject,
133 int uft8_length, 164 int uft8_length,
134 int character_position, 165 int character_position,
135 int utf8_position); 166 int utf8_position);
136 167
168 // Used to access the lastMatchInfo array.
169 static int GetLastCaptureCount(FixedArray* array) {
170 return Smi::cast(array->get(kLastCaptureCount))->value();
171 }
137 // A one element cache of the last utf8_subject string and its length. The 172 // A one element cache of the last utf8_subject string and its length. The
138 // subject JS String object is cached in the heap. We also cache a 173 // subject JS String object is cached in the heap. We also cache a
139 // translation between position and utf8 position. 174 // translation between position and utf8 position.
140 static char* utf8_subject_cache_; 175 static char* utf8_subject_cache_;
141 static int utf8_length_cache_; 176 static int utf8_length_cache_;
142 static int utf8_position_; 177 static int utf8_position_;
143 static int character_position_; 178 static int character_position_;
144 }; 179 };
145 180
146 181
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 Handle<String> pattern, 1360 Handle<String> pattern,
1326 bool is_ascii); 1361 bool is_ascii);
1327 1362
1328 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); 1363 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
1329 }; 1364 };
1330 1365
1331 1366
1332 } } // namespace v8::internal 1367 } } // namespace v8::internal
1333 1368
1334 #endif // V8_JSREGEXP_H_ 1369 #endif // V8_JSREGEXP_H_
OLDNEW
« 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