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

Side by Side Diff: src/runtime/runtime-strings.cc

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/runtime/runtime-regexp.cc ('k') | src/s390/code-stubs-s390.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/regexp/jsregexp-inl.h" 8 #include "src/regexp/jsregexp-inl.h"
9 #include "src/string-builder.h" 9 #include "src/string-builder.h"
10 #include "src/string-search.h" 10 #include "src/string-search.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 151
152 RUNTIME_FUNCTION(Runtime_InternalizeString) { 152 RUNTIME_FUNCTION(Runtime_InternalizeString) {
153 HandleScope handles(isolate); 153 HandleScope handles(isolate);
154 DCHECK(args.length() == 1); 154 DCHECK(args.length() == 1);
155 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); 155 CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
156 return *isolate->factory()->InternalizeString(string); 156 return *isolate->factory()->InternalizeString(string);
157 } 157 }
158 158
159 159
160 RUNTIME_FUNCTION(Runtime_StringMatch) {
161 HandleScope handles(isolate);
162 DCHECK(args.length() == 3);
163
164 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
165 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
166 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2);
167
168 CHECK(regexp_info->HasFastObjectElements());
169
170 RegExpImpl::GlobalCache global_cache(regexp, subject, isolate);
171 if (global_cache.HasException()) return isolate->heap()->exception();
172
173 int capture_count = regexp->CaptureCount();
174
175 Zone zone(isolate->allocator());
176 ZoneList<int> offsets(8, &zone);
177
178 while (true) {
179 int32_t* match = global_cache.FetchNext();
180 if (match == NULL) break;
181 offsets.Add(match[0], &zone); // start
182 offsets.Add(match[1], &zone); // end
183 }
184
185 if (global_cache.HasException()) return isolate->heap()->exception();
186
187 if (offsets.length() == 0) {
188 // Not a single match.
189 return isolate->heap()->null_value();
190 }
191
192 RegExpImpl::SetLastMatchInfo(regexp_info, subject, capture_count,
193 global_cache.LastSuccessfulMatch());
194
195 int matches = offsets.length() / 2;
196 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(matches);
197 Handle<String> substring =
198 isolate->factory()->NewSubString(subject, offsets.at(0), offsets.at(1));
199 elements->set(0, *substring);
200 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 1, i, i < matches, i++, {
201 int from = offsets.at(i * 2);
202 int to = offsets.at(i * 2 + 1);
203 Handle<String> substring =
204 isolate->factory()->NewProperSubString(subject, from, to);
205 elements->set(i, *substring);
206 });
207 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(elements);
208 result->set_length(Smi::FromInt(matches));
209 return *result;
210 }
211
212
213 RUNTIME_FUNCTION(Runtime_StringCharCodeAtRT) { 160 RUNTIME_FUNCTION(Runtime_StringCharCodeAtRT) {
214 HandleScope handle_scope(isolate); 161 HandleScope handle_scope(isolate);
215 DCHECK(args.length() == 2); 162 DCHECK(args.length() == 2);
216 163
217 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); 164 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
218 CONVERT_NUMBER_CHECKED(uint32_t, i, Uint32, args[1]); 165 CONVERT_NUMBER_CHECKED(uint32_t, i, Uint32, args[1]);
219 166
220 // Flatten the string. If someone wants to get a char at an index 167 // Flatten the string. If someone wants to get a char at an index
221 // in a cons string, it is likely that more indices will be 168 // in a cons string, it is likely that more indices will be
222 // accessed. 169 // accessed.
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 SealHandleScope shs(isolate); 984 SealHandleScope shs(isolate);
1038 DCHECK(args.length() == 2); 985 DCHECK(args.length() == 2);
1039 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); 986 if (!args[0]->IsString()) return isolate->heap()->undefined_value();
1040 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); 987 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value();
1041 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); 988 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value();
1042 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); 989 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate);
1043 } 990 }
1044 991
1045 } // namespace internal 992 } // namespace internal
1046 } // namespace v8 993 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-regexp.cc ('k') | src/s390/code-stubs-s390.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698