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

Unified Diff: src/heap.cc

Issue 8011: Use direct copy and templates to speed up flattening of strings. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/factory.cc ('k') | src/objects.h » ('j') | src/objects.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « src/factory.cc ('k') | src/objects.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698