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

Unified Diff: src/heap.cc

Issue 149068: - Inlined the code for make simple cons strings.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 6 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/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
===================================================================
--- src/heap.cc (revision 2281)
+++ src/heap.cc (working copy)
@@ -1536,14 +1536,24 @@
}
-Object* Heap::AllocateConsString(String* first,
- String* second) {
+Object* Heap::AllocateConsString(String* first, String* second) {
int first_length = first->length();
+ if (first_length == 0) return second;
+
int second_length = second->length();
+ if (second_length == 0) return first;
+
int length = first_length + second_length;
bool is_ascii = first->IsAsciiRepresentation()
&& second->IsAsciiRepresentation();
+ // Make sure that an out of memory exception is thrown if the length
+ // of the new cons string is too large to fit in a Smi.
+ if (length > Smi::kMaxValue || length < -0) {
+ Top::context()->mark_out_of_memory();
+ return Failure::OutOfMemoryException();
+ }
+
// If the resulting string is small make a flat string.
if (length < String::kMinNonFlatLength) {
ASSERT(first->IsFlat());
@@ -1553,8 +1563,12 @@
if (result->IsFailure()) return result;
// Copy the characters into the new object.
char* dest = SeqAsciiString::cast(result)->GetChars();
- String::WriteToFlat(first, dest, 0, first_length);
- String::WriteToFlat(second, dest + first_length, 0, second_length);
+ // Copy first part.
+ char* src = SeqAsciiString::cast(first)->GetChars();
Kasper Lund 2009/06/26 13:07:23 Remove extra space after src
+ for (int i = 0; i < first_length; i++) *dest++ = src[i];
+ // Copy second part.
+ src = SeqAsciiString::cast(second)->GetChars();
Kasper Lund 2009/06/26 13:07:23 Remove extra space after src.
+ for (int i = 0; i < second_length; i++) *dest++ = src[i];
return result;
} else {
Object* result = AllocateRawTwoByteString(length);
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698