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

Unified Diff: src/runtime.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
Index: src/runtime.cc
===================================================================
--- src/runtime.cc (revision 535)
+++ src/runtime.cc (working copy)
@@ -1356,7 +1356,7 @@
AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
// dispatch on type of strings
if (pat->is_ascii_representation()) {
- Vector<const char> pat_vector = pat->ToAsciiVector();
+ Vector<const byte> pat_vector = pat->ToAsciiVector();
if (sub->is_ascii_representation()) {
return StringMatchStrategy(sub->ToAsciiVector(), pat_vector, start_index);
}
@@ -2591,6 +2591,27 @@
}
+template<typename sinkchar>
+static inline void StringBuilderConcatHelper(String* special, sinkchar* sink, FixedArray* fixed_array, int array_length) {
+ int position = 0;
+ for (int i = 0; i < array_length; i++) {
+ Object* element = fixed_array->get(i);
+ if (element->IsSmi()) {
+ int len = Smi::cast(element)->value();
+ int pos = len >> 11;
+ len &= 0x7ff;
+ String::WriteToFlat(special, sink + position, pos, pos + len);
+ position += len;
+ } else {
+ String* string = String::cast(element);
+ int element_length = string->length();
+ String::WriteToFlat(string, sink + position, 0, element_length);
+ position += element_length;
+ }
+ }
+}
+
+
static Object* Runtime_StringBuilderConcat(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 2);
@@ -2647,32 +2668,27 @@
}
int length = position;
- position = 0;
Object* object;
+
if (ascii) {
object = Heap::AllocateRawAsciiString(length);
+ if (object->IsFailure()) return object;
+ SeqAsciiString* answer = SeqAsciiString::cast(object);
+ StringBuilderConcatHelper(special,
+ answer->GetCharsAddress(),
+ fixed_array,
+ array_length);
+ return answer;
} else {
object = Heap::AllocateRawTwoByteString(length);
+ if (object->IsFailure()) return object;
+ SeqTwoByteString* answer = SeqTwoByteString::cast(object);
+ StringBuilderConcatHelper(special,
+ reinterpret_cast<uc16*>(answer->GetCharsAddress()),
+ fixed_array,
+ array_length);
+ return answer;
}
- if (object->IsFailure()) return object;
-
- String* answer = String::cast(object);
- for (int i = 0; i < array_length; i++) {
- Object* element = fixed_array->get(i);
- if (element->IsSmi()) {
- int len = Smi::cast(element)->value();
- int pos = len >> 11;
- len &= 0x7ff;
- String::Flatten(special, answer, pos, pos + len, position);
- position += len;
- } else {
- String* string = String::cast(element);
- int element_length = string->length();
- String::Flatten(string, answer, 0, element_length, position);
- position += element_length;
- }
- }
- return answer;
}

Powered by Google App Engine
This is Rietveld 408576698