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

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

Issue 2401173002: Version 5.6.1.1 (cherry-pick) (Closed)
Patch Set: 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/isolate.cc ('k') | src/v8.gyp » ('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/conversions-inl.h" 8 #include "src/conversions-inl.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } else { 374 } else {
375 FindStringIndices(isolate, subject_vector, pattern_vector, indices, 375 FindStringIndices(isolate, subject_vector, pattern_vector, indices,
376 limit); 376 limit);
377 } 377 }
378 } 378 }
379 } 379 }
380 } 380 }
381 } 381 }
382 382
383 namespace { 383 namespace {
384 List<int>* GetRewoundRegexpIndicesList(Isolate* isolate) { 384 List<int>* GetRewindedRegexpIndicesList(Isolate* isolate) {
385 List<int>* list = isolate->regexp_indices(); 385 List<int>* list = isolate->regexp_indices();
386 list->Rewind(0); 386 list->Rewind(0);
387 return list; 387 return list;
388 } 388 }
389 389
390 void TruncateRegexpIndicesList(Isolate* isolate) { 390 void TruncateRegexpIndicesList(Isolate* isolate) {
391 // Same size as smallest zone segment, preserving behavior from the 391 // Same size as smallest zone segment, preserving behavior from the
392 // runtime zone. 392 // runtime zone.
393 static const size_t kMaxRegexpIndicesListCapacity = 8 * KB; 393 static const size_t kMaxRegexpIndicesListCapacity = 8 * KB;
394 if (isolate->regexp_indices()->capacity() > kMaxRegexpIndicesListCapacity) { 394 if (isolate->regexp_indices()->capacity() > kMaxRegexpIndicesListCapacity) {
395 isolate->regexp_indices()->Clear(); // Throw away backing storage 395 isolate->regexp_indices()->Clear(); // Throw away backing storage
396 } 396 }
397 } 397 }
398 } // namespace 398 } // namespace
399 399
400 template <typename ResultSeqString> 400 template <typename ResultSeqString>
401 MUST_USE_RESULT static Object* StringReplaceGlobalAtomRegExpWithString( 401 MUST_USE_RESULT static Object* StringReplaceGlobalAtomRegExpWithString(
402 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> pattern_regexp, 402 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> pattern_regexp,
403 Handle<String> replacement, Handle<JSObject> last_match_info) { 403 Handle<String> replacement, Handle<JSObject> last_match_info) {
404 DCHECK(subject->IsFlat()); 404 DCHECK(subject->IsFlat());
405 DCHECK(replacement->IsFlat()); 405 DCHECK(replacement->IsFlat());
406 406
407 List<int>* indices = GetRewoundRegexpIndicesList(isolate); 407 List<int>* indices = GetRewindedRegexpIndicesList(isolate);
408 408
409 DCHECK_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); 409 DCHECK_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag());
410 String* pattern = 410 String* pattern =
411 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); 411 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex));
412 int subject_len = subject->length(); 412 int subject_len = subject->length();
413 int pattern_len = pattern->length(); 413 int pattern_len = pattern->length();
414 int replacement_len = replacement->length(); 414 int replacement_len = replacement->length();
415 415
416 FindStringIndicesDispatch(isolate, *subject, pattern, indices, 0xffffffff); 416 FindStringIndicesDispatch(isolate, *subject, pattern, indices, 0xffffffff);
417 417
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 } 714 }
715 } 715 }
716 716
717 // The limit can be very large (0xffffffffu), but since the pattern 717 // The limit can be very large (0xffffffffu), but since the pattern
718 // isn't empty, we can never create more parts than ~half the length 718 // isn't empty, we can never create more parts than ~half the length
719 // of the subject. 719 // of the subject.
720 720
721 subject = String::Flatten(subject); 721 subject = String::Flatten(subject);
722 pattern = String::Flatten(pattern); 722 pattern = String::Flatten(pattern);
723 723
724 List<int>* indices = GetRewoundRegexpIndicesList(isolate); 724 List<int>* indices = GetRewindedRegexpIndicesList(isolate);
725 725
726 FindStringIndicesDispatch(isolate, *subject, *pattern, indices, limit); 726 FindStringIndicesDispatch(isolate, *subject, *pattern, indices, limit);
727 727
728 if (static_cast<uint32_t>(indices->length()) < limit) { 728 if (static_cast<uint32_t>(indices->length()) < limit) {
729 indices->Add(subject_length); 729 indices->Add(subject_length);
730 } 730 }
731 731
732 // The list indices now contains the end of each part to create. 732 // The list indices now contains the end of each part to create.
733 733
734 // Create JSArray of substrings separated by separator. 734 // Create JSArray of substrings separated by separator.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 1020
1021 1021
1022 RUNTIME_FUNCTION(Runtime_IsRegExp) { 1022 RUNTIME_FUNCTION(Runtime_IsRegExp) {
1023 SealHandleScope shs(isolate); 1023 SealHandleScope shs(isolate);
1024 DCHECK(args.length() == 1); 1024 DCHECK(args.length() == 1);
1025 CONVERT_ARG_CHECKED(Object, obj, 0); 1025 CONVERT_ARG_CHECKED(Object, obj, 0);
1026 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); 1026 return isolate->heap()->ToBoolean(obj->IsJSRegExp());
1027 } 1027 }
1028 } // namespace internal 1028 } // namespace internal
1029 } // namespace v8 1029 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698