Use array based storage in container objects (#3600)

Currently, collections use object based solutions for storing elements and
iterating on them. If an element is deleted and re-inserted, the storage
position is the same as before so the iteration order is wrong.
This patch replaces the object based storage with an array based solution
that helps to store and iterate elements as expected.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs@inf.u-szeged.hu
This commit is contained in:
Roland Takacs
2020-03-17 19:30:55 +01:00
committed by GitHub
parent 1cfda262bd
commit 51a9575fd0
10 changed files with 726 additions and 437 deletions
+45 -3
View File
@@ -989,6 +989,50 @@ typedef enum
ECMA_CONTAINER_FLAGS_EMPTY = (0), /** empty flags */
ECMA_CONTAINER_FLAGS_WEAK = (1 << 0) /** container object is weak */
} ecma_container_flags_t;
/**
* Description of map collection.
*/
typedef struct
{
ecma_value_t key; /**< key value */
ecma_value_t value; /**< value of the key */
} ecma_container_pair_t;
/**
* Size of a single element (in ecma_value_t unit).
*/
#define ECMA_CONTAINER_VALUE_SIZE 1
/**
* Size of a key - value pair (in ecma_value_t unit).
*/
#define ECMA_CONTAINER_PAIR_SIZE 2
/**
* Size of the internal buffer.
*/
#define ECMA_CONTAINER_GET_SIZE(container_p) \
(container_p->buffer_p[0])
/**
* Remove the size field of the internal buffer.
*/
#define ECMA_CONTAINER_SET_SIZE(container_p, size) \
(container_p->buffer_p[0] = (ecma_value_t) (size))
/**
* Number of entries of the internal buffer.
*/
#define ECMA_CONTAINER_ENTRY_COUNT(collection_p) \
(collection_p->item_count - 1)
/**
* Pointer to the first entry of the internal buffer.
*/
#define ECMA_CONTAINER_START(collection_p) \
(collection_p->buffer_p + 1)
#endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
typedef enum
@@ -1429,9 +1473,7 @@ typedef enum
ECMA_STRING_CONTAINER_SYMBOL, /**< the ecma-string is a symbol */
ECMA_STRING_CONTAINER_MAP_KEY, /**< the ecma-string is a map key string */
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_MAP_KEY /**< maximum value */
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_SYMBOL /**< maximum value */
} ecma_string_container_t;
/**