Skip to content

Commit a5143e1

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 e1f20ad commit a5143e1

File tree

5 files changed

+328
-150
lines changed

5 files changed

+328
-150
lines changed

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,16 +689,40 @@ typedef enum
689689
ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< the ecma-string is equal to one of external magic strings */
690690
} ecma_string_container_t;
691691

692+
/**
693+
* Mask for getting the container of a string.
694+
*/
695+
#define ECMA_STRING_CONTAINER_MASK 0x7u
696+
697+
/**
698+
* Value for increasing or decreasing the reference counter.
699+
*/
700+
#define ECMA_STRING_REF_ONE (1u << 3)
701+
702+
/**
703+
* Maximum value of the reference counter (8191).
704+
*/
705+
#define ECMA_STRING_MAX_REF (0x1fffu << 3)
706+
707+
/**
708+
* Set reference counter to zero (for refs_and_container member below).
709+
*/
710+
#define ECMA_STRING_SET_REF_TO_ONE(refs_and_container) \
711+
((uint16_t) (((refs_and_container) & ECMA_STRING_CONTAINER_MASK) | ECMA_STRING_REF_ONE))
712+
713+
/**
714+
* Returns with the container type of a string.
715+
*/
716+
#define ECMA_STRING_GET_CONTAINER(string_desc_p) \
717+
((ecma_string_container_t) ((string_desc_p)->refs_and_container & ECMA_STRING_CONTAINER_MASK))
718+
692719
/**
693720
* ECMA string-value descriptor
694721
*/
695722
typedef struct ecma_string_t
696723
{
697724
/** 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;
725+
uint16_t refs_and_container;
702726

703727
/** Hash of the string (calculated from two last characters of the string) */
704728
lit_string_hash_t hash;
@@ -712,10 +736,10 @@ typedef struct ecma_string_t
712736
mem_cpointer_t lit_cp;
713737

714738
/** Compressed pointer to an ecma_collection_header_t */
715-
__extension__ mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH;
739+
mem_cpointer_t collection_cp;
716740

717741
/** Compressed pointer to an ecma_number_t */
718-
__extension__ mem_cpointer_t number_cp : ECMA_POINTER_FIELD_WIDTH;
742+
mem_cpointer_t number_cp;
719743

720744
/** UInt32-represented number placed locally in the descriptor */
721745
uint32_t uint32_number;

0 commit comments

Comments
 (0)