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

Side by Side Diff: src/jsregexp.cc

Issue 7709024: Replace ToAsciiVector and ToUC16Vector with single function that returns a tagged value. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 int from, 205 int from,
206 int to) { 206 int to) {
207 NoHandleAllocation no_handles; 207 NoHandleAllocation no_handles;
208 RegExpImpl::SetLastCaptureCount(array, 2); 208 RegExpImpl::SetLastCaptureCount(array, 2);
209 RegExpImpl::SetLastSubject(array, subject); 209 RegExpImpl::SetLastSubject(array, subject);
210 RegExpImpl::SetLastInput(array, subject); 210 RegExpImpl::SetLastInput(array, subject);
211 RegExpImpl::SetCapture(array, 0, from); 211 RegExpImpl::SetCapture(array, 0, from);
212 RegExpImpl::SetCapture(array, 1, to); 212 RegExpImpl::SetCapture(array, 1, to);
213 } 213 }
214 214
215 /* template <typename SubjectChar>, typename PatternChar>
216 static int ReStringMatch(Vector<const SubjectChar> sub_vector,
217 Vector<const PatternChar> pat_vector,
218 int start_index) {
219 215
220 int pattern_length = pat_vector.length();
221 if (pattern_length == 0) return start_index;
222
223 int subject_length = sub_vector.length();
224 if (start_index + pattern_length > subject_length) return -1;
225 return SearchString(sub_vector, pat_vector, start_index);
226 }
227 */
228 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, 216 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re,
229 Handle<String> subject, 217 Handle<String> subject,
230 int index, 218 int index,
231 Handle<JSArray> last_match_info) { 219 Handle<JSArray> last_match_info) {
232 Isolate* isolate = re->GetIsolate(); 220 Isolate* isolate = re->GetIsolate();
233 221
234 ASSERT(0 <= index); 222 ASSERT(0 <= index);
235 ASSERT(index <= subject->length()); 223 ASSERT(index <= subject->length());
236 224
237 if (!subject->IsFlat()) FlattenString(subject); 225 if (!subject->IsFlat()) FlattenString(subject);
238 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid 226 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
239 // Extract flattened substrings of cons strings before determining asciiness. 227 // Extract flattened substrings of cons strings before determining asciiness.
240 String* seq_sub = *subject;
241 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first();
242 228
243 String* needle = String::cast(re->DataAt(JSRegExp::kAtomPatternIndex)); 229 String* needle = String::cast(re->DataAt(JSRegExp::kAtomPatternIndex));
244 int needle_len = needle->length(); 230 int needle_len = needle->length();
231 ASSERT(needle->IsFlat());
245 232
246 if (needle_len != 0) { 233 if (needle_len != 0) {
247 if (index + needle_len > subject->length()) 234 if (index + needle_len > subject->length()) {
248 return isolate->factory()->null_value(); 235 return isolate->factory()->null_value();
236 }
249 237
238 String::FlatContent needle_content = needle->GetFlatContent();
239 String::FlatContent subject_content = subject->GetFlatContent();
240 ASSERT(needle_content.IsFlat());
241 ASSERT(subject_content.IsFlat());
250 // dispatch on type of strings 242 // dispatch on type of strings
251 index = (needle->IsAsciiRepresentation() 243 index = (needle_content.IsAscii()
252 ? (seq_sub->IsAsciiRepresentation() 244 ? (subject_content.IsAscii()
253 ? SearchString(isolate, 245 ? SearchString(isolate,
254 seq_sub->ToAsciiVector(), 246 subject_content.ToAsciiVector(),
255 needle->ToAsciiVector(), 247 needle_content.ToAsciiVector(),
256 index) 248 index)
257 : SearchString(isolate, 249 : SearchString(isolate,
258 seq_sub->ToUC16Vector(), 250 subject_content.ToUC16Vector(),
259 needle->ToAsciiVector(), 251 needle_content.ToAsciiVector(),
260 index)) 252 index))
261 : (seq_sub->IsAsciiRepresentation() 253 : (subject_content.IsAscii()
262 ? SearchString(isolate, 254 ? SearchString(isolate,
263 seq_sub->ToAsciiVector(), 255 subject_content.ToAsciiVector(),
264 needle->ToUC16Vector(), 256 needle_content.ToUC16Vector(),
265 index) 257 index)
266 : SearchString(isolate, 258 : SearchString(isolate,
267 seq_sub->ToUC16Vector(), 259 subject_content.ToUC16Vector(),
268 needle->ToUC16Vector(), 260 needle_content.ToUC16Vector(),
269 index))); 261 index)));
270 if (index == -1) return isolate->factory()->null_value(); 262 if (index == -1) return isolate->factory()->null_value();
271 } 263 }
272 ASSERT(last_match_info->HasFastElements()); 264 ASSERT(last_match_info->HasFastElements());
273 265
274 { 266 {
275 NoHandleAllocation no_handles; 267 NoHandleAllocation no_handles;
276 FixedArray* array = FixedArray::cast(last_match_info->elements()); 268 FixedArray* array = FixedArray::cast(last_match_info->elements());
277 SetAtomLastCapture(array, *subject, index, index + needle_len); 269 SetAtomLastCapture(array, *subject, index, index + needle_len);
278 } 270 }
(...skipping 5078 matching lines...) Expand 10 before | Expand all | Expand 10 after
5357 } 5349 }
5358 5350
5359 return compiler.Assemble(&macro_assembler, 5351 return compiler.Assemble(&macro_assembler,
5360 node, 5352 node,
5361 data->capture_count, 5353 data->capture_count,
5362 pattern); 5354 pattern);
5363 } 5355 }
5364 5356
5365 5357
5366 }} // namespace v8::internal 5358 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/interpreter-irregexp.cc ('k') | src/objects.h » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698