Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 2ebeb655f28d210a2a6905147457461bf47a51c6..49551b2b996856d3c626594eecbec6fc454f8568 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -952,33 +952,36 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) { |
#endif // DEBUG |
Heap* heap = GetHeap(); |
int size = this->Size(); // Byte size of the original string. |
- if (size < ExternalString::kSize) { |
+ if (size < ExternalString::kShortSize) { |
return false; |
} |
- ASSERT(size >= ExternalString::kSize); |
+ ASSERT(size >= ExternalString::kShortSize); |
Lasse Reichstein
2011/11/23 08:43:20
This assert can safely be dropped.
Yang
2011/11/23 09:58:48
Done.
|
bool is_ascii = this->IsAsciiRepresentation(); |
bool is_symbol = this->IsSymbol(); |
- int length = this->length(); |
- int hash_field = this->hash_field(); |
// Morph the object to an external string by adjusting the map and |
// reinitializing the fields. |
- this->set_map(is_ascii ? |
- heap->external_string_with_ascii_data_map() : |
- heap->external_string_map()); |
+ if (size >= ExternalString::kSize) { |
+ this->set_map( |
+ is_symbol |
+ ? (is_ascii ? heap->external_symbol_with_ascii_data_map() |
+ : heap->external_symbol_map()) |
+ : (is_ascii ? heap->external_string_with_ascii_data_map() |
+ : heap->external_string_map())); |
+ } else { |
+ this->set_map( |
+ is_symbol |
+ ? (is_ascii ? heap->short_external_symbol_with_ascii_data_map() |
+ : heap->short_external_symbol_map()) |
+ : (is_ascii ? heap->short_external_string_with_ascii_data_map() |
+ : heap->short_external_string_map())); |
+ } |
ExternalTwoByteString* self = ExternalTwoByteString::cast(this); |
- self->set_length(length); |
- self->set_hash_field(hash_field); |
self->set_resource(resource); |
- // Additionally make the object into an external symbol if the original string |
- // was a symbol to start with. |
- if (is_symbol) { |
- self->Hash(); // Force regeneration of the hash value. |
- // Now morph this external string into a external symbol. |
- this->set_map(is_ascii ? |
- heap->external_symbol_with_ascii_data_map() : |
- heap->external_symbol_map()); |
- } |
+ STATIC_ASSERT(String::kLengthOffset == ExternalTwoByteString::kLengthOffset); |
+ STATIC_ASSERT(String::kHashFieldOffset == |
+ ExternalTwoByteString::kHashFieldOffset); |
Lasse Reichstein
2011/11/23 08:43:20
These two asserts are unnecessary, since ExternalA
Yang
2011/11/23 09:58:48
Done.
|
+ if (is_symbol) self->Hash(); // Force regeneration of the hash value. |
// Fill the remainder of the string with dead wood. |
int new_size = this->Size(); // Byte size of the external String object. |
@@ -1004,28 +1007,27 @@ bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) { |
#endif // DEBUG |
Heap* heap = GetHeap(); |
int size = this->Size(); // Byte size of the original string. |
- if (size < ExternalString::kSize) { |
+ if (size < ExternalString::kShortSize) { |
return false; |
} |
- ASSERT(size >= ExternalString::kSize); |
+ ASSERT(size >= ExternalString::kShortSize); |
Lasse Reichstein
2011/11/23 08:43:20
Ditto.
Yang
2011/11/23 09:58:48
Done.
|
bool is_symbol = this->IsSymbol(); |
- int length = this->length(); |
- int hash_field = this->hash_field(); |
// Morph the object to an external string by adjusting the map and |
- // reinitializing the fields. |
- this->set_map(heap->external_ascii_string_map()); |
+ // reinitializing the fields. Use short version if space is limited. |
+ if (size >= ExternalString::kSize) { |
+ this->set_map(is_symbol ? heap->external_ascii_symbol_map() |
+ : heap->external_ascii_string_map()); |
+ } else { |
+ this->set_map(is_symbol ? heap->short_external_ascii_symbol_map() |
+ : heap->short_external_ascii_string_map()); |
+ } |
ExternalAsciiString* self = ExternalAsciiString::cast(this); |
- self->set_length(length); |
- self->set_hash_field(hash_field); |
self->set_resource(resource); |
- // Additionally make the object into an external symbol if the original string |
- // was a symbol to start with. |
- if (is_symbol) { |
- self->Hash(); // Force regeneration of the hash value. |
- // Now morph this external string into a external symbol. |
- this->set_map(heap->external_ascii_symbol_map()); |
- } |
+ STATIC_ASSERT(String::kLengthOffset == ExternalAsciiString::kLengthOffset); |
+ STATIC_ASSERT(String::kHashFieldOffset == |
+ ExternalAsciiString::kHashFieldOffset); |
Lasse Reichstein
2011/11/23 08:43:20
As above.
Yang
2011/11/23 09:58:48
Done.
|
+ if (is_symbol) self->Hash(); // Force regeneration of the hash value. |
Lasse Reichstein
2011/11/23 08:43:20
Is there an explanation of how the hash can possib
Yang
2011/11/23 09:58:48
Looking into that later.
|
// Fill the remainder of the string with dead wood. |
int new_size = this->Size(); // Byte size of the external String object. |
@@ -1033,7 +1035,6 @@ bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) { |
if (Marking::IsBlack(Marking::MarkBitFrom(this))) { |
MemoryChunk::IncrementLiveBytes(this->address(), new_size - size); |
} |
- |
return true; |
} |