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

Side by Side Diff: src/factory.cc

Issue 247093002: Do not avoid flattening cons string when creating a string slice. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | no next file » | 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 "factory.h" 5 #include "factory.h"
6 6
7 #include "macro-assembler.h" 7 #include "macro-assembler.h"
8 #include "isolate-inl.h" 8 #include "isolate-inl.h"
9 #include "v8conversions.h" 9 #include "v8conversions.h"
10 10
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 525
526 526
527 Handle<String> Factory::NewProperSubString(Handle<String> str, 527 Handle<String> Factory::NewProperSubString(Handle<String> str,
528 int begin, 528 int begin,
529 int end) { 529 int end) {
530 #if VERIFY_HEAP 530 #if VERIFY_HEAP
531 if (FLAG_verify_heap) str->StringVerify(); 531 if (FLAG_verify_heap) str->StringVerify();
532 #endif 532 #endif
533 ASSERT(begin > 0 || end < str->length()); 533 ASSERT(begin > 0 || end < str->length());
534 534
535 str = String::Flatten(str);
536
535 int length = end - begin; 537 int length = end - begin;
536 if (length <= 0) return empty_string(); 538 if (length <= 0) return empty_string();
537 if (length == 1) { 539 if (length == 1) {
538 return LookupSingleCharacterStringFromCode(str->Get(begin)); 540 return LookupSingleCharacterStringFromCode(str->Get(begin));
539 } 541 }
540 if (length == 2) { 542 if (length == 2) {
541 // Optimization for 2-byte strings often used as keys in a decompression 543 // Optimization for 2-byte strings often used as keys in a decompression
542 // dictionary. Check whether we already have the string in the string 544 // dictionary. Check whether we already have the string in the string
543 // table to prevent creation of many unnecessary strings. 545 // table to prevent creation of many unnecessary strings.
544 uint16_t c1 = str->Get(begin); 546 uint16_t c1 = str->Get(begin);
(...skipping 14 matching lines...) Expand all
559 NewRawTwoByteString(length).ToHandleChecked(); 561 NewRawTwoByteString(length).ToHandleChecked();
560 uc16* dest = result->GetChars(); 562 uc16* dest = result->GetChars();
561 DisallowHeapAllocation no_gc; 563 DisallowHeapAllocation no_gc;
562 String::WriteToFlat(*str, dest, begin, end); 564 String::WriteToFlat(*str, dest, begin, end);
563 return result; 565 return result;
564 } 566 }
565 } 567 }
566 568
567 int offset = begin; 569 int offset = begin;
568 570
569 while (str->IsConsString()) {
570 Handle<ConsString> cons = Handle<ConsString>::cast(str);
571 int split = cons->first()->length();
572 if (split <= offset) {
573 // Slice is fully contained in the second part.
574 str = Handle<String>(cons->second(), isolate());
575 offset -= split; // Adjust for offset.
576 continue;
577 } else if (offset + length <= split) {
578 // Slice is fully contained in the first part.
579 str = Handle<String>(cons->first(), isolate());
580 continue;
581 }
582 break;
583 }
584
585 if (str->IsSlicedString()) { 571 if (str->IsSlicedString()) {
586 Handle<SlicedString> slice = Handle<SlicedString>::cast(str); 572 Handle<SlicedString> slice = Handle<SlicedString>::cast(str);
587 str = Handle<String>(slice->parent(), isolate()); 573 str = Handle<String>(slice->parent(), isolate());
588 offset += slice->offset(); 574 offset += slice->offset();
589 } else {
590 str = String::Flatten(str);
591 } 575 }
592 576
593 ASSERT(str->IsSeqString() || str->IsExternalString()); 577 ASSERT(str->IsSeqString() || str->IsExternalString());
594 Handle<SlicedString> slice = NewRawSlicedString( 578 Handle<SlicedString> slice = NewRawSlicedString(
595 str->IsOneByteRepresentation() ? String::ONE_BYTE_ENCODING 579 str->IsOneByteRepresentation() ? String::ONE_BYTE_ENCODING
596 : String::TWO_BYTE_ENCODING); 580 : String::TWO_BYTE_ENCODING);
597 581
598 slice->set_hash_field(String::kEmptyHashField); 582 slice->set_hash_field(String::kEmptyHashField);
599 slice->set_length(length); 583 slice->set_length(length);
600 slice->set_parent(*str); 584 slice->set_parent(*str);
(...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 return Handle<Object>::null(); 2336 return Handle<Object>::null();
2353 } 2337 }
2354 2338
2355 2339
2356 Handle<Object> Factory::ToBoolean(bool value) { 2340 Handle<Object> Factory::ToBoolean(bool value) {
2357 return value ? true_value() : false_value(); 2341 return value ? true_value() : false_value();
2358 } 2342 }
2359 2343
2360 2344
2361 } } // namespace v8::internal 2345 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698