Improve parse_identifier (#4691)
Ascii string length is no longer computed during string allocation. JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz batizjob@gmail.com
This commit is contained in:
@@ -335,6 +335,33 @@ ecma_find_special_string (const lit_utf8_byte_t *string_p, /**< utf8 string */
|
||||
return NULL;
|
||||
} /* ecma_find_special_string */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with characters from ascii characters
|
||||
*
|
||||
* @return pointer to ecma-string descriptor
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_new_ecma_string_from_ascii (const lit_utf8_byte_t *string_p, /**< ascii string */
|
||||
lit_utf8_size_t string_size) /**< string size */
|
||||
{
|
||||
JERRY_ASSERT (string_p != NULL || string_size == 0);
|
||||
|
||||
ecma_string_t *string_desc_p = ecma_find_special_string (string_p, string_size);
|
||||
|
||||
if (string_desc_p != NULL)
|
||||
{
|
||||
return string_desc_p;
|
||||
}
|
||||
|
||||
lit_utf8_byte_t *data_p;
|
||||
string_desc_p = ecma_new_ecma_string_from_utf8_buffer (string_size, string_size, &data_p);
|
||||
|
||||
string_desc_p->u.hash = lit_utf8_string_calc_hash (string_p, string_size);
|
||||
memcpy (data_p, string_p, string_size);
|
||||
|
||||
return string_desc_p;
|
||||
} /* ecma_new_ecma_string_from_ascii */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with characters from the utf8 string
|
||||
*
|
||||
@@ -2449,8 +2476,7 @@ ecma_string_substr (const ecma_string_t *string_p, /**< pointer to an ecma strin
|
||||
|
||||
if (string_length == buffer_size)
|
||||
{
|
||||
ecma_string_p = ecma_new_ecma_string_from_utf8 (start_p + start_pos,
|
||||
(lit_utf8_size_t) end_pos);
|
||||
ecma_string_p = ecma_new_ecma_string_from_utf8 (start_p + start_pos, (lit_utf8_size_t) end_pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -299,7 +299,10 @@ ecma_length_t ecma_op_advance_string_index (ecma_string_t *str_p, ecma_length_t
|
||||
ecma_string_t *ecma_new_map_key_string (ecma_value_t value);
|
||||
bool ecma_prop_name_is_map_key (ecma_string_t *string_p);
|
||||
#endif /* JERRY_BUILTIN_CONTAINER */
|
||||
ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size);
|
||||
ecma_string_t *ecma_new_ecma_string_from_ascii (const lit_utf8_byte_t *string_p,
|
||||
lit_utf8_size_t string_size);
|
||||
ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p,
|
||||
lit_utf8_size_t string_size);
|
||||
ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p,
|
||||
lit_utf8_size_t string_size);
|
||||
ecma_string_t *ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size,
|
||||
|
||||
@@ -165,9 +165,11 @@ ecma_finalize_lit_storage (void)
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string to be searched */
|
||||
lit_utf8_size_t size) /**< size of the string */
|
||||
lit_utf8_size_t size, /**< size of the string */
|
||||
bool is_ascii) /**< encode of the string */
|
||||
{
|
||||
ecma_string_t *string_p = ecma_new_ecma_string_from_utf8 (chars_p, size);
|
||||
ecma_string_t *string_p = (is_ascii ? ecma_new_ecma_string_from_ascii (chars_p, size)
|
||||
: ecma_new_ecma_string_from_utf8 (chars_p, size));
|
||||
|
||||
if (ECMA_IS_DIRECT_STRING (string_p))
|
||||
{
|
||||
@@ -702,7 +704,7 @@ ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */
|
||||
|
||||
uint16_t length = *(const uint16_t *) literal_p;
|
||||
|
||||
return ecma_find_or_create_literal_string (literal_p + sizeof (uint16_t), length);
|
||||
return ecma_find_or_create_literal_string (literal_p + sizeof (uint16_t), length, false);
|
||||
} /* ecma_snapshot_get_literal */
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ typedef struct
|
||||
|
||||
void ecma_finalize_lit_storage (void);
|
||||
|
||||
ecma_value_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, lit_utf8_size_t size);
|
||||
ecma_value_t ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, lit_utf8_size_t size, bool is_ascii);
|
||||
ecma_value_t ecma_find_or_create_literal_number (ecma_number_t number_arg);
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
ecma_value_t ecma_find_or_create_literal_bigint (ecma_value_t bigint);
|
||||
|
||||
Reference in New Issue
Block a user