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

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

Issue 2360403003: Revert of Replaced different means of zone pooling/reusing by one zone segment pool (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/runtime/runtime-strings.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/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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 386 }
387 } 387 }
388 388
389 template <typename ResultSeqString> 389 template <typename ResultSeqString>
390 MUST_USE_RESULT static Object* StringReplaceGlobalAtomRegExpWithString( 390 MUST_USE_RESULT static Object* StringReplaceGlobalAtomRegExpWithString(
391 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> pattern_regexp, 391 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> pattern_regexp,
392 Handle<String> replacement, Handle<JSObject> last_match_info) { 392 Handle<String> replacement, Handle<JSObject> last_match_info) {
393 DCHECK(subject->IsFlat()); 393 DCHECK(subject->IsFlat());
394 DCHECK(replacement->IsFlat()); 394 DCHECK(replacement->IsFlat());
395 395
396 Zone zone(isolate->allocator()); 396 ZoneScope zone_scope(isolate->runtime_zone());
397 ZoneList<int> indices(8, &zone); 397 ZoneList<int> indices(8, zone_scope.zone());
398 DCHECK_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); 398 DCHECK_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag());
399 String* pattern = 399 String* pattern =
400 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); 400 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex));
401 int subject_len = subject->length(); 401 int subject_len = subject->length();
402 int pattern_len = pattern->length(); 402 int pattern_len = pattern->length();
403 int replacement_len = replacement->length(); 403 int replacement_len = replacement->length();
404 404
405 FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff, 405 FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff,
406 &zone); 406 zone_scope.zone());
407 407
408 int matches = indices.length(); 408 int matches = indices.length();
409 if (matches == 0) return *subject; 409 if (matches == 0) return *subject;
410 410
411 // Detect integer overflow. 411 // Detect integer overflow.
412 int64_t result_len_64 = (static_cast<int64_t>(replacement_len) - 412 int64_t result_len_64 = (static_cast<int64_t>(replacement_len) -
413 static_cast<int64_t>(pattern_len)) * 413 static_cast<int64_t>(pattern_len)) *
414 static_cast<int64_t>(matches) + 414 static_cast<int64_t>(matches) +
415 static_cast<int64_t>(subject_len); 415 static_cast<int64_t>(subject_len);
416 int result_len; 416 int result_len;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithString( 467 MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithString(
468 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp, 468 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp,
469 Handle<String> replacement, Handle<JSObject> last_match_info) { 469 Handle<String> replacement, Handle<JSObject> last_match_info) {
470 DCHECK(subject->IsFlat()); 470 DCHECK(subject->IsFlat());
471 DCHECK(replacement->IsFlat()); 471 DCHECK(replacement->IsFlat());
472 472
473 int capture_count = regexp->CaptureCount(); 473 int capture_count = regexp->CaptureCount();
474 int subject_length = subject->length(); 474 int subject_length = subject->length();
475 475
476 // CompiledReplacement uses zone allocation. 476 // CompiledReplacement uses zone allocation.
477 Zone zone(isolate->allocator()); 477 ZoneScope zone_scope(isolate->runtime_zone());
478 CompiledReplacement compiled_replacement(&zone); 478 CompiledReplacement compiled_replacement(zone_scope.zone());
479 bool simple_replace = 479 bool simple_replace =
480 compiled_replacement.Compile(replacement, capture_count, subject_length); 480 compiled_replacement.Compile(replacement, capture_count, subject_length);
481 481
482 // Shortcut for simple non-regexp global replacements 482 // Shortcut for simple non-regexp global replacements
483 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { 483 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) {
484 if (subject->HasOnlyOneByteChars() && replacement->HasOnlyOneByteChars()) { 484 if (subject->HasOnlyOneByteChars() && replacement->HasOnlyOneByteChars()) {
485 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( 485 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>(
486 isolate, subject, regexp, replacement, last_match_info); 486 isolate, subject, regexp, replacement, last_match_info);
487 } else { 487 } else {
488 return StringReplaceGlobalAtomRegExpWithString<SeqTwoByteString>( 488 return StringReplaceGlobalAtomRegExpWithString<SeqTwoByteString>(
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 // The limit can be very large (0xffffffffu), but since the pattern 705 // The limit can be very large (0xffffffffu), but since the pattern
706 // isn't empty, we can never create more parts than ~half the length 706 // isn't empty, we can never create more parts than ~half the length
707 // of the subject. 707 // of the subject.
708 708
709 subject = String::Flatten(subject); 709 subject = String::Flatten(subject);
710 pattern = String::Flatten(pattern); 710 pattern = String::Flatten(pattern);
711 711
712 static const int kMaxInitialListCapacity = 16; 712 static const int kMaxInitialListCapacity = 16;
713 713
714 Zone zone(isolate->allocator()); 714 ZoneScope zone_scope(isolate->runtime_zone());
715 715
716 // Find (up to limit) indices of separator and end-of-string in subject 716 // Find (up to limit) indices of separator and end-of-string in subject
717 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); 717 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit);
718 ZoneList<int> indices(initial_capacity, &zone); 718 ZoneList<int> indices(initial_capacity, zone_scope.zone());
719 719
720 FindStringIndicesDispatch(isolate, *subject, *pattern, &indices, limit, 720 FindStringIndicesDispatch(isolate, *subject, *pattern, &indices, limit,
721 &zone); 721 zone_scope.zone());
722 722
723 if (static_cast<uint32_t>(indices.length()) < limit) { 723 if (static_cast<uint32_t>(indices.length()) < limit) {
724 indices.Add(subject_length, &zone); 724 indices.Add(subject_length, zone_scope.zone());
725 } 725 }
726 726
727 // The list indices now contains the end of each part to create. 727 // The list indices now contains the end of each part to create.
728 728
729 // Create JSArray of substrings separated by separator. 729 // Create JSArray of substrings separated by separator.
730 int part_count = indices.length(); 730 int part_count = indices.length();
731 731
732 Handle<JSArray> result = 732 Handle<JSArray> result =
733 isolate->factory()->NewJSArray(FAST_ELEMENTS, part_count, part_count, 733 isolate->factory()->NewJSArray(FAST_ELEMENTS, part_count, part_count,
734 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); 734 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 1013
1014 1014
1015 RUNTIME_FUNCTION(Runtime_IsRegExp) { 1015 RUNTIME_FUNCTION(Runtime_IsRegExp) {
1016 SealHandleScope shs(isolate); 1016 SealHandleScope shs(isolate);
1017 DCHECK(args.length() == 1); 1017 DCHECK(args.length() == 1);
1018 CONVERT_ARG_CHECKED(Object, obj, 0); 1018 CONVERT_ARG_CHECKED(Object, obj, 0);
1019 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); 1019 return isolate->heap()->ToBoolean(obj->IsJSRegExp());
1020 } 1020 }
1021 } // namespace internal 1021 } // namespace internal
1022 } // namespace v8 1022 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/runtime/runtime-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698