Fast path for writing a double into an array (511737, r=danderson).

This commit is contained in:
Andreas Gal 2009-08-20 16:53:10 -07:00
parent ebe9c3f20b
commit ebfe09b112
3 changed files with 29 additions and 3 deletions

View File

@ -955,6 +955,25 @@ js_Array_dense_setelem_int(JSContext* cx, JSObject* obj, jsint i, int32 j)
return dense_grow(cx, obj, i, v);
}
JS_DEFINE_CALLINFO_4(extern, BOOL, js_Array_dense_setelem_int, CONTEXT, OBJECT, INT32, INT32, 0, 0)
JSBool FASTCALL
js_Array_dense_setelem_double(JSContext* cx, JSObject* obj, jsint i, jsdouble d)
{
JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj));
jsval v;
jsint j;
if (JS_LIKELY(JSDOUBLE_IS_INT(d, j) && INT_FITS_IN_JSVAL(j))) {
v = INT_TO_JSVAL(j);
} else {
if (!js_NewDoubleInRootedValue(cx, d, &v))
return JS_FALSE;
}
return dense_grow(cx, obj, i, v);
}
JS_DEFINE_CALLINFO_4(extern, BOOL, js_Array_dense_setelem_double, CONTEXT, OBJECT, INT32, DOUBLE, 0, 0)
#endif
static JSBool

View File

@ -453,6 +453,7 @@ JS_DECLARE_CALLINFO(js_NewInstance)
/* Defined in jsarray.cpp. */
JS_DECLARE_CALLINFO(js_Array_dense_setelem)
JS_DECLARE_CALLINFO(js_Array_dense_setelem_int)
JS_DECLARE_CALLINFO(js_Array_dense_setelem_double)
JS_DECLARE_CALLINFO(js_NewEmptyArray)
JS_DECLARE_CALLINFO(js_NewUninitializedArray)
JS_DECLARE_CALLINFO(js_ArrayCompPush)

View File

@ -10423,9 +10423,15 @@ TraceRecorder::record_JSOP_SETELEM()
// builtin for every storage type. Special case for integers though,
// since they are so common.
LIns* res_ins;
if (isNumber(v) && isPromoteInt(v_ins)) {
LIns* args[] = { ::demote(lir, v_ins), idx_ins, obj_ins, cx_ins };
res_ins = lir->insCall(&js_Array_dense_setelem_int_ci, args);
LIns* args[] = { NULL, idx_ins, obj_ins, cx_ins };
if (isNumber(v)) {
if (isPromoteInt(v_ins)) {
args[0] = ::demote(lir, v_ins);
res_ins = lir->insCall(&js_Array_dense_setelem_int_ci, args);
} else {
args[0] = v_ins;
res_ins = lir->insCall(&js_Array_dense_setelem_double_ci, args);
}
} else {
LIns* args[] = { box_jsval(v, v_ins), idx_ins, obj_ins, cx_ins };
res_ins = lir->insCall(&js_Array_dense_setelem_ci, args);