Improve magic string handling. (#2221)

Remove unnecessary ref / deref calls when magic strings are used.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2018-03-01 13:31:15 +01:00
committed by GitHub
parent 26ee8f7137
commit d60d4dbba9
30 changed files with 306 additions and 497 deletions
@@ -127,8 +127,7 @@ ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property
JERRY_ASSERT (id == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
|| id == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
ecma_string_t *name_p = ecma_get_magic_string (id);
ecma_property_t *property_p = ecma_find_named_property (obj_p, name_p);
ecma_property_t *property_p = ecma_find_named_property (obj_p, ecma_get_magic_string (id));
if (property_p == NULL)
{
+32 -32
View File
@@ -220,7 +220,7 @@ ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, /**< utf-8 stri
if (magic_string_ex_id < lit_get_magic_string_ex_count ())
{
return ecma_get_magic_string_ex (magic_string_ex_id);
return ecma_new_ecma_string_from_magic_string_ex_id (magic_string_ex_id);
}
}
@@ -409,6 +409,22 @@ ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< uint32 value of t
return string_p;
} /* ecma_new_ecma_string_from_uint32 */
/**
* Returns the constant assigned to the uint32 number.
*
* Note:
* Calling ecma_deref_ecma_string on the returned pointer is optional.
*
* @return pointer to ecma-string descriptor
*/
ecma_string_t *
ecma_get_ecma_string_from_uint32 (uint32_t uint32_number)
{
JERRY_ASSERT (uint32_number <= ECMA_DIRECT_STRING_MAX_IMM);
return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number);
} /* ecma_get_ecma_string_from_uint32 */
/**
* Allocate new ecma-string and fill it with ecma-number
*
@@ -458,16 +474,19 @@ ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */
} /* ecma_new_ecma_string_from_number */
/**
* Allocate new ecma-string and fill it with reference to ECMA magic string
* Returns the constant assigned to the magic string id.
*
* Note:
* Calling ecma_deref_ecma_string on the returned pointer is optional.
*
* @return pointer to ecma-string descriptor
*/
inline ecma_string_t * __attr_always_inline___
ecma_new_ecma_string_from_magic_string_id (lit_magic_string_id_t id) /**< identifier of magic string */
ecma_get_magic_string (lit_magic_string_id_t id) /**< identifier of magic string */
{
JERRY_ASSERT (id < LIT_MAGIC_STRING__COUNT);
return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_MAGIC, (uintptr_t) id);
} /* ecma_new_ecma_string_from_magic_string_id */
} /* ecma_get_magic_string */
/**
* Allocate new ecma-string and fill it with reference to ECMA magic string
@@ -494,15 +513,18 @@ ecma_new_ecma_string_from_magic_string_ex_id (lit_magic_string_ex_id_t id) /**<
} /* ecma_new_ecma_string_from_magic_string_ex_id */
/**
* Allocate new ecma-string and fill it with reference to length magic string
* Returns the constant assigned to the length magic string.
*
* Note:
* Calling ecma_deref_ecma_string on the returned pointer is optional.
*
* @return pointer to ecma-string descriptor
*/
ecma_string_t *
ecma_new_ecma_length_string (void)
ecma_get_length_string (void)
{
return ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_LENGTH);
} /* ecma_new_ecma_length_string */
return ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
} /* ecma_get_length_string */
/**
* Append a cesu8 string after an ecma-string
@@ -666,7 +688,7 @@ ecma_append_chars_to_string (ecma_string_t *string1_p, /**< base ecma-string */
if (magic_string_ex_id < lit_get_magic_string_ex_count ())
{
ecma_deref_ecma_string (string1_p);
return ecma_get_magic_string_ex (magic_string_ex_id);
return ecma_new_ecma_string_from_magic_string_ex_id (magic_string_ex_id);
}
}
@@ -844,7 +866,7 @@ ecma_append_magic_string_to_string (ecma_string_t *string1_p,
{
if (unlikely (ecma_string_is_empty (string1_p)))
{
return ecma_new_ecma_string_from_magic_string_id (string2_id);
return ecma_get_magic_string (string2_id);
}
const lit_utf8_byte_t *cesu8_string2_p = lit_get_magic_string_utf8 (string2_id);
@@ -2153,28 +2175,6 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
return ch;
} /* ecma_string_get_char_at_pos */
/**
* Get specified magic string
*
* @return ecma-string containing specified magic string
*/
inline ecma_string_t * __attr_always_inline___
ecma_get_magic_string (lit_magic_string_id_t id) /**< magic string id */
{
return ecma_new_ecma_string_from_magic_string_id (id);
} /* ecma_get_magic_string */
/**
* Get specified external magic string
*
* @return ecma-string containing specified external magic string
*/
inline ecma_string_t * __attr_always_inline___
ecma_get_magic_string_ex (lit_magic_string_ex_id_t id) /**< external magic string id */
{
return ecma_new_ecma_string_from_magic_string_ex_id (id);
} /* ecma_get_magic_string_ex */
/**
* Check if passed string equals to one of magic strings
* and if equal magic string was found, return it's id in 'out_id_p' argument.
@@ -514,6 +514,15 @@ ecma_make_string_value (const ecma_string_t *ecma_string_p) /**< string to refer
return ecma_pointer_to_ecma_value (ecma_string_p) | ECMA_TYPE_STRING;
} /* ecma_make_string_value */
/**
* String value constructor
*/
inline ecma_value_t __attr_pure___ __attr_always_inline___
ecma_make_magic_string_value (lit_magic_string_id_t id) /**< magic string id */
{
return (ecma_value_t) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_MAGIC, (uintptr_t) id);
} /* ecma_make_magic_string_value */
/**
* Object value constructor
*/
+4 -4
View File
@@ -167,6 +167,7 @@ ecma_value_t ecma_make_number_value (ecma_number_t ecma_number);
ecma_value_t ecma_make_int32_value (int32_t int32_number);
ecma_value_t ecma_make_uint32_value (uint32_t uint32_number);
ecma_value_t ecma_make_string_value (const ecma_string_t *ecma_string_p) __attr_pure___;
ecma_value_t ecma_make_magic_string_value (lit_magic_string_id_t id) __attr_pure___;
ecma_value_t ecma_make_object_value (const ecma_object_t *object_p) __attr_pure___;
ecma_value_t ecma_make_error_reference_value (const ecma_error_reference_t *error_ref_p) __attr_pure___;
ecma_value_t ecma_make_collection_chunk_value (const ecma_collection_chunk_t *collection_chunk_p) __attr_pure___;
@@ -195,10 +196,11 @@ ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8
lit_utf8_size_t string_size);
ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit);
ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number);
ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number);
ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num);
ecma_string_t *ecma_new_ecma_string_from_magic_string_id (lit_magic_string_id_t id);
ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id);
ecma_string_t *ecma_new_ecma_string_from_magic_string_ex_id (lit_magic_string_ex_id_t id);
ecma_string_t *ecma_new_ecma_length_string (void);
ecma_string_t *ecma_get_length_string (void);
ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_p,
const lit_utf8_byte_t *cesu8_string2_p,
lit_utf8_size_t cesu8_string2_size,
@@ -252,8 +254,6 @@ lit_utf8_size_t ecma_string_get_size (const ecma_string_t *string_p);
lit_utf8_size_t ecma_string_get_utf8_size (const ecma_string_t *string_p);
ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, ecma_length_t index);
ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id);
ecma_string_t *ecma_get_magic_string_ex (lit_magic_string_ex_id_t id);
lit_magic_string_id_t ecma_get_string_magic (const ecma_string_t *string_p);
lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p);