Speed up Array.shift, and Array.{pop,shift} on empty arrays, bug 692847. r=dvander

This commit is contained in:
Brian Hackett
2011-10-18 11:08:52 -07:00
parent f5386c9025
commit 428c560e3b
7 changed files with 128 additions and 18 deletions

View File

@@ -2565,8 +2565,26 @@ js::array_pop(JSContext *cx, uintN argc, Value *vp)
return array_pop_slowly(cx, obj, vp);
}
static JSBool
array_shift(JSContext *cx, uintN argc, Value *vp)
#ifdef JS_METHODJIT
void FASTCALL
mjit::stubs::ArrayShift(VMFrame &f)
{
JSObject *obj = &f.regs.sp[-1].toObject();
JS_ASSERT(obj->isDenseArray());
JS_ASSERT(!js_PrototypeHasIndexedProperties(f.cx, obj));
/*
* At this point the length and initialized length have already been
* decremented and the result fetched, so just shift the array elements
* themselves.
*/
uint32 initlen = obj->getDenseArrayInitializedLength();
obj->moveDenseArrayElements(0, 1, initlen);
}
#endif /* JS_METHODJIT */
JSBool
js::array_shift(JSContext *cx, uintN argc, Value *vp)
{
JSObject *obj = ToObject(cx, &vp[1]);
if (!obj)