Skip to content

Commit 7e0aa08

Browse files
author
Robert Fancsik
authored
Adjust fast array growth (#4868)
Since we allow large buffer allocations during array constructor we could extend this behavior to [[Set]] operation as well. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent dbba83f commit 7e0aa08

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

jerry-core/ecma/operations/ecma-array-object.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@
3535
* @{
3636
*/
3737

38-
#if JERRY_CPOINTER_32_BIT
39-
/**
40-
* Maximum length of the array length to allocate fast mode access for it
41-
* e.g. new Array(5000) is constructed as fast mode access array,
42-
* but new Array(50000000) is consturcted as normal property list based array
43-
*/
44-
#define ECMA_FAST_ARRAY_MAX_INITIAL_LENGTH (1 << 17)
45-
#else /* JERRY_CPOINTER_32_BIT */
46-
/**
47-
* Maximum length of the array length to allocate fast mode access for it
48-
* e.g. new Array(5000) is constructed as fast mode access array,
49-
* but new Array(50000000) is consturcted as normal property list based array
50-
*/
51-
#define ECMA_FAST_ARRAY_MAX_INITIAL_LENGTH (1 << 13)
52-
#endif /* JERRY_CPOINTER_32_BIT */
53-
5438
/**
5539
* Property name type flag for array indices.
5640
*/
@@ -130,7 +114,7 @@ ecma_op_new_array_object (uint32_t length) /**< length of the new array */
130114

131115
if (length > 0)
132116
{
133-
if (length >= ECMA_FAST_ARRAY_MAX_INITIAL_LENGTH)
117+
if (length >= ECMA_FAST_ARRAY_MAX_HOLE_COUNT)
134118
{
135119
return object_p;
136120
}
@@ -398,8 +382,7 @@ ecma_fast_array_set_property (ecma_object_t *object_p, /**< fast access mode arr
398382
uint32_t old_holes = ext_obj_p->u.array.length_prop_and_hole_count;
399383
uint32_t new_holes = index - old_length;
400384

401-
if (JERRY_UNLIKELY (new_holes > ECMA_FAST_ARRAY_MAX_NEW_HOLES_COUNT
402-
|| ((old_holes >> ECMA_FAST_ARRAY_HOLE_SHIFT) + new_holes) > ECMA_FAST_ARRAY_MAX_HOLE_COUNT))
385+
if (JERRY_UNLIKELY (new_holes > (ECMA_FAST_ARRAY_MAX_HOLE_COUNT - (old_holes >> ECMA_FAST_ARRAY_HOLE_SHIFT))))
403386
{
404387
ecma_fast_array_convert_to_normal (object_p);
405388

@@ -623,17 +606,14 @@ ecma_fast_array_set_length (ecma_object_t *object_p, /**< fast access mode array
623606
uint32_t old_holes = ext_obj_p->u.array.length_prop_and_hole_count;
624607
uint32_t new_holes = new_length - old_length;
625608

626-
if (JERRY_UNLIKELY (new_holes > ECMA_FAST_ARRAY_MAX_NEW_HOLES_COUNT
627-
|| ((old_holes >> ECMA_FAST_ARRAY_HOLE_SHIFT) + new_holes) > ECMA_FAST_ARRAY_MAX_HOLE_COUNT))
609+
if (JERRY_UNLIKELY (new_holes > (ECMA_FAST_ARRAY_MAX_HOLE_COUNT - (old_holes >> ECMA_FAST_ARRAY_HOLE_SHIFT))))
628610
{
629611
ecma_fast_array_convert_to_normal (object_p);
630612
}
631613
else
632614
{
633615
ecma_fast_array_extend (object_p, new_length);
634616
}
635-
636-
return;
637617
} /* ecma_fast_array_set_length */
638618

639619
/**

jerry-core/ecma/operations/ecma-array-object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/**
6161
* Maximum number of array holes in a fast access mode array
6262
*/
63-
#define ECMA_FAST_ARRAY_MAX_HOLE_COUNT (1 << 24)
63+
#define ECMA_FAST_ARRAY_MAX_HOLE_COUNT (1 << 16)
6464

6565
ecma_object_t *ecma_op_new_array_object (uint32_t length);
6666

0 commit comments

Comments
 (0)