Index: src/heap-inl.h |
diff --git a/src/heap-inl.h b/src/heap-inl.h |
index 26cf6e0f4751d0c5ea1c839339170ff0433e0bae..7b91e8715a18d52294739664c8383825847e7f93 100644 |
--- a/src/heap-inl.h |
+++ b/src/heap-inl.h |
@@ -62,6 +62,71 @@ MaybeObject* Heap::AllocateSymbol(Vector<const char> str, |
} |
+MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str, |
+ uint32_t hash_field) { |
+ if (str.length() > SeqAsciiString::kMaxLength) { |
+ return Failure::OutOfMemoryException(); |
+ } |
+ // Compute map and object size. |
+ Map* map = ascii_symbol_map(); |
+ int size = SeqAsciiString::SizeFor(str.length()); |
+ |
+ // Allocate string. |
+ Object* result; |
+ { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
+ ? lo_space_->AllocateRaw(size) |
+ : old_data_space_->AllocateRaw(size); |
+ if (!maybe_result->ToObject(&result)) return maybe_result; |
+ } |
+ |
+ reinterpret_cast<HeapObject*>(result)->set_map(map); |
+ // Set length and hash fields of the allocated string. |
+ String* answer = String::cast(result); |
+ answer->set_length(str.length()); |
+ answer->set_hash_field(hash_field); |
+ |
+ ASSERT_EQ(size, answer->Size()); |
+ |
+ // Fill in the characters. |
+ memcpy(answer->address() + SeqAsciiString::kHeaderSize, |
+ str.start(), str.length()); |
+ |
+ return answer; |
+} |
+ |
+ |
+MaybeObject* Heap::AllocateTwoByteSymbol(Vector<const uc16> str, |
+ uint32_t hash_field) { |
+ if (str.length() > SeqTwoByteString::kMaxLength) { |
+ return Failure::OutOfMemoryException(); |
+ } |
+ // Compute map and object size. |
+ Map* map = symbol_map(); |
+ int size = SeqTwoByteString::SizeFor(str.length()); |
+ |
+ // Allocate string. |
+ Object* result; |
+ { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
+ ? lo_space_->AllocateRaw(size) |
+ : old_data_space_->AllocateRaw(size); |
+ if (!maybe_result->ToObject(&result)) return maybe_result; |
+ } |
+ |
+ reinterpret_cast<HeapObject*>(result)->set_map(map); |
+ // Set length and hash fields of the allocated string. |
+ String* answer = String::cast(result); |
+ answer->set_length(str.length()); |
+ answer->set_hash_field(hash_field); |
+ |
+ ASSERT_EQ(size, answer->Size()); |
+ |
+ // Fill in the characters. |
+ memcpy(answer->address() + SeqTwoByteString::kHeaderSize, |
+ str.start(), str.length() * kUC16Size); |
+ |
+ return answer; |
+} |
+ |
MaybeObject* Heap::CopyFixedArray(FixedArray* src) { |
return CopyFixedArrayWithMap(src, src->map()); |
} |