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

Side by Side Diff: src/regexp/jsregexp.h

Issue 2415103002: [regexp] Turn last match info into a simple FixedArray (Closed)
Patch Set: Don't check instance type before map check Created 4 years, 2 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
« no previous file with comments | « src/ppc/code-stubs-ppc.cc ('k') | src/regexp/jsregexp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_REGEXP_JSREGEXP_H_ 5 #ifndef V8_REGEXP_JSREGEXP_H_
6 #define V8_REGEXP_JSREGEXP_H_ 6 #define V8_REGEXP_JSREGEXP_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/assembler.h" 9 #include "src/assembler.h"
10 #include "src/regexp/regexp-ast.h" 10 #include "src/regexp/regexp-ast.h"
(...skipping 30 matching lines...) Expand all
41 // the implementation wants to store in the data field. 41 // the implementation wants to store in the data field.
42 // Returns false if compilation fails. 42 // Returns false if compilation fails.
43 MUST_USE_RESULT static MaybeHandle<Object> Compile(Handle<JSRegExp> re, 43 MUST_USE_RESULT static MaybeHandle<Object> Compile(Handle<JSRegExp> re,
44 Handle<String> pattern, 44 Handle<String> pattern,
45 JSRegExp::Flags flags); 45 JSRegExp::Flags flags);
46 46
47 // See ECMA-262 section 15.10.6.2. 47 // See ECMA-262 section 15.10.6.2.
48 // This function calls the garbage collector if necessary. 48 // This function calls the garbage collector if necessary.
49 V8_EXPORT_PRIVATE MUST_USE_RESULT static MaybeHandle<Object> Exec( 49 V8_EXPORT_PRIVATE MUST_USE_RESULT static MaybeHandle<Object> Exec(
50 Handle<JSRegExp> regexp, Handle<String> subject, int index, 50 Handle<JSRegExp> regexp, Handle<String> subject, int index,
51 Handle<JSObject> lastMatchInfo); 51 Handle<RegExpMatchInfo> last_match_info);
52 52
53 // Prepares a JSRegExp object with Irregexp-specific data. 53 // Prepares a JSRegExp object with Irregexp-specific data.
54 static void IrregexpInitialize(Handle<JSRegExp> re, 54 static void IrregexpInitialize(Handle<JSRegExp> re,
55 Handle<String> pattern, 55 Handle<String> pattern,
56 JSRegExp::Flags flags, 56 JSRegExp::Flags flags,
57 int capture_register_count); 57 int capture_register_count);
58 58
59 59
60 static void AtomCompile(Handle<JSRegExp> re, 60 static void AtomCompile(Handle<JSRegExp> re,
61 Handle<String> pattern, 61 Handle<String> pattern,
62 JSRegExp::Flags flags, 62 JSRegExp::Flags flags,
63 Handle<String> match_pattern); 63 Handle<String> match_pattern);
64 64
65 65
66 static int AtomExecRaw(Handle<JSRegExp> regexp, 66 static int AtomExecRaw(Handle<JSRegExp> regexp,
67 Handle<String> subject, 67 Handle<String> subject,
68 int index, 68 int index,
69 int32_t* output, 69 int32_t* output,
70 int output_size); 70 int output_size);
71 71
72 static Handle<Object> AtomExec(Handle<JSRegExp> regexp, 72 static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
73 Handle<String> subject, int index, 73 Handle<String> subject, int index,
74 Handle<JSObject> lastMatchInfo); 74 Handle<RegExpMatchInfo> last_match_info);
75 75
76 enum IrregexpResult { RE_FAILURE = 0, RE_SUCCESS = 1, RE_EXCEPTION = -1 }; 76 enum IrregexpResult { RE_FAILURE = 0, RE_SUCCESS = 1, RE_EXCEPTION = -1 };
77 77
78 // Prepare a RegExp for being executed one or more times (using 78 // Prepare a RegExp for being executed one or more times (using
79 // IrregexpExecOnce) on the subject. 79 // IrregexpExecOnce) on the subject.
80 // This ensures that the regexp is compiled for the subject, and that 80 // This ensures that the regexp is compiled for the subject, and that
81 // the subject is flat. 81 // the subject is flat.
82 // Returns the number of integer spaces required by IrregexpExecOnce 82 // Returns the number of integer spaces required by IrregexpExecOnce
83 // as its "registers" argument. If the regexp cannot be compiled, 83 // as its "registers" argument. If the regexp cannot be compiled,
84 // an exception is set as pending, and this function returns negative. 84 // an exception is set as pending, and this function returns negative.
(...skipping 11 matching lines...) Expand all
96 int index, 96 int index,
97 int32_t* output, 97 int32_t* output,
98 int output_size); 98 int output_size);
99 99
100 // Execute an Irregexp bytecode pattern. 100 // Execute an Irregexp bytecode pattern.
101 // On a successful match, the result is a JSArray containing 101 // On a successful match, the result is a JSArray containing
102 // captured positions. On a failure, the result is the null value. 102 // captured positions. On a failure, the result is the null value.
103 // Returns an empty handle in case of an exception. 103 // Returns an empty handle in case of an exception.
104 MUST_USE_RESULT static MaybeHandle<Object> IrregexpExec( 104 MUST_USE_RESULT static MaybeHandle<Object> IrregexpExec(
105 Handle<JSRegExp> regexp, Handle<String> subject, int index, 105 Handle<JSRegExp> regexp, Handle<String> subject, int index,
106 Handle<JSObject> lastMatchInfo); 106 Handle<RegExpMatchInfo> last_match_info);
107 107
108 // Set last match info. If match is NULL, then setting captures is omitted. 108 // Set last match info. If match is NULL, then setting captures is omitted.
109 static Handle<JSObject> SetLastMatchInfo(Handle<JSObject> last_match_info, 109 static Handle<RegExpMatchInfo> SetLastMatchInfo(
110 Handle<String> subject, 110 Handle<RegExpMatchInfo> last_match_info, Handle<String> subject,
111 int capture_count, int32_t* match); 111 int capture_count, int32_t* match);
112 112
113 class GlobalCache { 113 class GlobalCache {
114 public: 114 public:
115 GlobalCache(Handle<JSRegExp> regexp, 115 GlobalCache(Handle<JSRegExp> regexp,
116 Handle<String> subject, 116 Handle<String> subject,
117 Isolate* isolate); 117 Isolate* isolate);
118 118
119 INLINE(~GlobalCache()); 119 INLINE(~GlobalCache());
120 120
121 // Fetch the next entry in the cache for global regexp match results. 121 // Fetch the next entry in the cache for global regexp match results.
(...skipping 13 matching lines...) Expand all
135 int max_matches_; 135 int max_matches_;
136 int current_match_index_; 136 int current_match_index_;
137 int registers_per_match_; 137 int registers_per_match_;
138 // Pointer to the last set of captures. 138 // Pointer to the last set of captures.
139 int32_t* register_array_; 139 int32_t* register_array_;
140 int register_array_size_; 140 int register_array_size_;
141 Handle<JSRegExp> regexp_; 141 Handle<JSRegExp> regexp_;
142 Handle<String> subject_; 142 Handle<String> subject_;
143 }; 143 };
144 144
145
146 // Array index in the lastMatchInfo array.
147 static const int kLastCaptureCount = 0;
148 static const int kLastSubject = 1;
149 static const int kLastInput = 2;
150 static const int kFirstCapture = 3;
151 static const int kLastMatchOverhead = 3;
152
153 // Direct offset into the lastMatchInfo array.
154 static const int kLastCaptureCountOffset =
155 FixedArray::kHeaderSize + kLastCaptureCount * kPointerSize;
156 static const int kLastSubjectOffset =
157 FixedArray::kHeaderSize + kLastSubject * kPointerSize;
158 static const int kLastInputOffset =
159 FixedArray::kHeaderSize + kLastInput * kPointerSize;
160 static const int kFirstCaptureOffset =
161 FixedArray::kHeaderSize + kFirstCapture * kPointerSize;
162
163 // Used to access the lastMatchInfo array.
164 static int GetCapture(FixedArray* array, int index) {
165 return Smi::cast(array->get(index + kFirstCapture))->value();
166 }
167
168 static void SetLastCaptureCount(FixedArray* array, int to) {
169 array->set(kLastCaptureCount, Smi::FromInt(to));
170 }
171
172 static void SetLastSubject(FixedArray* array, String* to) {
173 array->set(kLastSubject, to);
174 }
175
176 static void SetLastInput(FixedArray* array, String* to) {
177 array->set(kLastInput, to);
178 }
179
180 static void SetCapture(FixedArray* array, int index, int to) {
181 array->set(index + kFirstCapture, Smi::FromInt(to));
182 }
183
184 static int GetLastCaptureCount(FixedArray* array) {
185 return Smi::cast(array->get(kLastCaptureCount))->value();
186 }
187
188 // For acting on the JSRegExp data FixedArray. 145 // For acting on the JSRegExp data FixedArray.
189 static int IrregexpMaxRegisterCount(FixedArray* re); 146 static int IrregexpMaxRegisterCount(FixedArray* re);
190 static void SetIrregexpMaxRegisterCount(FixedArray* re, int value); 147 static void SetIrregexpMaxRegisterCount(FixedArray* re, int value);
191 static void SetIrregexpCaptureNameMap(FixedArray* re, 148 static void SetIrregexpCaptureNameMap(FixedArray* re,
192 Handle<FixedArray> value); 149 Handle<FixedArray> value);
193 static int IrregexpNumberOfCaptures(FixedArray* re); 150 static int IrregexpNumberOfCaptures(FixedArray* re);
194 static int IrregexpNumberOfRegisters(FixedArray* re); 151 static int IrregexpNumberOfRegisters(FixedArray* re);
195 static ByteArray* IrregexpByteCode(FixedArray* re, bool is_one_byte); 152 static ByteArray* IrregexpByteCode(FixedArray* re, bool is_one_byte);
196 static Code* IrregexpNativeCode(FixedArray* re, bool is_one_byte); 153 static Code* IrregexpNativeCode(FixedArray* re, bool is_one_byte);
197 154
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 static const int kStringOffset = 0; 1535 static const int kStringOffset = 0;
1579 static const int kPatternOffset = 1; 1536 static const int kPatternOffset = 1;
1580 static const int kArrayOffset = 2; 1537 static const int kArrayOffset = 2;
1581 static const int kLastMatchOffset = 3; 1538 static const int kLastMatchOffset = 3;
1582 }; 1539 };
1583 1540
1584 } // namespace internal 1541 } // namespace internal
1585 } // namespace v8 1542 } // namespace v8
1586 1543
1587 #endif // V8_REGEXP_JSREGEXP_H_ 1544 #endif // V8_REGEXP_JSREGEXP_H_
OLDNEW
« no previous file with comments | « src/ppc/code-stubs-ppc.cc ('k') | src/regexp/jsregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698