Commit 0071bf92 authored by antonm@chromium.org's avatar antonm@chromium.org

Do not turn source array elements into writable if doing Array.slice.

Array.slice doesn't mutate original array, so it's fine with read only data.
Plus nuke unnecessary cast.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6113 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c5916f55
......@@ -380,7 +380,7 @@ static inline MaybeObject* EnsureJSArrayWithWritableFastElements(
Object* receiver) {
if (!receiver->IsJSArray()) return NULL;
JSArray* array = JSArray::cast(receiver);
HeapObject* elms = HeapObject::cast(array->elements());
HeapObject* elms = array->elements();
if (elms->map() == Heap::fixed_array_map()) return elms;
if (elms->map() == Heap::fixed_cow_array_map()) {
return array->EnsureWritableFastElements();
......@@ -613,17 +613,14 @@ BUILTIN(ArraySlice) {
Object* receiver = *args.receiver();
FixedArray* elms;
int len = -1;
{ MaybeObject* maybe_elms_obj =
EnsureJSArrayWithWritableFastElements(receiver);
Object* elms_obj;
if (maybe_elms_obj != NULL && maybe_elms_obj->ToObject(&elms_obj)) {
if (!IsJSArrayFastElementMovingAllowed(JSArray::cast(receiver))) {
if (receiver->IsJSArray()) {
JSArray* array = JSArray::cast(receiver);
if (!array->HasFastElements() ||
!IsJSArrayFastElementMovingAllowed(array)) {
return CallJsBuiltin("ArraySlice", args);
}
elms = FixedArray::cast(elms_obj);
JSArray* array = JSArray::cast(receiver);
ASSERT(array->HasFastElements());
elms = FixedArray::cast(array->elements());
len = Smi::cast(array->length())->value();
} else {
// Array.slice(arguments, ...) is quite a common idiom (notably more
......@@ -649,7 +646,6 @@ BUILTIN(ArraySlice) {
}
#endif
}
}
ASSERT(len >= 0);
int n_arguments = args.length() - 1;
......
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