Commit cab07f55 authored by danno@chromium.org's avatar danno@chromium.org

Add InternalArrayCodeGeneric

R=whesse@chromium.org
BUG=none
TEST=none

Review URL: http://codereview.chromium.org/9006051

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10308 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5bc7e823
......@@ -463,7 +463,7 @@ void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
__ bind(&generic_array_code);
Handle<Code> array_code =
masm->isolate()->builtins()->ArrayCodeGeneric();
masm->isolate()->builtins()->InternalArrayCodeGeneric();
__ Jump(array_code, RelocInfo::CODE_TARGET);
}
......
......@@ -184,17 +184,17 @@ BUILTIN(EmptyFunction) {
}
BUILTIN(ArrayCodeGeneric) {
static MaybeObject* ArrayCodeGenericCommon(Arguments* args,
Isolate* isolate,
JSFunction* constructor) {
Heap* heap = isolate->heap();
isolate->counters()->array_function_runtime()->Increment();
JSArray* array;
if (CalledAsConstructor(isolate)) {
array = JSArray::cast(*args.receiver());
array = JSArray::cast((*args)[0]);
} else {
// Allocate the JS Array
JSFunction* constructor =
isolate->context()->global_context()->array_function();
Object* obj;
{ MaybeObject* maybe_obj = heap->AllocateJSObject(constructor);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
......@@ -202,13 +202,10 @@ BUILTIN(ArrayCodeGeneric) {
array = JSArray::cast(obj);
}
// 'array' now contains the JSArray we should initialize.
ASSERT(array->HasFastTypeElements());
// Optimize the case where there is one argument and the argument is a
// small smi.
if (args.length() == 2) {
Object* obj = args[1];
if (args->length() == 2) {
Object* obj = (*args)[1];
if (obj->IsSmi()) {
int len = Smi::cast(obj)->value();
if (len >= 0 && len < JSObject::kInitialMaxFastElementArray) {
......@@ -225,18 +222,18 @@ BUILTIN(ArrayCodeGeneric) {
{ MaybeObject* maybe_obj = array->Initialize(0);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
return array->SetElementsLength(args[1]);
return array->SetElementsLength((*args)[1]);
}
// Optimize the case where there are no parameters passed.
if (args.length() == 1) {
if (args->length() == 1) {
return array->Initialize(JSArray::kPreallocatedArrayElements);
}
// Set length and elements on the array.
int number_of_elements = args.length() - 1;
int number_of_elements = args->length() - 1;
MaybeObject* maybe_object =
array->EnsureCanContainElements(&args, 1, number_of_elements,
array->EnsureCanContainElements(args, 1, number_of_elements,
ALLOW_CONVERTED_DOUBLE_ELEMENTS);
if (maybe_object->IsFailure()) return maybe_object;
......@@ -257,7 +254,7 @@ BUILTIN(ArrayCodeGeneric) {
case FAST_SMI_ONLY_ELEMENTS: {
FixedArray* smi_elms = FixedArray::cast(elms);
for (int index = 0; index < number_of_elements; index++) {
smi_elms->set(index, args[index+1], SKIP_WRITE_BARRIER);
smi_elms->set(index, (*args)[index+1], SKIP_WRITE_BARRIER);
}
break;
}
......@@ -266,14 +263,14 @@ BUILTIN(ArrayCodeGeneric) {
WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
FixedArray* object_elms = FixedArray::cast(elms);
for (int index = 0; index < number_of_elements; index++) {
object_elms->set(index, args[index+1], mode);
object_elms->set(index, (*args)[index+1], mode);
}
break;
}
case FAST_DOUBLE_ELEMENTS: {
FixedDoubleArray* double_elms = FixedDoubleArray::cast(elms);
for (int index = 0; index < number_of_elements; index++) {
double_elms->set(index, args[index+1]->Number());
double_elms->set(index, (*args)[index+1]->Number());
}
break;
}
......@@ -288,6 +285,22 @@ BUILTIN(ArrayCodeGeneric) {
}
BUILTIN(InternalArrayCodeGeneric) {
return ArrayCodeGenericCommon(
&args,
isolate,
isolate->context()->global_context()->internal_array_function());
}
BUILTIN(ArrayCodeGeneric) {
return ArrayCodeGenericCommon(
&args,
isolate,
isolate->context()->global_context()->array_function());
}
MUST_USE_RESULT static MaybeObject* AllocateJSArray(Heap* heap) {
JSFunction* array_function =
heap->isolate()->context()->global_context()->array_function();
......
......@@ -44,6 +44,7 @@ enum BuiltinExtraArguments {
\
V(EmptyFunction, NO_EXTRA_ARGUMENTS) \
\
V(InternalArrayCodeGeneric, NO_EXTRA_ARGUMENTS) \
V(ArrayCodeGeneric, NO_EXTRA_ARGUMENTS) \
\
V(ArrayPush, NO_EXTRA_ARGUMENTS) \
......
......@@ -1337,7 +1337,7 @@ void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
// the construction.
__ bind(&generic_array_code);
Handle<Code> array_code =
masm->isolate()->builtins()->ArrayCodeGeneric();
masm->isolate()->builtins()->InternalArrayCodeGeneric();
__ jmp(array_code, RelocInfo::CODE_TARGET);
}
......
......@@ -1357,7 +1357,7 @@ void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
// the construction.
__ bind(&generic_array_code);
Handle<Code> array_code =
masm->isolate()->builtins()->ArrayCodeGeneric();
masm->isolate()->builtins()->InternalArrayCodeGeneric();
__ Jump(array_code, RelocInfo::CODE_TARGET);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment