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

Side by Side Diff: src/objects.cc

Issue 2762008: Track ascii-ness of data in externalized strings. (Closed)
Patch Set: Extended tests. Created 10 years, 6 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
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 cs->set_second(Heap::empty_string()); 671 cs->set_second(Heap::empty_string());
672 return result; 672 return result;
673 } 673 }
674 default: 674 default:
675 return this; 675 return this;
676 } 676 }
677 } 677 }
678 678
679 679
680 bool String::MakeExternal(v8::String::ExternalStringResource* resource) { 680 bool String::MakeExternal(v8::String::ExternalStringResource* resource) {
681 // Externalizing twice leaks the external resouce, so it's
682 // prohibited by the API.
683 ASSERT(!this->IsExternalString());
681 #ifdef DEBUG 684 #ifdef DEBUG
682 if (FLAG_enable_slow_asserts) { 685 if (FLAG_enable_slow_asserts) {
683 // Assert that the resource and the string are equivalent. 686 // Assert that the resource and the string are equivalent.
684 ASSERT(static_cast<size_t>(this->length()) == resource->length()); 687 ASSERT(static_cast<size_t>(this->length()) == resource->length());
685 ScopedVector<uc16> smart_chars(this->length()); 688 ScopedVector<uc16> smart_chars(this->length());
686 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 689 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
687 ASSERT(memcmp(smart_chars.start(), 690 ASSERT(memcmp(smart_chars.start(),
688 resource->data(), 691 resource->data(),
689 resource->length() * sizeof(smart_chars[0])) == 0); 692 resource->length() * sizeof(smart_chars[0])) == 0);
690 } 693 }
691 #endif // DEBUG 694 #endif // DEBUG
692 695
693 int size = this->Size(); // Byte size of the original string. 696 int size = this->Size(); // Byte size of the original string.
694 if (size < ExternalString::kSize) { 697 if (size < ExternalString::kSize) {
695 // The string is too small to fit an external String in its place. This can 698 // The string is too small to fit an external String in its place. This can
696 // only happen for zero length strings. 699 // only happen for zero length strings.
697 return false; 700 return false;
698 } 701 }
699 ASSERT(size >= ExternalString::kSize); 702 ASSERT(size >= ExternalString::kSize);
703 bool is_ascii = this->IsAsciiRepresentation();
700 bool is_symbol = this->IsSymbol(); 704 bool is_symbol = this->IsSymbol();
701 int length = this->length(); 705 int length = this->length();
702 int hash_field = this->hash_field(); 706 int hash_field = this->hash_field();
703 707
704 // Morph the object to an external string by adjusting the map and 708 // Morph the object to an external string by adjusting the map and
705 // reinitializing the fields. 709 // reinitializing the fields.
706 this->set_map(Heap::external_string_map()); 710 this->set_map(is_ascii ?
711 Heap::external_string_with_ascii_data_map() :
712 Heap::external_string_map());
707 ExternalTwoByteString* self = ExternalTwoByteString::cast(this); 713 ExternalTwoByteString* self = ExternalTwoByteString::cast(this);
708 self->set_length(length); 714 self->set_length(length);
709 self->set_hash_field(hash_field); 715 self->set_hash_field(hash_field);
710 self->set_resource(resource); 716 self->set_resource(resource);
711 // Additionally make the object into an external symbol if the original string 717 // Additionally make the object into an external symbol if the original string
712 // was a symbol to start with. 718 // was a symbol to start with.
713 if (is_symbol) { 719 if (is_symbol) {
714 self->Hash(); // Force regeneration of the hash value. 720 self->Hash(); // Force regeneration of the hash value.
715 // Now morph this external string into a external symbol. 721 // Now morph this external string into a external symbol.
716 this->set_map(Heap::external_symbol_map()); 722 this->set_map(is_ascii ?
723 Heap::external_symbol_with_ascii_data_map() :
724 Heap::external_symbol_map());
717 } 725 }
718 726
719 // Fill the remainder of the string with dead wood. 727 // Fill the remainder of the string with dead wood.
720 int new_size = this->Size(); // Byte size of the external String object. 728 int new_size = this->Size(); // Byte size of the external String object.
721 Heap::CreateFillerObjectAt(this->address() + new_size, size - new_size); 729 Heap::CreateFillerObjectAt(this->address() + new_size, size - new_size);
722 return true; 730 return true;
723 } 731 }
724 732
725 733
726 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) { 734 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) {
(...skipping 7995 matching lines...) Expand 10 before | Expand all | Expand 10 after
8722 if (break_point_objects()->IsUndefined()) return 0; 8730 if (break_point_objects()->IsUndefined()) return 0;
8723 // Single beak point. 8731 // Single beak point.
8724 if (!break_point_objects()->IsFixedArray()) return 1; 8732 if (!break_point_objects()->IsFixedArray()) return 1;
8725 // Multiple break points. 8733 // Multiple break points.
8726 return FixedArray::cast(break_point_objects())->length(); 8734 return FixedArray::cast(break_point_objects())->length();
8727 } 8735 }
8728 #endif 8736 #endif
8729 8737
8730 8738
8731 } } // namespace v8::internal 8739 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | src/objects-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698