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

Micro-optimizations to pop() and shift()

R=verwaest@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/247613002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21043 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 930aa4a5
......@@ -279,8 +279,8 @@ static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>();
Handle<JSArray> array = Handle<JSArray>::cast(receiver);
// If there may be elements accessors in the prototype chain, the fast path
// cannot be used.
if (array->map()->DictionaryElementsInPrototypeChainOnly()) {
// cannot be used if there arguments to add to the array.
if (args != NULL && array->map()->DictionaryElementsInPrototypeChainOnly()) {
return MaybeHandle<FixedArrayBase>();
}
if (array->map()->is_observed()) return MaybeHandle<FixedArrayBase>();
......@@ -500,15 +500,11 @@ BUILTIN(ArrayPop) {
ElementsAccessor* accessor = array->GetElementsAccessor();
int new_length = len - 1;
MaybeHandle<Object> maybe_element;
if (accessor->HasElement(array, array, new_length, elms_obj)) {
maybe_element = accessor->Get(array, array, new_length, elms_obj);
} else {
Handle<Object> proto(array->GetPrototype(), isolate);
maybe_element = Object::GetElement(isolate, proto, len - 1);
Handle<Object> element =
accessor->Get(array, array, new_length, elms_obj).ToHandleChecked();
if (element->IsTheHole()) {
return CallJsBuiltin(isolate, "ArrayPop", args);
}
Handle<Object> element;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element, maybe_element);
RETURN_FAILURE_ON_EXCEPTION(
isolate,
accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate)));
......@@ -536,11 +532,10 @@ BUILTIN(ArrayShift) {
// Get first element
ElementsAccessor* accessor = array->GetElementsAccessor();
Handle<Object> first;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, first, accessor->Get(receiver, array, 0, elms_obj));
Handle<Object> first =
accessor->Get(array, array, 0, elms_obj).ToHandleChecked();
if (first->IsTheHole()) {
first = isolate->factory()->undefined_value();
return CallJsBuiltin(isolate, "ArrayShift", args);
}
if (heap->CanMoveObjectStart(*elms_obj)) {
......
......@@ -4209,6 +4209,7 @@ TEST(ArrayShiftSweeping) {
v8::Local<v8::Value> result = CompileRun(
"var array = new Array(40000);"
"var tmp = new Array(100000);"
"array[0] = 10;"
"gc();"
"array.shift();"
"array;");
......
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