Improve the construction of "length" built-in strings.

The "length" property name is the most frequently used built-in string
and also frequently created by various hot-paths. New functions are
added to improve the speed of the "length" string creation.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2016-07-13 04:50:47 -07:00
parent b4bba2ef70
commit 6f1ce8d6bb
17 changed files with 131 additions and 84 deletions
@@ -183,6 +183,21 @@ ecma_init_ecma_string_from_uint32 (ecma_string_t *string_desc_p, /**< ecma-strin
string_desc_p->u.uint32_number = uint32_number;
} /* ecma_init_ecma_string_from_uint32 */
/**
* Initialize a length ecma-string
*/
inline void __attr_always_inline___
ecma_init_ecma_length_string (ecma_string_t *string_desc_p) /**< ecma-string */
{
JERRY_ASSERT (lit_utf8_string_calc_hash ((const lit_utf8_byte_t *) "length", 6) == LIT_STRING_LENGTH_HASH);
string_desc_p->refs_and_container = ECMA_STRING_CONTAINER_MAGIC_STRING | ECMA_STRING_REF_ONE;
string_desc_p->hash = LIT_STRING_LENGTH_HASH;
string_desc_p->u.common_field = 0;
string_desc_p->u.magic_string_id = LIT_MAGIC_STRING_LENGTH;
} /* ecma_init_ecma_length_string */
/**
* Allocate new ecma-string and fill it with ecma-number
*
@@ -280,6 +295,20 @@ ecma_new_ecma_string_from_magic_string_ex_id (lit_magic_string_ex_id_t id) /**<
return string_desc_p;
} /* ecma_new_ecma_string_from_magic_string_ex_id */
/**
* Allocate new ecma-string and fill it with reference to length magic string
*
* @return pointer to ecma-string descriptor
*/
ecma_string_t *
ecma_new_ecma_length_string (void)
{
ecma_string_t *string_desc_p = ecma_alloc_string ();
ecma_init_ecma_length_string (string_desc_p);
return string_desc_p;
} /* ecma_new_ecma_length_string */
/**
* Concatenate ecma-strings
*
@@ -761,6 +790,32 @@ ecma_string_is_empty (const ecma_string_t *str_p) /**< ecma-string */
&& str_p->u.magic_string_id == LIT_MAGIC_STRING__EMPTY);
} /* ecma_string_is_empty */
/**
* Checks whether the string equals to "length".
*
* @return true if the string equals to "length"
* false otherwise
*/
inline bool __attr_always_inline___
ecma_string_is_length (const ecma_string_t *string_p) /**< property name */
{
ecma_string_container_t container = ECMA_STRING_GET_CONTAINER (string_p);
if (container == ECMA_STRING_CONTAINER_MAGIC_STRING)
{
return string_p->u.magic_string_id == LIT_MAGIC_STRING_LENGTH;
}
if (container != ECMA_STRING_CONTAINER_HEAP_UTF8_STRING
|| string_p->u.utf8_string.size != 6
|| string_p->hash != LIT_STRING_LENGTH_HASH)
{
return false;
}
return !strncmp ((char *) (string_p + 1), "length", 6);
} /* ecma_string_is_length */
/**
* Long path part of ecma-string to ecma-string comparison routine
*
+3
View File
@@ -168,6 +168,7 @@ extern ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t);
extern ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t);
extern ecma_string_t *ecma_new_ecma_string_from_magic_string_id (lit_magic_string_id_t);
extern ecma_string_t *ecma_new_ecma_string_from_magic_string_ex_id (lit_magic_string_ex_id_t);
extern ecma_string_t *ecma_new_ecma_length_string ();
extern ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *, ecma_string_t *);
extern void ecma_ref_ecma_string (ecma_string_t *);
extern void ecma_deref_ecma_string (ecma_string_t *);
@@ -179,7 +180,9 @@ ecma_string_copy_to_utf8_buffer (const ecma_string_t *, lit_utf8_byte_t *, lit_u
extern void ecma_string_to_utf8_bytes (const ecma_string_t *, lit_utf8_byte_t *, lit_utf8_size_t);
extern const lit_utf8_byte_t *ecma_string_raw_chars (const ecma_string_t *, lit_utf8_size_t *, bool *);
extern void ecma_init_ecma_string_from_uint32 (ecma_string_t *, uint32_t);
extern void ecma_init_ecma_length_string (ecma_string_t *);
extern bool ecma_string_is_empty (const ecma_string_t *);
extern bool ecma_string_is_length (const ecma_string_t *);
extern bool ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *, const ecma_string_t *);
extern bool ecma_compare_ecma_strings (const ecma_string_t *, const ecma_string_t *);