OLD | NEW |
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 Loading... |
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 = |
| 239 needle->GetFlatContent(no_heap_allocation); |
| 240 String::FlatContent subject_content = |
| 241 subject->GetFlatContent(no_heap_allocation); |
| 242 ASSERT(needle_content.IsFlat()); |
| 243 ASSERT(subject_content.IsFlat()); |
250 // dispatch on type of strings | 244 // dispatch on type of strings |
251 index = (needle->IsAsciiRepresentation() | 245 index = (needle_content.IsAscii() |
252 ? (seq_sub->IsAsciiRepresentation() | 246 ? (subject_content.IsAscii() |
253 ? SearchString(isolate, | 247 ? SearchString(isolate, |
254 seq_sub->ToAsciiVector(), | 248 subject_content.ToAsciiVector(), |
255 needle->ToAsciiVector(), | 249 needle_content.ToAsciiVector(), |
256 index) | 250 index) |
257 : SearchString(isolate, | 251 : SearchString(isolate, |
258 seq_sub->ToUC16Vector(), | 252 subject_content.ToUC16Vector(), |
259 needle->ToAsciiVector(), | 253 needle_content.ToAsciiVector(), |
260 index)) | 254 index)) |
261 : (seq_sub->IsAsciiRepresentation() | 255 : (subject_content.IsAscii() |
262 ? SearchString(isolate, | 256 ? SearchString(isolate, |
263 seq_sub->ToAsciiVector(), | 257 subject_content.ToAsciiVector(), |
264 needle->ToUC16Vector(), | 258 needle_content.ToUC16Vector(), |
265 index) | 259 index) |
266 : SearchString(isolate, | 260 : SearchString(isolate, |
267 seq_sub->ToUC16Vector(), | 261 subject_content.ToUC16Vector(), |
268 needle->ToUC16Vector(), | 262 needle_content.ToUC16Vector(), |
269 index))); | 263 index))); |
270 if (index == -1) return isolate->factory()->null_value(); | 264 if (index == -1) return isolate->factory()->null_value(); |
271 } | 265 } |
272 ASSERT(last_match_info->HasFastElements()); | 266 ASSERT(last_match_info->HasFastElements()); |
273 | 267 |
274 { | 268 { |
275 NoHandleAllocation no_handles; | 269 NoHandleAllocation no_handles; |
276 FixedArray* array = FixedArray::cast(last_match_info->elements()); | 270 FixedArray* array = FixedArray::cast(last_match_info->elements()); |
277 SetAtomLastCapture(array, *subject, index, index + needle_len); | 271 SetAtomLastCapture(array, *subject, index, index + needle_len); |
278 } | 272 } |
(...skipping 5078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5357 } | 5351 } |
5358 | 5352 |
5359 return compiler.Assemble(¯o_assembler, | 5353 return compiler.Assemble(¯o_assembler, |
5360 node, | 5354 node, |
5361 data->capture_count, | 5355 data->capture_count, |
5362 pattern); | 5356 pattern); |
5363 } | 5357 } |
5364 | 5358 |
5365 | 5359 |
5366 }} // namespace v8::internal | 5360 }} // namespace v8::internal |
OLD | NEW |