Skip to content

Commit 5911f72

Browse files
committed
Optimize string character access for ascii strings and refactor type store
to allow two byte hashes in the future. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 91b1547 commit 5911f72

File tree

5 files changed

+338
-152
lines changed

5 files changed

+338
-152
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -686,19 +686,45 @@ typedef enum
686686
ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
687687
stored locally in the string's descriptor */
688688
ECMA_STRING_CONTAINER_MAGIC_STRING, /**< the ecma-string is equal to one of ECMA magic strings */
689-
ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< the ecma-string is equal to one of external magic strings */
689+
ECMA_STRING_CONTAINER_MAGIC_STRING_EX, /**< the ecma-string is equal to one of external magic strings */
690+
691+
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< maximum value */
690692
} ecma_string_container_t;
691693

694+
/**
695+
* Mask for getting the container of a string.
696+
*/
697+
#define ECMA_STRING_CONTAINER_MASK 0x7u
698+
699+
/**
700+
* Value for increasing or decreasing the reference counter.
701+
*/
702+
#define ECMA_STRING_REF_ONE (1u << 3)
703+
704+
/**
705+
* Maximum value of the reference counter (8191).
706+
*/
707+
#define ECMA_STRING_MAX_REF (0x1fffu << 3)
708+
709+
/**
710+
* Set reference counter to zero (for refs_and_container member below).
711+
*/
712+
#define ECMA_STRING_SET_REF_TO_ONE(refs_and_container) \
713+
((uint16_t) (((refs_and_container) & ECMA_STRING_CONTAINER_MASK) | ECMA_STRING_REF_ONE))
714+
715+
/**
716+
* Returns with the container type of a string.
717+
*/
718+
#define ECMA_STRING_GET_CONTAINER(string_desc_p) \
719+
((ecma_string_container_t) ((string_desc_p)->refs_and_container & ECMA_STRING_CONTAINER_MASK))
720+
692721
/**
693722
* ECMA string-value descriptor
694723
*/
695724
typedef struct ecma_string_t
696725
{
697726
/** Reference counter for the string */
698-
unsigned int refs : CONFIG_ECMA_REFERENCE_COUNTER_WIDTH;
699-
700-
/** Where the string's data is placed (ecma_string_container_t) */
701-
uint8_t container;
727+
uint16_t refs_and_container;
702728

703729
/** Hash of the string (calculated from two last characters of the string) */
704730
lit_string_hash_t hash;
@@ -712,10 +738,10 @@ typedef struct ecma_string_t
712738
mem_cpointer_t lit_cp;
713739

714740
/** Compressed pointer to an ecma_collection_header_t */
715-
__extension__ mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH;
741+
mem_cpointer_t collection_cp;
716742

717743
/** Compressed pointer to an ecma_number_t */
718-
__extension__ mem_cpointer_t number_cp : ECMA_POINTER_FIELD_WIDTH;
744+
mem_cpointer_t number_cp;
719745

720746
/** UInt32-represented number placed locally in the descriptor */
721747
uint32_t uint32_number;

0 commit comments

Comments
 (0)