Skip to content

Commit af24694

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 af24694

File tree

5 files changed

+343
-154
lines changed

5 files changed

+343
-154
lines changed

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -686,19 +687,45 @@ typedef enum
686687
ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
687688
stored locally in the string's descriptor */
688689
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 */
690+
ECMA_STRING_CONTAINER_MAGIC_STRING_EX, /**< the ecma-string is equal to one of external magic strings */
691+
692+
ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< maximum value */
690693
} ecma_string_container_t;
691694

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

703730
/** Hash of the string (calculated from two last characters of the string) */
704731
lit_string_hash_t hash;
@@ -712,10 +739,10 @@ typedef struct ecma_string_t
712739
mem_cpointer_t lit_cp;
713740

714741
/** Compressed pointer to an ecma_collection_header_t */
715-
__extension__ mem_cpointer_t collection_cp : ECMA_POINTER_FIELD_WIDTH;
742+
mem_cpointer_t collection_cp;
716743

717744
/** Compressed pointer to an ecma_number_t */
718-
__extension__ mem_cpointer_t number_cp : ECMA_POINTER_FIELD_WIDTH;
745+
mem_cpointer_t number_cp;
719746

720747
/** UInt32-represented number placed locally in the descriptor */
721748
uint32_t uint32_number;

0 commit comments

Comments
 (0)