Revision: 10711
Author:   [email protected]
Date:     Wed Feb 15 04:13:55 2012
Log: Remove unnecessary elements type check when allocating array in runtime.

BUG=
TEST=--smi-only-arrays should be perf-neutral to allocating big arrays in a tight loop.

Review URL: https://chromiumcodereview.appspot.com/9356002
http://code.google.com/p/v8/source/detail?r=10711

Modified:
 /branches/bleeding_edge/src/builtins.cc
 /branches/bleeding_edge/src/heap.cc

=======================================
--- /branches/bleeding_edge/src/builtins.cc     Wed Feb  8 01:50:13 2012
+++ /branches/bleeding_edge/src/builtins.cc     Wed Feb 15 04:13:55 2012
@@ -218,12 +218,13 @@
     if (obj->IsSmi()) {
       int len = Smi::cast(obj)->value();
       if (len >= 0 && len < JSObject::kInitialMaxFastElementArray) {
-        Object* obj;
+        Object* fixed_array;
         { MaybeObject* maybe_obj = heap->AllocateFixedArrayWithHoles(len);
-          if (!maybe_obj->ToObject(&obj)) return maybe_obj;
-        }
-        MaybeObject* maybe_obj = array->SetContent(FixedArray::cast(obj));
-        if (maybe_obj->IsFailure()) return maybe_obj;
+          if (!maybe_obj->ToObject(&fixed_array)) return maybe_obj;
+        }
+ // We do not use SetContent to skip the unnecessary elements type check.
+        array->set_elements(FixedArray::cast(fixed_array));
+        array->set_length(Smi::cast(obj));
         return array;
       }
     }
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Feb 10 04:36:05 2012
+++ /branches/bleeding_edge/src/heap.cc Wed Feb 15 04:13:55 2012
@@ -4361,10 +4361,10 @@
   Context* global_context = isolate()->context()->global_context();
   JSFunction* array_function = global_context->array_function();
   Map* map = array_function->initial_map();
-  if (elements_kind == FAST_ELEMENTS || !FLAG_smi_only_arrays) {
-    map = Map::cast(global_context->object_js_array_map());
-  } else if (elements_kind == FAST_DOUBLE_ELEMENTS) {
+  if (elements_kind == FAST_DOUBLE_ELEMENTS) {
     map = Map::cast(global_context->double_js_array_map());
+  } else if (elements_kind == FAST_ELEMENTS || !FLAG_smi_only_arrays) {
+    map = Map::cast(global_context->object_js_array_map());
   } else {
     ASSERT(elements_kind == FAST_SMI_ONLY_ELEMENTS);
     ASSERT(map == global_context->smi_js_array_map());

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to