Index: src/heap.cc |
diff --git a/src/heap.cc b/src/heap.cc |
index 84909d52a5970164098dd4ac6be3f659501a6ffb..fdb010edb2b71df05664ca521ccd3547e43909ce 100644 |
--- a/src/heap.cc |
+++ b/src/heap.cc |
@@ -2661,25 +2661,24 @@ MaybeObject* Heap::AllocateSubString(String* buffer, |
// Make an attempt to flatten the buffer to reduce access time. |
buffer = buffer->TryFlattenGetString(); |
- // TODO(1626): For now slicing external strings is not supported. However, |
- // a flat cons string can have an external string as first part in some cases. |
- // Therefore we have to single out this case as well. |
if (!FLAG_string_slices || |
- (buffer->IsConsString() && |
- (!buffer->IsFlat() || |
- !ConsString::cast(buffer)->first()->IsSeqString())) || |
- buffer->IsExternalString() || |
+ !buffer->IsFlat() || |
length < SlicedString::kMinLength || |
pretenure == TENURED) { |
Object* result; |
- { MaybeObject* maybe_result = buffer->IsAsciiRepresentation() |
- ? AllocateRawAsciiString(length, pretenure) |
- : AllocateRawTwoByteString(length, pretenure); |
+ // The string encoding of the string might be ascii, while the underlying |
Vitaly Repeshko
2011/09/13 18:20:25
Let's just replace this with
"WriteToFlat takes ca
|
+ // string is actually a twobyte. The content must be ascii though, |
+ // therefore this is a good opportunity to go back to ascii encoding. |
+ // WriteToFlat takes care of twobyte to ascii conversion. |
+ bool is_ascii = buffer->IsAsciiRepresentation(); |
+ { MaybeObject* maybe_result = is_ascii |
+ ? AllocateRawAsciiString(length, pretenure) |
+ : AllocateRawTwoByteString(length, pretenure); |
if (!maybe_result->ToObject(&result)) return maybe_result; |
} |
String* string_result = String::cast(result); |
// Copy the characters into the new object. |
- if (buffer->IsAsciiRepresentation()) { |
+ if (is_ascii) { |
ASSERT(string_result->IsAsciiRepresentation()); |
char* dest = SeqAsciiString::cast(string_result)->GetChars(); |
String::WriteToFlat(buffer, dest, start, end); |
@@ -2692,12 +2691,13 @@ MaybeObject* Heap::AllocateSubString(String* buffer, |
} |
ASSERT(buffer->IsFlat()); |
- ASSERT(!buffer->IsExternalString()); |
#if DEBUG |
buffer->StringVerify(); |
#endif |
Object* result; |
+ // The string encoding tag in the newly created slice does not really matter. |
Vitaly Repeshko
2011/09/13 18:20:25
"When slicing an indirect string we use its encodi
|
+ // Therefore we do not further check the encoding of the underlying string. |
{ Map* map = buffer->IsAsciiRepresentation() |
? sliced_ascii_string_map() |
: sliced_string_map(); |
@@ -2723,7 +2723,8 @@ MaybeObject* Heap::AllocateSubString(String* buffer, |
sliced_string->set_parent(buffer); |
sliced_string->set_offset(start); |
} |
- ASSERT(sliced_string->parent()->IsSeqString()); |
+ ASSERT(sliced_string->parent()->IsSeqString() || |
+ sliced_string->parent()->IsExternalString()); |
return result; |
} |