Optimize Array.prototype.fill for fast-array cases (#3569)

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam 2020-03-03 15:48:50 +01:00 committed by GitHub
parent 3c8a6ca71d
commit 76bbb088e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -2257,6 +2257,28 @@ ecma_builtin_array_prototype_fill (ecma_value_t value, /**< value */
}
}
if (ecma_op_object_is_fast_array (obj_p))
{
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
if (ext_obj_p->u.array.u.hole_count < ECMA_FAST_ARRAY_HOLE_ONE
&& len != 0
&& ecma_op_ordinary_object_is_extensible (obj_p))
{
ecma_value_t *buffer_p = ECMA_GET_NON_NULL_POINTER (ecma_value_t, obj_p->u1.property_list_cp);
while (k < final)
{
ecma_free_value_if_not_object (buffer_p[k]);
buffer_p[k] = ecma_copy_value_if_not_object (value);
k++;
}
ecma_ref_object (obj_p);
return ecma_make_object_value (obj_p);
}
}
/* 11. */
while (k < final)
{

View File

@ -47,6 +47,8 @@ assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, -2, -1), [0, 0, 0, 8, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, -1, -3), [0, 0, 0, 0, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, undefined, 4), [8, 8, 8, 8, 0]));
assert (assertArrayEquals ([ , , , , 0].fill (8, 1, 3), [, 8, 8, , 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (7.8), [7.8, 7.8, 7.8, 7.8, 7.8]));
assert (assertArrayEquals (["foo", "bar", "baz"].fill (1), [1, 1, 1]));
// If the range is empty, the array is not actually modified and