Index: src/factory.cc |
diff --git a/src/factory.cc b/src/factory.cc |
index 8b842a733928f7425f73870b8c61523bc03ac84c..10e70d909fdbf98be99fd436768170d9e621d3bb 100644 |
--- a/src/factory.cc |
+++ b/src/factory.cc |
@@ -259,6 +259,32 @@ Handle<String> Factory::NewConsString(Handle<String> first, |
} |
+template<typename SinkChar, typename StringType> |
+Handle<String> ConcatStringContent(Handle<StringType> result, |
+ Handle<String> first, |
+ Handle<String> second) { |
+ DisallowHeapAllocation pointer_stays_valid; |
+ SinkChar* sink = result->GetChars(); |
+ String::WriteToFlat(*first, sink, 0, first->length()); |
+ String::WriteToFlat(*second, sink + first->length(), 0, second->length()); |
+ return result; |
+} |
+ |
+ |
+Handle<String> Factory::NewFlatConcatString(Handle<String> first, |
+ Handle<String> second) { |
+ int total_length = first->length() + second->length(); |
+ if (first->IsOneByteRepresentationUnderneath() && |
+ second->IsOneByteRepresentationUnderneath()) { |
+ return ConcatStringContent<uint8_t>( |
+ NewRawOneByteString(total_length), first, second); |
+ } else { |
+ return ConcatStringContent<uc16>( |
+ NewRawTwoByteString(total_length), first, second); |
+ } |
+} |
+ |
+ |
Handle<String> Factory::NewSubString(Handle<String> str, |
int begin, |
int end) { |