Introduce ECMA_STRING_TO_UTF8_STRING and ECMA_FINALIZE_UTF8_STRING

Benefits:
 * Better readability and maintenance
 * Better heap consumption on 'date-format-xparb.js' test of SunSpider

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
László Langó
2016-03-29 09:23:23 +02:00
parent 9ab0998ae6
commit 9dad7dbfba
13 changed files with 136 additions and 195 deletions
+29 -34
View File
@@ -549,25 +549,18 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */
case ECMA_STRING_CONTAINER_MAGIC_STRING: case ECMA_STRING_CONTAINER_MAGIC_STRING:
case ECMA_STRING_CONTAINER_MAGIC_STRING_EX: case ECMA_STRING_CONTAINER_MAGIC_STRING_EX:
{ {
const lit_utf8_size_t string_size = ecma_string_get_size (str_p); ecma_number_t num;
if (string_size == 0) ECMA_STRING_TO_UTF8_STRING (str_p, str_buffer_p, str_buffer_size);
if (str_buffer_size == 0)
{ {
return ECMA_NUMBER_ZERO; return ECMA_NUMBER_ZERO;
} }
ecma_number_t num; num = ecma_utf8_string_to_number (str_buffer_p, str_buffer_size);
MEM_DEFINE_LOCAL_ARRAY (str_buffer_p, string_size, lit_utf8_byte_t); ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size);
lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (str_p,
str_buffer_p,
string_size);
JERRY_ASSERT (bytes_copied == string_size);
num = ecma_utf8_string_to_number (str_buffer_p, string_size);
MEM_FINALIZE_LOCAL_ARRAY (str_buffer_p);
return num; return num;
} }
@@ -1345,12 +1338,16 @@ static bool
ecma_is_string_magic_longpath (const ecma_string_t *string_p, /**< ecma-string */ ecma_is_string_magic_longpath (const ecma_string_t *string_p, /**< ecma-string */
lit_magic_string_id_t *out_id_p) /**< [out] magic string's id */ lit_magic_string_id_t *out_id_p) /**< [out] magic string's id */
{ {
lit_utf8_byte_t utf8_string_buffer[LIT_MAGIC_STRING_LENGTH_LIMIT]; lit_utf8_size_t utf8_str_size;
bool is_ascii;
const lit_utf8_byte_t *utf8_str_p = ecma_string_raw_chars (string_p, &utf8_str_size, &is_ascii);
lit_utf8_size_t copied = ecma_string_to_utf8_string (string_p, utf8_string_buffer, sizeof (utf8_string_buffer)); if (utf8_str_p == NULL || !is_ascii)
JERRY_ASSERT (copied <= sizeof (utf8_string_buffer)); {
return false;
}
return lit_is_utf8_string_magic (utf8_string_buffer, (lit_utf8_size_t) copied, out_id_p); return lit_is_utf8_string_magic (utf8_str_p, utf8_str_size, out_id_p);
} /* ecma_is_string_magic_longpath */ } /* ecma_is_string_magic_longpath */
/** /**
@@ -1366,12 +1363,16 @@ static bool
ecma_is_ex_string_magic_longpath (const ecma_string_t *string_p, /**< ecma-string */ ecma_is_ex_string_magic_longpath (const ecma_string_t *string_p, /**< ecma-string */
lit_magic_string_ex_id_t *out_id_p) /**< [out] external magic string's id */ lit_magic_string_ex_id_t *out_id_p) /**< [out] external magic string's id */
{ {
lit_utf8_byte_t utf8_string_buffer[LIT_MAGIC_STRING_LENGTH_LIMIT]; lit_utf8_size_t utf8_str_size;
bool is_ascii;
const lit_utf8_byte_t *utf8_str_p = ecma_string_raw_chars (string_p, &utf8_str_size, &is_ascii);
lit_utf8_size_t copied = ecma_string_to_utf8_string (string_p, utf8_string_buffer, sizeof (utf8_string_buffer)); if (utf8_str_p == NULL || !is_ascii)
JERRY_ASSERT (copied <= sizeof (utf8_string_buffer)); {
return false;
}
return lit_is_ex_utf8_string_magic (utf8_string_buffer, (lit_utf8_size_t) copied, out_id_p); return lit_is_ex_utf8_string_magic (utf8_str_p, utf8_str_size, out_id_p);
} /* ecma_is_ex_string_magic_longpath */ } /* ecma_is_ex_string_magic_longpath */
/** /**
@@ -1556,19 +1557,14 @@ ecma_string_trim (const ecma_string_t *string_p) /**< pointer to an ecma string
{ {
ecma_string_t *ret_string_p; ecma_string_t *ret_string_p;
lit_utf8_size_t buffer_size = ecma_string_get_size (string_p); ECMA_STRING_TO_UTF8_STRING (string_p, utf8_str_p, utf8_str_size);
if (buffer_size > 0) if (utf8_str_size > 0)
{ {
MEM_DEFINE_LOCAL_ARRAY (utf8_str_p, buffer_size, lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (string_p, utf8_str_p, buffer_size);
JERRY_ASSERT (sz == buffer_size);
ecma_char_t ch; ecma_char_t ch;
lit_utf8_size_t read_size; lit_utf8_size_t read_size;
lit_utf8_byte_t *nonws_start_p = utf8_str_p + buffer_size; const lit_utf8_byte_t *nonws_start_p = utf8_str_p + utf8_str_size;
lit_utf8_byte_t *current_p = utf8_str_p; const lit_utf8_byte_t *current_p = utf8_str_p;
/* Trim front. */ /* Trim front. */
while (current_p < nonws_start_p) while (current_p < nonws_start_p)
@@ -1585,7 +1581,7 @@ ecma_string_trim (const ecma_string_t *string_p) /**< pointer to an ecma string
current_p += read_size; current_p += read_size;
} }
current_p = utf8_str_p + buffer_size; current_p = utf8_str_p + utf8_str_size;
/* Trim back. */ /* Trim back. */
while (current_p > utf8_str_p) while (current_p > utf8_str_p)
@@ -1611,16 +1607,15 @@ ecma_string_trim (const ecma_string_t *string_p) /**< pointer to an ecma string
{ {
ret_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); ret_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
} }
MEM_FINALIZE_LOCAL_ARRAY (utf8_str_p);
} }
else else
{ {
ret_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); ret_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
} }
return ret_string_p; ECMA_FINALIZE_UTF8_STRING (utf8_str_p, utf8_str_size);
return ret_string_p;
} /* ecma_string_trim */ } /* ecma_string_trim */
/** /**
+30
View File
@@ -52,6 +52,36 @@
*/ */
#define ECMA_SET_POINTER(field, non_compressed_pointer) MEM_CP_SET_POINTER (field, non_compressed_pointer) #define ECMA_SET_POINTER(field, non_compressed_pointer) MEM_CP_SET_POINTER (field, non_compressed_pointer)
/**
* Convert ecma-string's contents to a cesu-8 string and put it into a buffer.
*/
#define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \
utf8_ptr, /**< [out] output buffer pointer */ \
utf8_str_size) /**< [out] output buffer size */ \
lit_utf8_size_t utf8_str_size; \
bool utf8_ptr ## must_be_freed; \
const lit_utf8_byte_t *utf8_ptr = ecma_string_raw_chars (ecma_str_ptr, &utf8_str_size, &utf8_ptr ## must_be_freed); \
utf8_ptr ## must_be_freed = false; /* it was used as 'is_ascii' in 'ecma_string_raw_chars', so we must reset it */ \
\
if (utf8_ptr == NULL) \
{ \
utf8_ptr = (const lit_utf8_byte_t *) (mem_heap_alloc_block (utf8_str_size)); \
lit_utf8_size_t sz = ecma_string_to_utf8_string (ecma_str_ptr, (lit_utf8_byte_t *) utf8_ptr, utf8_str_size); \
JERRY_ASSERT (sz == utf8_str_size); \
utf8_ptr ## must_be_freed = true; \
}
/**
* Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING'
*/
#define ECMA_FINALIZE_UTF8_STRING(utf8_ptr, /**< pointer to character buffer */ \
utf8_str_size) /**< buffer size */ \
if (utf8_ptr ## must_be_freed) \
{ \
JERRY_ASSERT (utf8_ptr != NULL); \
mem_heap_free_block ((void *) utf8_ptr, utf8_str_size); \
}
/* ecma-helpers-value.c */ /* ecma-helpers-value.c */
extern ecma_type_t ecma_get_value_type_field (ecma_value_t) __attr_pure___; extern ecma_type_t ecma_get_value_type_field (ecma_value_t) __attr_pure___;
@@ -205,14 +205,10 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
ecma_string_t *date_str_p = ecma_get_string_from_value (date_str_value); ecma_string_t *date_str_p = ecma_get_string_from_value (date_str_value);
lit_utf8_size_t date_str_size = ecma_string_get_size (date_str_p); ECMA_STRING_TO_UTF8_STRING (date_str_p, date_start_p, date_start_size);
MEM_DEFINE_LOCAL_ARRAY (date_start_p, date_str_size, lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (date_str_p, date_start_p, date_str_size); lit_utf8_byte_t *date_str_curr_p = (lit_utf8_byte_t *) date_start_p;
JERRY_ASSERT (sz == date_str_size); const lit_utf8_byte_t *date_str_end_p = date_start_p + date_start_size;
lit_utf8_byte_t *date_str_curr_p = date_start_p;
const lit_utf8_byte_t *date_str_end_p = date_start_p + date_str_size;
/* 1. read year */ /* 1. read year */
ecma_number_t year = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 4); ecma_number_t year = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 4);
@@ -396,7 +392,7 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
ret_value = ecma_make_number_value (date_num_p); ret_value = ecma_make_number_value (date_num_p);
MEM_FINALIZE_LOCAL_ARRAY (date_start_p); ECMA_FINALIZE_UTF8_STRING (date_start_p, date_start_size);
ECMA_FINALIZE (date_str_value); ECMA_FINALIZE (date_str_value);
return ret_value; return ret_value;
@@ -203,23 +203,17 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value); ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value);
ecma_string_t *number_str_p = ecma_get_string_from_value (string_var); ecma_string_t *number_str_p = ecma_get_string_from_value (string_var);
lit_utf8_size_t str_size = ecma_string_get_size (number_str_p); ECMA_STRING_TO_UTF8_STRING (number_str_p, string_buff, string_buff_size);
if (str_size > 0) if (string_buff_size > 0)
{ {
MEM_DEFINE_LOCAL_ARRAY (string_buff, str_size, lit_utf8_byte_t); lit_utf8_byte_t *string_curr_p = (lit_utf8_byte_t *) string_buff;
const lit_utf8_byte_t *string_end_p = string_buff + string_buff_size;
lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
string_buff,
str_size);
JERRY_ASSERT (bytes_copied == str_size);
lit_utf8_byte_t *string_curr_p = string_buff;
lit_utf8_byte_t *string_end_p = string_buff + str_size;
/* 2. Remove leading whitespace. */ /* 2. Remove leading whitespace. */
lit_utf8_byte_t *start_p = string_end_p; lit_utf8_byte_t *start_p = (lit_utf8_byte_t *) string_end_p;
lit_utf8_byte_t *end_p = string_end_p; lit_utf8_byte_t *end_p = start_p;
while (string_curr_p < string_end_p) while (string_curr_p < string_end_p)
{ {
@@ -396,7 +390,6 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
ret_value = ecma_make_number_value (ret_num_p); ret_value = ecma_make_number_value (ret_num_p);
} }
MEM_FINALIZE_LOCAL_ARRAY (string_buff);
} }
else else
{ {
@@ -405,6 +398,7 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
ret_value = ecma_make_number_value (ret_num_p); ret_value = ecma_make_number_value (ret_num_p);
} }
ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size);
ECMA_FINALIZE (string_var); ECMA_FINALIZE (string_var);
return ret_value; return ret_value;
} /* ecma_builtin_global_object_parse_int */ } /* ecma_builtin_global_object_parse_int */
@@ -428,22 +422,15 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value); ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value);
ecma_string_t *number_str_p = ecma_get_string_from_value (string_var); ecma_string_t *number_str_p = ecma_get_string_from_value (string_var);
lit_utf8_size_t str_size = ecma_string_get_size (number_str_p); ECMA_STRING_TO_UTF8_STRING (number_str_p, string_buff, string_buff_size);
if (str_size > 0) if (string_buff_size > 0)
{ {
MEM_DEFINE_LOCAL_ARRAY (string_buff, str_size, lit_utf8_byte_t); lit_utf8_byte_t *str_curr_p = (lit_utf8_byte_t *) string_buff;
const lit_utf8_byte_t *str_end_p = string_buff + string_buff_size;
lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (number_str_p, lit_utf8_byte_t *start_p = (lit_utf8_byte_t *) str_end_p;
string_buff, lit_utf8_byte_t *end_p = (lit_utf8_byte_t *) str_end_p;
str_size);
JERRY_ASSERT (bytes_copied == str_size);
lit_utf8_byte_t *str_curr_p = string_buff;
lit_utf8_byte_t *str_end_p = string_buff + str_size;
lit_utf8_byte_t *start_p = str_end_p;
lit_utf8_byte_t *end_p = str_end_p;
/* 2. Find first non whitespace char and set starting position. */ /* 2. Find first non whitespace char and set starting position. */
while (str_curr_p < str_end_p) while (str_curr_p < str_end_p)
@@ -626,7 +613,6 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
*ret_num_p = ecma_number_make_nan (); *ret_num_p = ecma_number_make_nan ();
ret_value = ecma_make_number_value (ret_num_p); ret_value = ecma_make_number_value (ret_num_p);
} }
MEM_FINALIZE_LOCAL_ARRAY (string_buff);
} }
/* String length is zero. */ /* String length is zero. */
else else
@@ -636,6 +622,7 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
ret_value = ecma_make_number_value (ret_num_p); ret_value = ecma_make_number_value (ret_num_p);
} }
ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size);
ECMA_FINALIZE (string_var); ECMA_FINALIZE (string_var);
return ret_value; return ret_value;
@@ -565,12 +565,8 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
ecma_length_t *ret_index_p) /**< position found in original string */ ecma_length_t *ret_index_p) /**< position found in original string */
{ {
bool match_found = false; bool match_found = false;
const ecma_length_t original_len = ecma_string_get_length (original_str_p); const ecma_length_t original_len = ecma_string_get_length (original_str_p);
const lit_utf8_size_t original_size = ecma_string_get_size (original_str_p);
const ecma_length_t search_len = ecma_string_get_length (search_str_p); const ecma_length_t search_len = ecma_string_get_length (search_str_p);
const lit_utf8_size_t search_size = ecma_string_get_size (search_str_p);
if (search_len <= original_len) if (search_len <= original_len)
{ {
@@ -582,34 +578,20 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
else else
{ {
/* create utf8 string from original string and advance to position */ /* create utf8 string from original string and advance to position */
MEM_DEFINE_LOCAL_ARRAY (original_str_utf8_p, ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8_p, original_str_size);
original_size,
lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (original_str_p,
original_str_utf8_p,
original_size);
JERRY_ASSERT (sz == original_size);
ecma_length_t index = start_pos; ecma_length_t index = start_pos;
lit_utf8_byte_t *original_str_curr_p = original_str_utf8_p; lit_utf8_byte_t *original_str_curr_p = (lit_utf8_byte_t *) original_str_utf8_p;
for (ecma_length_t idx = 0; idx < index; idx++) for (ecma_length_t idx = 0; idx < index; idx++)
{ {
lit_utf8_incr (&original_str_curr_p); lit_utf8_incr (&original_str_curr_p);
} }
/* create utf8 string from search string */ /* create utf8 string from search string */
MEM_DEFINE_LOCAL_ARRAY (search_str_utf8_p, ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8_p, search_str_size);
search_size,
lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (search_str_p, lit_utf8_byte_t *search_str_curr_p = (lit_utf8_byte_t *) search_str_utf8_p;
search_str_utf8_p,
search_size);
JERRY_ASSERT (sz == search_size);
lit_utf8_byte_t *search_str_curr_p = search_str_utf8_p;
/* iterate original string and try to match at each position */ /* iterate original string and try to match at each position */
bool searching = true; bool searching = true;
@@ -667,8 +649,8 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index
} }
} }
MEM_FINALIZE_LOCAL_ARRAY (search_str_utf8_p); ECMA_FINALIZE_UTF8_STRING (search_str_utf8_p, search_str_size);
MEM_FINALIZE_LOCAL_ARRAY (original_str_utf8_p); ECMA_FINALIZE_UTF8_STRING (original_str_utf8_p, original_str_size);
} }
} }
@@ -76,12 +76,12 @@ typedef struct
{ {
ecma_json_token_type_t type; /**< type of the current token */ ecma_json_token_type_t type; /**< type of the current token */
lit_utf8_byte_t *current_p; /**< current position of the string processed by the parser */ lit_utf8_byte_t *current_p; /**< current position of the string processed by the parser */
lit_utf8_byte_t *end_p; /**< end of the string processed by the parser */ const lit_utf8_byte_t *end_p; /**< end of the string processed by the parser */
union union
{ {
struct struct
{ {
lit_utf8_byte_t *start_p; /**< when type is string_token, it contains the start of the string */ const lit_utf8_byte_t *start_p; /**< when type is string_token, it contains the start of the string */
lit_utf8_size_t size; /**< when type is string_token, it contains the size of the string */ lit_utf8_size_t size; /**< when type is string_token, it contains the size of the string */
} string; } string;
ecma_number_t number; /**< when type is number_token, it contains the value of the number */ ecma_number_t number; /**< when type is number_token, it contains the value of the number */
@@ -286,11 +286,11 @@ ecma_builtin_json_parse_next_token (ecma_json_token_t *token_p) /**< token argum
lit_utf8_byte_t *current_p = token_p->current_p; lit_utf8_byte_t *current_p = token_p->current_p;
token_p->type = invalid_token; token_p->type = invalid_token;
/* while (current_p < token_p->end_p
* No need for end check since the string is zero terminated. && (*current_p == LIT_CHAR_SP
*/ || *current_p == LIT_CHAR_CR
while (*current_p == LIT_CHAR_SP || *current_p == LIT_CHAR_CR || *current_p == LIT_CHAR_LF
|| *current_p == LIT_CHAR_LF || *current_p == LIT_CHAR_TAB) || *current_p == LIT_CHAR_TAB))
{ {
current_p++; current_p++;
} }
@@ -500,7 +500,7 @@ ecma_builtin_json_parse_value (ecma_json_token_t *token_p) /**< token argument *
break; break;
} }
lit_utf8_byte_t *string_start_p = token_p->u.string.start_p; const lit_utf8_byte_t *string_start_p = token_p->u.string.start_p;
lit_utf8_size_t string_size = token_p->u.string.size; lit_utf8_size_t string_size = token_p->u.string.size;
ecma_builtin_json_parse_next_token (token_p); ecma_builtin_json_parse_next_token (token_p);
@@ -709,19 +709,12 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg
ret_value); ret_value);
ecma_string_t *string_p = ecma_get_string_from_value (string); ecma_string_t *string_p = ecma_get_string_from_value (string);
ecma_length_t string_size = (uint32_t) ecma_string_get_size (string_p);
lit_utf8_size_t buffer_size = sizeof (lit_utf8_byte_t) * (string_size + 1);
MEM_DEFINE_LOCAL_ARRAY (str_start_p, buffer_size, lit_utf8_byte_t); ECMA_STRING_TO_UTF8_STRING (string_p, str_start_p, str_start_size);
lit_utf8_size_t sz = ecma_string_to_utf8_string (string_p, str_start_p, buffer_size);
JERRY_ASSERT (sz == string_size);
str_start_p[string_size] = LIT_BYTE_NULL;
ecma_json_token_t token; ecma_json_token_t token;
token.current_p = str_start_p; token.current_p = (lit_utf8_byte_t *) str_start_p;
token.end_p = str_start_p + string_size; token.end_p = str_start_p + str_start_size;
ecma_value_t final_result = ecma_builtin_json_parse_value (&token); ecma_value_t final_result = ecma_builtin_json_parse_value (&token);
@@ -767,7 +760,7 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg
} }
} }
MEM_FINALIZE_LOCAL_ARRAY (str_start_p); ECMA_FINALIZE_UTF8_STRING (str_start_p, str_start_size);
ECMA_FINALIZE (string); ECMA_FINALIZE (string);
return ret_value; return ret_value;
@@ -1064,18 +1057,10 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
ecma_string_t *product_str_p = ecma_copy_or_ref_ecma_string (quote_str_p); ecma_string_t *product_str_p = ecma_copy_or_ref_ecma_string (quote_str_p);
ecma_string_t *tmp_str_p; ecma_string_t *tmp_str_p;
ecma_length_t string_size = ecma_string_get_size (string_p); ECMA_STRING_TO_UTF8_STRING (string_p, string_buff, string_buff_size);
MEM_DEFINE_LOCAL_ARRAY (string_buff, string_size, lit_utf8_byte_t); lit_utf8_byte_t *str_p = (lit_utf8_byte_t *) string_buff;
const lit_utf8_byte_t *str_end_p = string_buff + string_buff_size;
lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string_p,
string_buff,
string_size);
JERRY_ASSERT (bytes_copied == string_size);
lit_utf8_byte_t *str_p = string_buff;
const lit_utf8_byte_t *str_end_p = str_p + string_size;
while (str_p < str_end_p) while (str_p < str_end_p)
{ {
@@ -1196,7 +1181,7 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
} }
} }
MEM_FINALIZE_LOCAL_ARRAY (string_buff); ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size);
/* 3. */ /* 3. */
tmp_str_p = ecma_concat_ecma_strings (product_str_p, quote_str_p); tmp_str_p = ecma_concat_ecma_strings (product_str_p, quote_str_p);
@@ -1198,23 +1198,15 @@ ecma_builtin_string_prototype_object_replace_main (ecma_builtin_replace_search_c
ret_value); ret_value);
ecma_string_t *replace_string_p = ecma_get_string_from_value (to_string_replace_val); ecma_string_t *replace_string_p = ecma_get_string_from_value (to_string_replace_val);
lit_utf8_size_t replace_size = ecma_string_get_size (replace_string_p);
MEM_DEFINE_LOCAL_ARRAY (replace_start_p, ECMA_STRING_TO_UTF8_STRING (replace_string_p, replace_start_p, replace_start_size);
replace_size,
lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (replace_string_p,
replace_start_p,
replace_size);
JERRY_ASSERT (sz == replace_size);
context_p->replace_string_p = replace_string_p; context_p->replace_string_p = replace_string_p;
context_p->replace_str_curr_p = replace_start_p; context_p->replace_str_curr_p = (lit_utf8_byte_t *) replace_start_p;
ret_value = ecma_builtin_string_prototype_object_replace_loop (context_p); ret_value = ecma_builtin_string_prototype_object_replace_loop (context_p);
MEM_FINALIZE_LOCAL_ARRAY (replace_start_p); ECMA_FINALIZE_UTF8_STRING (replace_start_p, replace_start_size);
ECMA_FINALIZE (to_string_replace_val); ECMA_FINALIZE (to_string_replace_val);
} }
@@ -2073,16 +2065,8 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_value_t this_arg, /
/* 3. */ /* 3. */
ecma_string_t *input_string_p = ecma_get_string_from_value (to_string_val); ecma_string_t *input_string_p = ecma_get_string_from_value (to_string_val);
lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);
MEM_DEFINE_LOCAL_ARRAY (input_start_p, ECMA_STRING_TO_UTF8_STRING (input_string_p, input_start_p, input_start_size);
input_size,
lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
input_size);
JERRY_ASSERT (sz == input_size);
/* /*
* The URI encoding has two major phases: first we compute * The URI encoding has two major phases: first we compute
@@ -2090,8 +2074,8 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_value_t this_arg, /
*/ */
lit_utf8_size_t output_length = 0; lit_utf8_size_t output_length = 0;
lit_utf8_byte_t *input_str_curr_p = input_start_p; lit_utf8_byte_t *input_str_curr_p = (lit_utf8_byte_t *) input_start_p;
const lit_utf8_byte_t *input_str_end_p = input_start_p + input_size; const lit_utf8_byte_t *input_str_end_p = input_start_p + input_start_size;
while (input_str_curr_p < input_str_end_p) while (input_str_curr_p < input_str_end_p)
{ {
@@ -2130,7 +2114,7 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_value_t this_arg, /
lit_utf8_byte_t *output_char_p = output_start_p; lit_utf8_byte_t *output_char_p = output_start_p;
/* Encoding the output. */ /* Encoding the output. */
input_str_curr_p = input_start_p; input_str_curr_p = (lit_utf8_byte_t *) input_start_p;
while (input_str_curr_p < input_str_end_p) while (input_str_curr_p < input_str_end_p)
{ {
@@ -2166,7 +2150,7 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_value_t this_arg, /
ret_value = ecma_make_string_value (output_string_p); ret_value = ecma_make_string_value (output_string_p);
MEM_FINALIZE_LOCAL_ARRAY (output_start_p); MEM_FINALIZE_LOCAL_ARRAY (output_start_p);
MEM_FINALIZE_LOCAL_ARRAY (input_start_p); ECMA_FINALIZE_UTF8_STRING (input_start_p, input_start_size);
ECMA_FINALIZE (to_string_val); ECMA_FINALIZE (to_string_val);
ECMA_FINALIZE (check_coercible_val); ECMA_FINALIZE (check_coercible_val);
+2 -9
View File
@@ -52,21 +52,14 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */
} }
else else
{ {
MEM_DEFINE_LOCAL_ARRAY (code_utf8_buffer_p, ECMA_STRING_TO_UTF8_STRING (code_p, code_utf8_buffer_p, code_utf8_buffer_size);
chars_num,
lit_utf8_byte_t);
lit_utf8_size_t buffer_size_req = ecma_string_to_utf8_string (code_p,
code_utf8_buffer_p,
chars_num);
JERRY_ASSERT (buffer_size_req == chars_num);
ret_value = ecma_op_eval_chars_buffer ((jerry_api_char_t *) code_utf8_buffer_p, ret_value = ecma_op_eval_chars_buffer ((jerry_api_char_t *) code_utf8_buffer_p,
chars_num, chars_num,
is_direct, is_direct,
is_called_from_strict_mode_code); is_called_from_strict_mode_code);
MEM_FINALIZE_LOCAL_ARRAY (code_utf8_buffer_p); ECMA_FINALIZE_UTF8_STRING (code_utf8_buffer_p, code_utf8_buffer_size);
} }
return ret_value; return ret_value;
+15 -21
View File
@@ -76,14 +76,10 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
{ {
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
lit_utf8_size_t flags_str_size = ecma_string_get_size (flags_str_p); ECMA_STRING_TO_UTF8_STRING (flags_str_p, flags_start_p, flags_start_size);
MEM_DEFINE_LOCAL_ARRAY (flags_start_p, flags_str_size, lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (flags_str_p, flags_start_p, flags_str_size); const lit_utf8_byte_t *flags_str_curr_p = flags_start_p;
JERRY_ASSERT (sz == flags_str_size); const lit_utf8_byte_t *flags_str_end_p = flags_start_p + flags_start_size;
lit_utf8_byte_t *flags_str_curr_p = flags_start_p;
const lit_utf8_byte_t *flags_str_end_p = flags_start_p + flags_str_size;
while (flags_str_curr_p < flags_str_end_p while (flags_str_curr_p < flags_str_end_p
&& ecma_is_value_empty (ret_value)) && ecma_is_value_empty (ret_value))
@@ -125,7 +121,7 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
} }
} }
MEM_FINALIZE_LOCAL_ARRAY (flags_start_p); ECMA_FINALIZE_UTF8_STRING (flags_start_p, flags_start_size);
return ret_value; return ret_value;
} /* re_parse_regexp_flags */ } /* re_parse_regexp_flags */
@@ -1274,27 +1270,23 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
return ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type")); return ecma_raise_type_error (ECMA_ERR_MSG ("Incompatible type"));
} }
ecma_string_t *input_string_p = ecma_get_string_from_value (input_string);
lit_utf8_size_t input_string_size = ecma_string_get_size (input_string_p);
MEM_DEFINE_LOCAL_ARRAY (input_buffer_p, input_string_size, lit_utf8_byte_t);
re_matcher_ctx_t re_ctx; re_matcher_ctx_t re_ctx;
lit_utf8_byte_t *input_curr_p = NULL; lit_utf8_byte_t *input_curr_p = NULL;
lit_utf8_size_t sz = ecma_string_to_utf8_string (input_string_p, input_buffer_p, input_string_size);
JERRY_ASSERT (sz == input_string_size);
if (input_string_size == 0u) ecma_string_t *input_string_p = ecma_get_string_from_value (input_string);
ECMA_STRING_TO_UTF8_STRING (input_string_p, input_buffer_p, input_buffer_size);
if (input_buffer_size == 0u)
{ {
input_curr_p = (lit_utf8_byte_t *) lit_get_magic_string_utf8 (LIT_MAGIC_STRING__EMPTY); input_curr_p = (lit_utf8_byte_t *) lit_get_magic_string_utf8 (LIT_MAGIC_STRING__EMPTY);
} }
else else
{ {
input_curr_p = input_buffer_p; input_curr_p = (lit_utf8_byte_t *) input_buffer_p;
} }
re_ctx.input_start_p = input_curr_p; re_ctx.input_start_p = input_curr_p;
const lit_utf8_byte_t *input_end_p = re_ctx.input_start_p + input_string_size; const lit_utf8_byte_t *input_end_p = re_ctx.input_start_p + input_buffer_size;
re_ctx.input_end_p = input_end_p; re_ctx.input_end_p = input_end_p;
/* 1. Read bytecode header and init regexp matcher context. */ /* 1. Read bytecode header and init regexp matcher context. */
@@ -1333,7 +1325,9 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
bool is_match = false; bool is_match = false;
re_ctx.num_of_iterations_p = num_of_iter_p; re_ctx.num_of_iterations_p = num_of_iter_p;
int32_t index = 0; int32_t index = 0;
ecma_length_t input_str_len = lit_utf8_string_length (input_buffer_p, input_string_size); ecma_length_t input_str_len;
input_str_len = lit_utf8_string_length (input_buffer_p, input_buffer_size);
if (input_buffer_p && (re_ctx.flags & RE_FLAG_GLOBAL)) if (input_buffer_p && (re_ctx.flags & RE_FLAG_GLOBAL))
{ {
@@ -1435,7 +1429,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
ecma_value_t result_array = ecma_op_create_array_object (0, 0, false); ecma_value_t result_array = ecma_op_create_array_object (0, 0, false);
ecma_object_t *result_array_obj_p = ecma_get_object_from_value (result_array); ecma_object_t *result_array_obj_p = ecma_get_object_from_value (result_array);
ecma_string_t *input_str_p = ecma_new_ecma_string_from_utf8 (input_buffer_p, input_string_size); ecma_string_t *input_str_p = ecma_new_ecma_string_from_utf8 (input_buffer_p, input_buffer_size);
re_set_result_array_properties (result_array_obj_p, input_str_p, re_ctx.num_of_captures / 2, index); re_set_result_array_properties (result_array_obj_p, input_str_p, re_ctx.num_of_captures / 2, index);
ecma_deref_ecma_string (input_str_p); ecma_deref_ecma_string (input_str_p);
@@ -1492,7 +1486,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
MEM_FINALIZE_LOCAL_ARRAY (num_of_iter_p); MEM_FINALIZE_LOCAL_ARRAY (num_of_iter_p);
MEM_FINALIZE_LOCAL_ARRAY (saved_p); MEM_FINALIZE_LOCAL_ARRAY (saved_p);
MEM_FINALIZE_LOCAL_ARRAY (input_buffer_p); ECMA_FINALIZE_UTF8_STRING (input_buffer_p, input_buffer_size);
return ret_value; return ret_value;
} /* ecma_regexp_exec_helper */ } /* ecma_regexp_exec_helper */
+5 -6
View File
@@ -1886,23 +1886,22 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p) /**< compiled
ecma_string_t *pattern_string_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, ecma_string_t *pattern_string_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
pattern_cp); pattern_cp);
ecma_length_t pattern_size = ecma_string_get_size (pattern_string_p); ecma_length_t pattern_size = 0;
MEM_DEFINE_LOCAL_ARRAY (buffer_p, pattern_size, lit_utf8_byte_t); ECMA_STRING_TO_UTF8_STRING (pattern_string_p, buffer_p, buffer_size);
lit_utf8_size_t sz = ecma_string_to_utf8_string (pattern_string_p, buffer_p, pattern_size); pattern_size = buffer_size;
JERRY_ASSERT (sz == pattern_size);
if (!jrt_write_to_buffer_by_offset (snapshot_buffer_p, if (!jrt_write_to_buffer_by_offset (snapshot_buffer_p,
snapshot_buffer_size, snapshot_buffer_size,
&snapshot_buffer_write_offset, &snapshot_buffer_write_offset,
buffer_p, buffer_p,
pattern_size)) buffer_size))
{ {
snapshot_error_occured = true; snapshot_error_occured = true;
} }
MEM_FINALIZE_LOCAL_ARRAY (buffer_p); ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size);
snapshot_buffer_write_offset = JERRY_ALIGNUP (snapshot_buffer_write_offset, MEM_ALIGNMENT); snapshot_buffer_write_offset = JERRY_ALIGNUP (snapshot_buffer_write_offset, MEM_ALIGNMENT);
+4 -8
View File
@@ -546,16 +546,12 @@ re_compile_bytecode (const re_compiled_code_t **out_bytecode_p, /**< [out] point
re_ctx.bytecode_ctx_p = &bc_ctx; re_ctx.bytecode_ctx_p = &bc_ctx;
lit_utf8_size_t pattern_str_size = ecma_string_get_size (pattern_str_p); ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start_p, pattern_start_size);
MEM_DEFINE_LOCAL_ARRAY (pattern_start_p, pattern_str_size, lit_utf8_byte_t);
lit_utf8_size_t sz = ecma_string_to_utf8_string (pattern_str_p, pattern_start_p, pattern_str_size);
JERRY_ASSERT (sz == pattern_str_size);
re_parser_ctx_t parser_ctx; re_parser_ctx_t parser_ctx;
parser_ctx.input_start_p = pattern_start_p; parser_ctx.input_start_p = pattern_start_p;
parser_ctx.input_curr_p = pattern_start_p; parser_ctx.input_curr_p = (lit_utf8_byte_t *) pattern_start_p;
parser_ctx.input_end_p = pattern_start_p + pattern_str_size; parser_ctx.input_end_p = pattern_start_p + pattern_start_size;
parser_ctx.num_of_groups = -1; parser_ctx.num_of_groups = -1;
re_ctx.parser_ctx_p = &parser_ctx; re_ctx.parser_ctx_p = &parser_ctx;
@@ -593,7 +589,7 @@ re_compile_bytecode (const re_compiled_code_t **out_bytecode_p, /**< [out] point
ECMA_FINALIZE (empty); ECMA_FINALIZE (empty);
MEM_FINALIZE_LOCAL_ARRAY (pattern_start_p); ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size);
size_t byte_code_size = (size_t) (bc_ctx.block_end_p - bc_ctx.block_start_p); size_t byte_code_size = (size_t) (bc_ctx.block_end_p - bc_ctx.block_start_p);
+1 -1
View File
@@ -259,7 +259,7 @@ re_count_num_of_groups (re_parser_ctx_t *parser_ctx_p) /**< RegExp parser contex
{ {
int char_class_in = 0; int char_class_in = 0;
parser_ctx_p->num_of_groups = 0; parser_ctx_p->num_of_groups = 0;
lit_utf8_byte_t *curr_p = parser_ctx_p->input_start_p; lit_utf8_byte_t *curr_p = (lit_utf8_byte_t *) parser_ctx_p->input_start_p;
while (curr_p < parser_ctx_p->input_end_p) while (curr_p < parser_ctx_p->input_end_p)
{ {
+2 -2
View File
@@ -92,9 +92,9 @@ typedef struct
*/ */
typedef struct typedef struct
{ {
lit_utf8_byte_t *input_start_p; /**< start of input pattern */ const lit_utf8_byte_t *input_start_p; /**< start of input pattern */
lit_utf8_byte_t *input_curr_p; /**< current position in input pattern */ lit_utf8_byte_t *input_curr_p; /**< current position in input pattern */
lit_utf8_byte_t *input_end_p; /**< end of input pattern */ const lit_utf8_byte_t *input_end_p; /**< end of input pattern */
int num_of_groups; /**< number of groups */ int num_of_groups; /**< number of groups */
uint32_t num_of_classes; /**< number of character classes */ uint32_t num_of_classes; /**< number of character classes */
} re_parser_ctx_t; } re_parser_ctx_t;