mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
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:
parent
3c8a6ca71d
commit
76bbb088e9
@ -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)
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user