Index: src/heap.cc |
=================================================================== |
--- src/heap.cc (revision 535) |
+++ src/heap.cc (working copy) |
@@ -1342,29 +1342,34 @@ |
Object* Heap::AllocateConsString(String* first, String* second) { |
- int length = first->length() + second->length(); |
+ int first_length = first->length(); |
+ int second_length = second->length(); |
+ int length = first_length + second_length; |
bool is_ascii = first->is_ascii_representation() |
&& second->is_ascii_representation(); |
// If the resulting string is small make a flat string. |
- if (length < ConsString::kMinLength) { |
- Object* result = is_ascii |
- ? AllocateRawAsciiString(length) |
- : AllocateRawTwoByteString(length); |
- if (result->IsFailure()) return result; |
- // Copy the characters into the new object. |
- String* string_result = String::cast(result); |
- int first_length = first->length(); |
- // Copy the content of the first string. |
- for (int i = 0; i < first_length; i++) { |
- string_result->Set(i, first->Get(i)); |
+ if (length < String::kMinNonFlatLength) { |
+ ASSERT(first->IsFlat()); |
+ ASSERT(second->IsFlat()); |
+ if (is_ascii) { |
+ Object* result = AllocateRawAsciiString(length); |
+ if (result->IsFailure()) return result; |
+ // Copy the characters into the new object. |
+ byte* dest = SeqAsciiString::cast(result)->GetCharsAddress(); |
Christian Plesner Hansen
2008/10/21 14:16:22
There is some confusion about whether to use char
Erik Corry
2008/10/22 11:59:48
I've tried to use char consistently, since the nam
|
+ String::WriteToFlat(first, dest, 0, first_length); |
+ String::WriteToFlat(second, dest + first_length, 0, second_length); |
+ return result; |
+ } else { |
+ Object* result = AllocateRawTwoByteString(length); |
+ if (result->IsFailure()) return result; |
+ // Copy the characters into the new object. |
+ uc16* dest = reinterpret_cast<uc16*>( |
+ SeqTwoByteString::cast(result)->GetCharsAddress()); |
+ String::WriteToFlat(first, dest, 0, first_length); |
+ String::WriteToFlat(second, dest + first_length, 0, second_length); |
+ return result; |
} |
- int second_length = second->length(); |
- // Copy the content of the first string. |
- for (int i = 0; i < second_length; i++) { |
- string_result->Set(first_length + i, second->Get(i)); |
- } |
- return result; |
} |
Map* map; |
@@ -1395,7 +1400,7 @@ |
int length = end - start; |
// If the resulting string is small make a sub string. |
- if (end - start <= SlicedString::kMinLength) { |
+ if (end - start <= String::kMinNonFlatLength) { |
return Heap::AllocateSubString(buffer, start, end); |
} |