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

Unified Diff: src/heap.cc

Issue 7516: - Optimized copying of FixedArray. (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
« src/heap.h ('K') | « src/heap.h ('k') | src/objects.h » ('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 523)
+++ src/heap.cc (working copy)
@@ -2034,6 +2034,43 @@
}
+Object* Heap::AllocateRawFixedArray(int length) {
+ // Allocate the raw data for a fixed array.
+ int size = FixedArray::SizeFor(length);
+ return (size > MaxHeapObjectSize())
+ ? lo_space_->AllocateRawFixedArray(size)
+ : new_space_.AllocateRaw(size);
+}
+
+
+Object* Heap::CopyFixedArray(FixedArray* src) {
+ int len = src->length();
+ Object* obj = Heap::AllocateRawFixedArray(len);
+ if (obj->IsFailure()) return obj;
+ HeapObject::cast(obj)->set_map(src->map());
+ FixedArray* result = FixedArray::cast(obj);
+ result->set_length(len);
+ FixedArray::WriteBarrierMode mode = result->GetWriteBarrierMode();
+ // Copy the content
+ for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
+ return result;
+}
+
+
+Object* Heap::AllocateFixedArray(int length) {
+ Object* result = AllocateRawFixedArray(length);
+ if (!result->IsFailure()) {
+ // Initialize header.
+ reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
+ FixedArray* array = FixedArray::cast(result);
+ array->set_length(length);
+ // Initialize body.
+ for (int index = 0; index < length; index++) array->set_undefined(index);
+ }
+ return result;
+}
+
+
Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
ASSERT(empty_fixed_array()->IsFixedArray());
if (length == 0) return empty_fixed_array();
@@ -2060,18 +2097,16 @@
Object* Heap::AllocateFixedArrayWithHoles(int length) {
if (length == 0) return empty_fixed_array();
- int size = FixedArray::SizeFor(length);
- Object* result = size > MaxHeapObjectSize()
- ? lo_space_->AllocateRawFixedArray(size)
- : AllocateRaw(size, NEW_SPACE);
- if (result->IsFailure()) return result;
-
- // Initialize the object.
- reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
- FixedArray* array = FixedArray::cast(result);
- array->set_length(length);
- for (int index = 0; index < length; index++) array->set_the_hole(index);
- return array;
+ Object* result = AllocateRawFixedArray(length);
+ if (!result->IsFailure()) {
+ // Initialize header.
+ reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
+ FixedArray* array = FixedArray::cast(result);
+ array->set_length(length);
+ // Initialize body.
+ for (int index = 0; index < length; index++) array->set_the_hole(index);
+ }
+ return result;
}
« src/heap.h ('K') | « src/heap.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698