From b9c0a58e3ca7e3190487079ea0bb09612fa71b30 Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Wed, 11 Dec 2024 18:41:52 +0000 Subject: [PATCH] Improve ecma_string_get_chars related code Introduce lit_utf8_string_t and use it to reduce heap allocation and improve performance Mark ECMA_STRING_TO_UTF8_STRING/ECMA_STRING_TO_UTF8_STRING_AND_LENGTH do not use heap allocation Now with lit_utf8_string_t, ECMA_STRING_TO_UTF8_STRING and ECMA_STRING_TO_UTF8_STRING_AND_LENGTH are simplified. The parameters passed to ECMA_STRING_TO_UTF8_STRING and ECMA_STRING_TO_UTF8_STRING_AND_LENGTH are reduced and easier to call The function prototype of ecma_string_get_chars are simplified as: lit_utf8_size_t ecma_string_get_chars (const ecma_string_t *string_p, lit_utf8_string_t *string_out_p, lit_utf8_byte_t *uint32_buff_p, uint8_t *flags_p); The macro prototype of ECMA_STRING_TO_UTF8_STRING and ECMA_STRING_TO_UTF8_STRING_AND_LENGTH are simplified as: #define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \ utf8_str) /**< [out] lit_utf8_string_t to get */ \ #define ECMA_STRING_TO_UTF8_STRING_AND_LENGTH(ecma_str_ptr, /**< ecma string pointer */ \ utf8_str) /**< [out] lit_utf8_string_t to get */ \ Now the parameters are reduced. Aslo the calling to ecma_string_get_chars are largely reduced, in most case, ECMA_STRING_TO_UTF8_STRING/ECMA_STRING_TO_UTF8_STRING_AND_LENGTH is enough. Because the heap allocation are reduced, the performance should be improved. And in most case, we only use ECMA_STRING_TO_UTF8_STRING, only when the length is needed, the ECMA_STRING_TO_UTF8_STRING_AND_LENGTH is called, ECMA_STRING_TO_UTF8_STRING_AND_LENGTH needs to calculate the length that's very slow. ECMA_FINALIZE_UTF8_STRING is removed, if we have heap allocation situation, use ecma_string_get_chars instead and free it manually JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com --- jerry-core/api/jerry-snapshot.c | 26 ++---- jerry-core/api/jerryscript.c | 26 ++---- jerry-core/debugger/debugger.c | 20 ++-- jerry-core/ecma/base/ecma-helpers-string.c | 92 +++++++------------ jerry-core/ecma/base/ecma-helpers.h | 48 ++++++---- .../ecma/builtin-objects/ecma-builtin-date.c | 8 +- .../ecma-builtin-function-prototype.c | 5 +- .../builtin-objects/ecma-builtin-global.c | 7 +- .../builtin-objects/ecma-builtin-helpers.c | 47 ++++------ .../builtin-objects/ecma-builtin-intrinsic.c | 14 ++- .../ecma/builtin-objects/ecma-builtin-json.c | 15 ++- .../ecma-builtin-regexp-prototype.c | 8 +- .../ecma-builtin-string-prototype.c | 72 +++++---------- jerry-core/ecma/operations/ecma-bigint.c | 5 +- .../ecma/operations/ecma-regexp-object.c | 61 ++++-------- jerry-core/lit/lit-char-helpers.c | 8 +- jerry-core/lit/lit-globals.h | 9 ++ jerry-core/parser/js/common.c | 5 +- jerry-core/parser/js/js-parser-internal.h | 6 +- jerry-core/parser/js/js-parser.c | 69 +++++++------- jerry-core/parser/js/js-scanner.c | 20 ++-- jerry-core/parser/regexp/re-compiler.c | 10 +- 22 files changed, 230 insertions(+), 351 deletions(-) diff --git a/jerry-core/api/jerry-snapshot.c b/jerry-core/api/jerry-snapshot.c index 33760b299f..8e4016fb75 100644 --- a/jerry-core/api/jerry-snapshot.c +++ b/jerry-core/api/jerry-snapshot.c @@ -191,22 +191,19 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co lit_utf8_size_t pattern_size = 0; - ECMA_STRING_TO_UTF8_STRING (pattern_string_p, buffer_p, buffer_size); + ECMA_STRING_TO_UTF8_STRING (pattern_string_p, buffer); - pattern_size = buffer_size; + pattern_size = buffer.size; if (!snapshot_write_to_buffer_by_offset (snapshot_buffer_p, snapshot_buffer_size, &globals_p->snapshot_buffer_write_offset, - buffer_p, - buffer_size)) + buffer.ptr, + buffer.size)) { globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, error_buffer_too_small_p); - /* cannot return inside ECMA_FINALIZE_UTF8_STRING */ } - ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size); - if (!ecma_is_value_empty (globals_p->snapshot_error)) { return 0; @@ -1484,15 +1481,13 @@ jerry_append_ecma_string_to_buffer (uint8_t *buffer_p, /**< buffer */ uint8_t *buffer_end_p, /**< the end of the buffer */ ecma_string_t *string_p) /**< ecma-string */ { - ECMA_STRING_TO_UTF8_STRING (string_p, str_buffer_p, str_buffer_size); + ECMA_STRING_TO_UTF8_STRING (string_p, str_buffer); /* Append the string to the buffer. */ uint8_t *new_buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, - (const jerry_char_t *) str_buffer_p, - (jerry_size_t) str_buffer_size); - - ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size); + (const jerry_char_t *) str_buffer.ptr, + (jerry_size_t) str_buffer.size); return new_buffer_p; } /* jerry_append_ecma_string_to_buffer */ @@ -1623,10 +1618,10 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho for (lit_utf8_size_t i = 0; i < literal_count; i++) { lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (" \"")); - ECMA_STRING_TO_UTF8_STRING (literal_array[i], str_buffer_p, str_buffer_size); - for (lit_utf8_size_t j = 0; j < str_buffer_size; j++) + ECMA_STRING_TO_UTF8_STRING (literal_array[i], str_buffer); + for (lit_utf8_size_t j = 0; j < str_buffer.size; j++) { - uint8_t byte = str_buffer_p[j]; + uint8_t byte = str_buffer.ptr[j]; if (byte < 32 || byte > 127) { lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("\\x")); @@ -1645,7 +1640,6 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho } } - ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size); lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("\"")); if (i < literal_count - 1) diff --git a/jerry-core/api/jerryscript.c b/jerry-core/api/jerryscript.c index d8174b92c0..56663e0eaa 100644 --- a/jerry-core/api/jerryscript.c +++ b/jerry-core/api/jerryscript.c @@ -384,14 +384,11 @@ jerry_parse_common (void *source_p, /**< script source */ if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) && options_p != NULL && (options_p->options & JERRY_PARSE_HAS_SOURCE_NAME) && ecma_is_value_string (options_p->source_name)) { - ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (options_p->source_name), - source_name_start_p, - source_name_size); + ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (options_p->source_name), source_name_start); jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME, JERRY_DEBUGGER_NO_SUBTYPE, - source_name_start_p, - source_name_size); - ECMA_FINALIZE_UTF8_STRING (source_name_start_p, source_name_size); + source_name_start.ptr, + source_name_start.size); } #endif /* JERRY_DEBUGGER */ @@ -891,12 +888,12 @@ jerry_native_module (jerry_native_module_evaluate_cb_t callback, /**< evaluation bool valid_identifier = false; - ECMA_STRING_TO_UTF8_STRING (name_str_p, name_start_p, name_size); + ECMA_STRING_TO_UTF8_STRING (name_str_p, name_start); - if (name_size > 0) + if (name_start.size > 0) { - const lit_utf8_byte_t *name_p = name_start_p; - const lit_utf8_byte_t *name_end_p = name_start_p + name_size; + const lit_utf8_byte_t *name_p = name_start.ptr; + const lit_utf8_byte_t *name_end_p = name_start.ptr + name_start.size; lit_code_point_t code_point; lit_utf8_size_t size = lit_read_code_point_from_cesu8 (name_p, name_end_p, &code_point); @@ -922,8 +919,6 @@ jerry_native_module (jerry_native_module_evaluate_cb_t callback, /**< evaluation } } - ECMA_FINALIZE_UTF8_STRING (name_start_p, name_size); - if (!valid_identifier) { ecma_deref_object (scope_p); @@ -3001,10 +2996,10 @@ jerry_string_iterate (const jerry_value_t value, } ecma_string_t *str_p = ecma_get_string_from_value (value); - ECMA_STRING_TO_UTF8_STRING (str_p, buffer_p, buffer_size); + ECMA_STRING_TO_UTF8_STRING (str_p, buffer); - const lit_utf8_byte_t *current_p = buffer_p; - const lit_utf8_byte_t *end_p = buffer_p + buffer_size; + const lit_utf8_byte_t *current_p = buffer.ptr; + const lit_utf8_byte_t *end_p = buffer.ptr + buffer.size; switch (encoding) { @@ -3048,7 +3043,6 @@ jerry_string_iterate (const jerry_value_t value, break; } } - ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size); } /* jerry_string_iterate */ /** diff --git a/jerry-core/debugger/debugger.c b/jerry-core/debugger/debugger.c index 2d77f88328..e35fc2fbbf 100644 --- a/jerry-core/debugger/debugger.c +++ b/jerry-core/debugger/debugger.c @@ -335,7 +335,7 @@ jerry_debugger_copy_variables_to_string_message (uint8_t variable_type, /**< typ const size_t max_byte_count = JERRY_DEBUGGER_SEND_MAX (uint8_t); const size_t max_message_size = JERRY_DEBUGGER_SEND_SIZE (max_byte_count, uint8_t); - ECMA_STRING_TO_UTF8_STRING (value_str, str_buff, str_buff_size); + ECMA_STRING_TO_UTF8_STRING (value_str, str_buff); size_t str_size = 0; size_t str_limit = 255; @@ -373,7 +373,7 @@ jerry_debugger_copy_variables_to_string_message (uint8_t variable_type, /**< typ } else { - str_size = (str_buff_size > str_limit) ? str_limit : str_buff_size; + str_size = (str_buff.size > str_limit) ? str_limit : str_buff.size; } message_string_p->string[*buffer_pos] = (uint8_t) str_size; @@ -384,7 +384,7 @@ jerry_debugger_copy_variables_to_string_message (uint8_t variable_type, /**< typ if (result) { size_t free_bytes = max_byte_count - *buffer_pos; - const uint8_t *string_p = str_buff; + const uint8_t *string_p = str_buff.ptr; while (str_size > free_bytes) { @@ -409,8 +409,6 @@ jerry_debugger_copy_variables_to_string_message (uint8_t variable_type, /**< typ } } - ECMA_FINALIZE_UTF8_STRING (str_buff, str_buff_size); - return result; } /* jerry_debugger_copy_variables_to_string_message */ @@ -614,9 +612,8 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s ecma_string_t *string_p = ecma_get_string_from_value (message); - ECMA_STRING_TO_UTF8_STRING (string_p, buffer_p, buffer_size); - jerry_debugger_send_string (JERRY_DEBUGGER_EVAL_RESULT, type, buffer_p, buffer_size); - ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size); + ECMA_STRING_TO_UTF8_STRING (string_p, buffer); + jerry_debugger_send_string (JERRY_DEBUGGER_EVAL_RESULT, type, buffer.ptr, buffer.size); ecma_free_value (message); @@ -1525,12 +1522,9 @@ jerry_debugger_send_exception_string (ecma_value_t exception_value) string_p = ecma_op_to_string (exception_value); } - ECMA_STRING_TO_UTF8_STRING (string_p, string_data_p, string_size); - - bool result = - jerry_debugger_send_string (JERRY_DEBUGGER_EXCEPTION_STR, JERRY_DEBUGGER_NO_SUBTYPE, string_data_p, string_size); + ECMA_STRING_TO_UTF8_STRING (string_p, str); - ECMA_FINALIZE_UTF8_STRING (string_data_p, string_size); + bool result = jerry_debugger_send_string (JERRY_DEBUGGER_EXCEPTION_STR, JERRY_DEBUGGER_NO_SUBTYPE, str.ptr, str.size); ecma_deref_ecma_string (string_p); return result; diff --git a/jerry-core/ecma/base/ecma-helpers-string.c b/jerry-core/ecma/base/ecma-helpers-string.c index 2f88abab7a..9aa9a49784 100644 --- a/jerry-core/ecma/base/ecma-helpers-string.c +++ b/jerry-core/ecma/base/ecma-helpers-string.c @@ -723,29 +723,22 @@ ecma_append_chars_to_string (ecma_string_t *string1_p, /**< base ecma-string */ return ecma_new_ecma_string_from_utf8 (cesu8_string2_p, cesu8_string2_size); } - lit_utf8_size_t cesu8_string1_size; - lit_utf8_size_t cesu8_string1_length; - uint8_t flags = ECMA_STRING_FLAG_IS_ASCII; - lit_utf8_byte_t uint32_to_string_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; - - const lit_utf8_byte_t *cesu8_string1_p = - ecma_string_get_chars (string1_p, &cesu8_string1_size, &cesu8_string1_length, uint32_to_string_buffer, &flags); + ECMA_STRING_TO_UTF8_STRING_AND_LENGTH (string1_p, cesu8_string1); - JERRY_ASSERT (!(flags & ECMA_STRING_FLAG_MUST_BE_FREED)); JERRY_ASSERT (cesu8_string1_length > 0); - JERRY_ASSERT (cesu8_string1_length <= cesu8_string1_size); + JERRY_ASSERT (cesu8_string1_length <= cesu8_string1.size); - lit_utf8_size_t new_size = cesu8_string1_size + cesu8_string2_size; + lit_utf8_size_t new_size = cesu8_string1.size + cesu8_string2_size; /* Poor man's carry flag check: it is impossible to allocate this large string. */ - if (new_size < (cesu8_string1_size | cesu8_string2_size)) + if (new_size < (cesu8_string1.size | cesu8_string2_size)) { jerry_fatal (JERRY_FATAL_OUT_OF_MEMORY); } lit_magic_string_id_t magic_string_id; magic_string_id = - lit_is_utf8_string_pair_magic (cesu8_string1_p, cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + lit_is_utf8_string_pair_magic (cesu8_string1.ptr, cesu8_string1.size, cesu8_string2_p, cesu8_string2_size); if (magic_string_id != LIT_MAGIC_STRING__COUNT) { @@ -753,13 +746,13 @@ ecma_append_chars_to_string (ecma_string_t *string1_p, /**< base ecma-string */ return ecma_get_magic_string (magic_string_id); } - if ((flags & ECMA_STRING_FLAG_IS_UINT32) && new_size <= ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32) + if ((cesu8_string1_flags & ECMA_STRING_FLAG_IS_UINT32) && new_size < ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32) { - memcpy (uint32_to_string_buffer + cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + memcpy (cesu8_string1_uint32_buffer + cesu8_string1.size, cesu8_string2_p, cesu8_string2_size); uint32_t array_index; - if (ecma_string_to_array_index (uint32_to_string_buffer, new_size, &array_index)) + if (ecma_string_to_array_index (cesu8_string1_uint32_buffer, new_size, &array_index)) { ecma_deref_ecma_string (string1_p); return ecma_new_ecma_string_from_uint32 (array_index); @@ -770,7 +763,7 @@ ecma_append_chars_to_string (ecma_string_t *string1_p, /**< base ecma-string */ { lit_magic_string_ex_id_t magic_string_ex_id; magic_string_ex_id = - lit_is_ex_utf8_string_pair_magic (cesu8_string1_p, cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + lit_is_ex_utf8_string_pair_magic (cesu8_string1.ptr, cesu8_string1.size, cesu8_string2_p, cesu8_string2_size); if (magic_string_ex_id < lit_get_magic_string_ex_count ()) { @@ -785,9 +778,9 @@ ecma_append_chars_to_string (ecma_string_t *string1_p, /**< base ecma-string */ lit_string_hash_t hash_start; - if (JERRY_UNLIKELY (flags & ECMA_STRING_FLAG_REHASH_NEEDED)) + if (JERRY_UNLIKELY (cesu8_string1_flags & ECMA_STRING_FLAG_REHASH_NEEDED)) { - hash_start = lit_utf8_string_calc_hash (cesu8_string1_p, cesu8_string1_size); + hash_start = lit_utf8_string_calc_hash (cesu8_string1.ptr, cesu8_string1.size); } else { @@ -797,8 +790,8 @@ ecma_append_chars_to_string (ecma_string_t *string1_p, /**< base ecma-string */ string_desc_p->u.hash = lit_utf8_string_hash_combine (hash_start, cesu8_string2_p, cesu8_string2_size); - memcpy (data_p, cesu8_string1_p, cesu8_string1_size); - memcpy (data_p + cesu8_string1_size, cesu8_string2_p, cesu8_string2_size); + memcpy (data_p, cesu8_string1.ptr, cesu8_string1.size); + memcpy (data_p + cesu8_string1.size, cesu8_string2_p, cesu8_string2_size); ecma_deref_ecma_string (string1_p); return (ecma_string_t *) string_desc_p; @@ -829,20 +822,11 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */ return string1_p; } - lit_utf8_size_t cesu8_string2_size; - lit_utf8_size_t cesu8_string2_length; - lit_utf8_byte_t uint32_to_string_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; - uint8_t flags = ECMA_STRING_FLAG_IS_ASCII; - - const lit_utf8_byte_t *cesu8_string2_p = - ecma_string_get_chars (string2_p, &cesu8_string2_size, &cesu8_string2_length, uint32_to_string_buffer, &flags); - - JERRY_ASSERT (cesu8_string2_p != NULL); + ECMA_STRING_TO_UTF8_STRING_AND_LENGTH (string2_p, cesu8_string2); + JERRY_ASSERT (cesu8_string2.ptr != NULL); ecma_string_t *result_p = - ecma_append_chars_to_string (string1_p, cesu8_string2_p, cesu8_string2_size, cesu8_string2_length); - - JERRY_ASSERT (!(flags & ECMA_STRING_FLAG_MUST_BE_FREED)); + ecma_append_chars_to_string (string1_p, cesu8_string2.ptr, cesu8_string2.size, cesu8_string2_length); return result_p; } /* ecma_concat_ecma_strings */ @@ -1224,13 +1208,11 @@ ecma_string_get_uint32_size (const uint32_t uint32_number) /**< number in the st * - The ASCII check only happens if the flags parameter gets * 'ECMA_STRING_FLAG_IS_ASCII' as an input. * - * @return start of cesu8 characters + * @return the length of the ecma string */ -const lit_utf8_byte_t * +lit_utf8_size_t ecma_string_get_chars (const ecma_string_t *string_p, /**< ecma-string */ - lit_utf8_size_t *size_p, /**< [out] size of the ecma string */ - lit_utf8_size_t *length_p, /**< [out] optional argument. If the pointer is not NULL the pointed - * memory area is filled with the length of the ecma string */ + lit_utf8_string_t *string_out_p, /**< [out] size of the ecma string */ lit_utf8_byte_t *uint32_buff_p, /**< [out] optional argument. If the pointer is not NULL the * pointed memory area is filled with the string converted * uint32 string descriptor */ @@ -1366,19 +1348,15 @@ ecma_string_get_chars (const ecma_string_t *string_p, /**< ecma-string */ } } } - - *size_p = size; - if (length_p != NULL) - { - *length_p = length; - } + string_out_p->ptr = result_p; + string_out_p->size = size; if ((*flags_p & ECMA_STRING_FLAG_IS_ASCII) && length != size) { *flags_p = (uint8_t) (*flags_p & (uint8_t) ~ECMA_STRING_FLAG_IS_ASCII); } - return result_p; + return length; } /* ecma_string_get_chars */ /** @@ -2200,9 +2178,10 @@ ecma_string_substr (const ecma_string_t *string_p, /**< pointer to an ecma strin ecma_string_t *ecma_string_p = NULL; end_pos -= start_pos; - ECMA_STRING_TO_UTF8_STRING (string_p, start_p, buffer_size); + ECMA_STRING_TO_UTF8_STRING (string_p, string_start); + const lit_utf8_byte_t *start_p = string_start.ptr; - if (string_length == buffer_size) + if (string_length == string_start.size) { ecma_string_p = ecma_new_ecma_string_from_utf8 (start_p + start_pos, (lit_utf8_size_t) end_pos); } @@ -2222,8 +2201,6 @@ ecma_string_substr (const ecma_string_t *string_p, /**< pointer to an ecma strin ecma_string_p = ecma_new_ecma_string_from_utf8 (start_p, (lit_utf8_size_t) (end_p - start_p)); } - ECMA_FINALIZE_UTF8_STRING (start_p, buffer_size); - return ecma_string_p; } /* ecma_string_substr */ @@ -2318,12 +2295,11 @@ ecma_string_trim (const ecma_string_t *string_p) /**< pointer to an ecma string { ecma_string_t *ret_string_p; - lit_utf8_size_t utf8_str_size; - uint8_t flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *utf8_str_p = ecma_string_get_chars (string_p, &utf8_str_size, NULL, NULL, &flags); - - if (utf8_str_size > 0) + ECMA_STRING_TO_UTF8_STRING (string_p, utf8_str); + if (utf8_str.size > 0) { + const lit_utf8_byte_t *utf8_str_p = utf8_str.ptr; + lit_utf8_size_t utf8_str_size = utf8_str.size; ecma_string_trim_helper (&utf8_str_p, &utf8_str_size); ret_string_p = ecma_new_ecma_string_from_utf8 (utf8_str_p, utf8_str_size); } @@ -2332,11 +2308,6 @@ 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); } - if (flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) utf8_str_p, utf8_str_size); - } - return ret_string_p; } /* ecma_string_trim */ @@ -2410,8 +2381,8 @@ ecma_string_pad (ecma_value_t original_string_p, /**< Input ecma string */ uint32_t remaining = fill_len - (prepend_count * filler_length); - ECMA_STRING_TO_UTF8_STRING (filler_p, start_p, utf8_str_size); - const lit_utf8_byte_t *temp_start_p = start_p; + ECMA_STRING_TO_UTF8_STRING (filler_p, start); + const lit_utf8_byte_t *temp_start_p = start.ptr; while (remaining > 0) { ecma_char_t ch; @@ -2420,7 +2391,6 @@ ecma_string_pad (ecma_value_t original_string_p, /**< Input ecma string */ temp_start_p += read_size; remaining--; } - ECMA_FINALIZE_UTF8_STRING (start_p, utf8_str_size); ecma_deref_ecma_string (filler_p); /* 11 - 12 */ diff --git a/jerry-core/ecma/base/ecma-helpers.h b/jerry-core/ecma/base/ecma-helpers.h index 0e98ea243b..99eac6c83d 100644 --- a/jerry-core/ecma/base/ecma-helpers.h +++ b/jerry-core/ecma/base/ecma-helpers.h @@ -104,24 +104,35 @@ typedef enum /** * Convert ecma-string's contents to a cesu-8 string and put it into a buffer. + * No allocation needed by providing a uint32 string buffer. + * The flags name is `utf8_str##_flags` + * The uint32 string buffer name is `utf8_str##_uint32_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; \ - uint8_t utf8_ptr##flags = ECMA_STRING_FLAG_EMPTY; \ - const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, &utf8_str_size, NULL, NULL, &utf8_ptr##flags); +#define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \ + utf8_str) /**< [out] lit_utf8_string_t to get */ \ + lit_utf8_string_t utf8_str; \ + uint8_t utf8_str##_flags = ECMA_STRING_FLAG_EMPTY; \ + lit_utf8_byte_t utf8_str##_uint32_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; \ + (void) ecma_string_get_chars (ecma_str_ptr, &utf8_str, utf8_str##_uint32_buffer, &utf8_str##_flags); \ + JERRY_ASSERT (!(utf8_str##_flags & ECMA_STRING_FLAG_MUST_BE_FREED)); /** - * Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING' + * Convert ecma-string's contents to a cesu-8 string and put it into a buffer. + * No allocation needed by providing a uint32 string buffer + * The flags name is `utf8_str##_flags` + * The uint32 string buffer name is `utf8_str##_uint32_buffer` + * The string length name is `utf8_str##_length` + * */ -#define ECMA_FINALIZE_UTF8_STRING(utf8_ptr, /**< pointer to character buffer */ \ - utf8_str_size) /**< buffer size */ \ - if (utf8_ptr##flags & ECMA_STRING_FLAG_MUST_BE_FREED) \ - { \ - JERRY_ASSERT (utf8_ptr != NULL); \ - jmem_heap_free_block ((void *) utf8_ptr, utf8_str_size); \ - } +#define ECMA_STRING_TO_UTF8_STRING_AND_LENGTH(ecma_str_ptr, /**< ecma string pointer */ \ + utf8_str) /**< [out] lit_utf8_string_t to get */ \ + lit_utf8_string_t utf8_str; \ + uint8_t utf8_str##_flags = ECMA_STRING_FLAG_IS_ASCII; \ + lit_utf8_byte_t utf8_str##_uint32_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; \ + lit_utf8_size_t utf8_str##_length = \ + ecma_string_get_chars (ecma_str_ptr, &utf8_str, utf8_str##_uint32_buffer, &utf8_str##_flags); \ + JERRY_ASSERT (!(utf8_str##_flags & ECMA_STRING_FLAG_MUST_BE_FREED)); #ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY @@ -314,11 +325,10 @@ lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT ecma_string_copy_to_buffer (const jerry_encoding_t encoding); void ecma_string_to_cesu8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size); -const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p, - lit_utf8_size_t *size_p, - lit_utf8_size_t *length_p, - lit_utf8_byte_t *uint32_buff_p, - uint8_t *flags_p); +lit_utf8_size_t ecma_string_get_chars (const ecma_string_t *string_p, + lit_utf8_string_t *string_out_p, + lit_utf8_byte_t *uint32_buff_p, + uint8_t *flags_p); bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id); bool ecma_string_is_empty (const ecma_string_t *string_p); bool ecma_string_is_length (const ecma_string_t *string_p); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-date.c b/jerry-core/ecma/builtin-objects/ecma-builtin-date.c index 201634d93a..4d84a969ba 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date.c @@ -638,9 +638,9 @@ ecma_builtin_date_parse_toString_formats (const lit_utf8_byte_t *date_str_curr_p static ecma_number_t ecma_builtin_date_parse (ecma_string_t *string_p) /**< string */ { - ECMA_STRING_TO_UTF8_STRING (string_p, str_p, str_size); - const lit_utf8_byte_t *date_str_curr_p = str_p; - const lit_utf8_byte_t *date_str_end_p = str_p + str_size; + ECMA_STRING_TO_UTF8_STRING (string_p, str); + const lit_utf8_byte_t *date_str_curr_p = str.ptr; + const lit_utf8_byte_t *date_str_end_p = str.ptr + str.size; /* try to parse date string as ISO string - ECMA-262 v5, 15.9.1.15 */ ecma_number_t tv = ecma_builtin_date_parse_basic (date_str_curr_p, date_str_end_p); @@ -651,8 +651,6 @@ ecma_builtin_date_parse (ecma_string_t *string_p) /**< string */ tv = ecma_builtin_date_parse_toString_formats (date_str_curr_p, date_str_end_p); } - ECMA_FINALIZE_UTF8_STRING (str_p, str_size); - return tv; } /* ecma_builtin_date_parse */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c index e7f0b1f9a4..19fb95527c 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c @@ -136,9 +136,8 @@ ecma_builtin_function_prototype_object_to_string (ecma_object_t *func_obj_p) /** ecma_string_t *result_string_p; - ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (source_code), source_p, source_size); - result_string_p = ecma_new_ecma_string_from_utf8 (source_p + range_start, range_size); - ECMA_FINALIZE_UTF8_STRING (source_p, source_size); + ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (source_code), source); + result_string_p = ecma_new_ecma_string_from_utf8 (source.ptr + range_start, range_size); return ecma_make_string_value (result_string_p); } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-global.c b/jerry-core/ecma/builtin-objects/ecma-builtin-global.c index d9ccc8ff68..428324e22d 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-global.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-global.c @@ -626,19 +626,18 @@ ecma_builtin_global_dispatch_routine (uint8_t builtin_routine_id, /**< built-in if (builtin_routine_id <= ECMA_GLOBAL_PARSE_FLOAT) { - ECMA_STRING_TO_UTF8_STRING (str_p, string_buff, string_buff_size); + ECMA_STRING_TO_UTF8_STRING (str_p, string_buff); if (builtin_routine_id == ECMA_GLOBAL_PARSE_INT) { - ret_value = ecma_number_parse_int (string_buff, string_buff_size, arguments_list_p[1]); + ret_value = ecma_number_parse_int (string_buff.ptr, string_buff.size, arguments_list_p[1]); } else { JERRY_ASSERT (builtin_routine_id == ECMA_GLOBAL_PARSE_FLOAT); - ret_value = ecma_number_parse_float (string_buff, string_buff_size); + ret_value = ecma_number_parse_float (string_buff.ptr, string_buff.size); } - ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size); ecma_deref_ecma_string (str_p); return ret_value; } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c index e298fad4ac..4d7692f6e3 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c @@ -479,14 +479,14 @@ ecma_builtin_helper_string_find_last_index (ecma_string_t *original_str_p, /**< uint32_t original_length = ecma_string_get_length (original_str_p); - ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8_p, search_str_size); - ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8_p, original_str_size); + ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8); + ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8); uint32_t ret_value = UINT32_MAX; - if (original_str_size >= search_str_size) + if (original_str_utf8.size >= search_str_utf8.size) { - const lit_utf8_byte_t *end_p = original_str_utf8_p + original_str_size; + const lit_utf8_byte_t *end_p = original_str_utf8.ptr + original_str_utf8.size; const lit_utf8_byte_t *current_p = end_p; for (ecma_number_t i = original_length; i > position; i--) @@ -494,7 +494,7 @@ ecma_builtin_helper_string_find_last_index (ecma_string_t *original_str_p, /**< lit_utf8_decr (¤t_p); } - while (current_p + search_str_size > end_p) + while (current_p + search_str_utf8.size > end_p) { lit_utf8_decr (¤t_p); position--; @@ -502,7 +502,7 @@ ecma_builtin_helper_string_find_last_index (ecma_string_t *original_str_p, /**< while (true) { - if (memcmp (current_p, search_str_utf8_p, search_str_size) == 0) + if (memcmp (current_p, search_str_utf8.ptr, search_str_utf8.size) == 0) { ret_value = position; break; @@ -517,8 +517,6 @@ ecma_builtin_helper_string_find_last_index (ecma_string_t *original_str_p, /**< position--; } } - ECMA_FINALIZE_UTF8_STRING (original_str_utf8_p, original_str_size); - ECMA_FINALIZE_UTF8_STRING (search_str_utf8_p, search_str_size); return ret_value; } /* ecma_builtin_helper_string_find_last_index */ @@ -717,21 +715,21 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index return start_pos; } - ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8_p, search_str_size); - ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8_p, original_str_size); + ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8); + ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8); - const lit_utf8_byte_t *str_current_p = original_str_utf8_p; + const lit_utf8_byte_t *str_current_p = original_str_utf8.ptr; - for (ecma_number_t i = 0; i < start_pos; i++) + for (uint32_t i = 0; i < start_pos; i++) { lit_utf8_incr (&str_current_p); } - const lit_utf8_byte_t *original_end_p = original_str_utf8_p + original_str_size; + const lit_utf8_byte_t *original_end_p = original_str_utf8.ptr + original_str_utf8.size; - while (!((size_t) (original_end_p - str_current_p) < search_str_size)) + while (!((size_t) (original_end_p - str_current_p) < search_str_utf8.size)) { - if (memcmp (str_current_p, search_str_utf8_p, search_str_size) == 0) + if (memcmp (str_current_p, search_str_utf8.ptr, search_str_utf8.size) == 0) { match_found = start_pos; break; @@ -741,9 +739,6 @@ ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index start_pos++; } - ECMA_FINALIZE_UTF8_STRING (original_str_utf8_p, original_str_size); - ECMA_FINALIZE_UTF8_STRING (search_str_utf8_p, search_str_size); - return match_found; } /* ecma_builtin_helper_string_find_index */ @@ -865,14 +860,11 @@ ecma_builtin_replace_substitute (ecma_replace_context_t *ctx_p) /**< replace con JERRY_ASSERT (ctx_p->matched_p == NULL || (ctx_p->matched_p >= ctx_p->string_p && ctx_p->matched_p <= ctx_p->string_p + ctx_p->string_size)); - lit_utf8_size_t replace_size; - uint8_t replace_flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *replace_buf_p = - ecma_string_get_chars (ctx_p->replace_str_p, &replace_size, NULL, NULL, &replace_flags); + ECMA_STRING_TO_UTF8_STRING (ctx_p->replace_str_p, replace); - const lit_utf8_byte_t *const replace_end_p = replace_buf_p + replace_size; - const lit_utf8_byte_t *curr_p = replace_buf_p; - const lit_utf8_byte_t *last_inserted_end_p = replace_buf_p; + const lit_utf8_byte_t *const replace_end_p = replace.ptr + replace.size; + const lit_utf8_byte_t *curr_p = replace.ptr; + const lit_utf8_byte_t *last_inserted_end_p = replace.ptr; while (curr_p < replace_end_p) { @@ -1013,11 +1005,6 @@ ecma_builtin_replace_substitute (ecma_replace_context_t *ctx_p) /**< replace con ecma_stringbuilder_append_raw (&(ctx_p->builder), last_inserted_end_p, (lit_utf8_size_t) (replace_end_p - last_inserted_end_p)); - - if (replace_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) replace_buf_p, replace_size); - } } /* ecma_builtin_replace_substitute */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c b/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c index 66519dcdcd..9fc229b9b6 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c @@ -241,11 +241,11 @@ ecma_builtin_intrinsic_dispatch_routine (uint8_t builtin_routine_id, /**< built- return ECMA_VALUE_ERROR; } - ECMA_STRING_TO_UTF8_STRING (to_str_p, start_p, input_start_size); + ECMA_STRING_TO_UTF8_STRING (to_str_p, start); lit_utf8_size_t size; - const lit_utf8_byte_t *input_start_p = start_p; - const lit_utf8_byte_t *input_str_end_p = start_p + input_start_size; + const lit_utf8_byte_t *input_start_p = start.ptr; + const lit_utf8_byte_t *input_str_end_p = start.ptr + start.size; ecma_string_t *ret_str_p; if (builtin_routine_id == ECMA_INTRINSIC_STRING_TRIM_START) @@ -261,7 +261,6 @@ ecma_builtin_intrinsic_dispatch_routine (uint8_t builtin_routine_id, /**< built- ret_str_p = ecma_new_ecma_string_from_utf8 (input_start_p, size); } - ECMA_FINALIZE_UTF8_STRING (start_p, input_start_size); ecma_value_t result = ecma_make_string_value (ret_str_p); ecma_deref_ecma_string (to_str_p); return result; @@ -279,19 +278,18 @@ ecma_builtin_intrinsic_dispatch_routine (uint8_t builtin_routine_id, /**< built- } ecma_value_t result; - ECMA_STRING_TO_UTF8_STRING (str_p, string_buff, string_buff_size); + ECMA_STRING_TO_UTF8_STRING (str_p, string_buff); if (builtin_routine_id == ECMA_INTRINSIC_PARSE_INT) { - result = ecma_number_parse_int (string_buff, string_buff_size, arguments_list_p[1]); + result = ecma_number_parse_int (string_buff.ptr, string_buff.size, arguments_list_p[1]); } else { JERRY_ASSERT (builtin_routine_id == ECMA_INTRINSIC_PARSE_FLOAT); - result = ecma_number_parse_float (string_buff, string_buff_size); + result = ecma_number_parse_float (string_buff.ptr, string_buff.size); } - ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size); ecma_deref_ecma_string (str_p); return result; } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c index 11a6871b60..84e398774d 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c @@ -844,9 +844,8 @@ ecma_builtin_json_parse (ecma_value_t arg1, /**< string argument */ return ECMA_VALUE_ERROR; } - ECMA_STRING_TO_UTF8_STRING (text_string_p, str_start_p, string_size); - ecma_value_t result = ecma_builtin_json_parse_buffer (str_start_p, string_size); - ECMA_FINALIZE_UTF8_STRING (str_start_p, string_size); + ECMA_STRING_TO_UTF8_STRING (text_string_p, str_start); + ecma_value_t result = ecma_builtin_json_parse_buffer (str_start.ptr, str_start.size); ecma_deref_ecma_string (text_string_p); if (!ECMA_IS_VALUE_ERROR (result) && ecma_op_is_callable (arg2)) @@ -878,10 +877,10 @@ static void ecma_builtin_json_quote (ecma_stringbuilder_t *builder_p, /**< builder for the result */ ecma_string_t *string_p) /**< string that should be quoted */ { - ECMA_STRING_TO_UTF8_STRING (string_p, string_buff, string_buff_size); - const lit_utf8_byte_t *str_p = string_buff; - const lit_utf8_byte_t *regular_str_start_p = string_buff; - const lit_utf8_byte_t *str_end_p = str_p + string_buff_size; + ECMA_STRING_TO_UTF8_STRING (string_p, string_buff); + const lit_utf8_byte_t *str_p = string_buff.ptr; + const lit_utf8_byte_t *regular_str_start_p = string_buff.ptr; + const lit_utf8_byte_t *str_end_p = string_buff.ptr + string_buff.size; ecma_stringbuilder_append_byte (builder_p, LIT_CHAR_DOUBLE_QUOTE); @@ -974,8 +973,6 @@ ecma_builtin_json_quote (ecma_stringbuilder_t *builder_p, /**< builder for the r ecma_stringbuilder_append_raw (builder_p, regular_str_start_p, (lit_utf8_size_t) (str_end_p - regular_str_start_p)); ecma_stringbuilder_append_byte (builder_p, LIT_CHAR_DOUBLE_QUOTE); - - ECMA_FINALIZE_UTF8_STRING (string_buff, string_buff_size); } /* ecma_builtin_json_quote */ static ecma_value_t ecma_builtin_json_serialize_property (ecma_json_stringify_context_t *context_p, diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c index 94c0384dd8..ff01f07946 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c @@ -131,10 +131,10 @@ ecma_op_escape_regexp_pattern (ecma_string_t *pattern_str_p) /**< RegExp pattern { ecma_stringbuilder_t builder = ecma_stringbuilder_create (); - ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start_p, pattern_start_size); + ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start); - const lit_utf8_byte_t *pattern_str_curr_p = pattern_start_p; - const lit_utf8_byte_t *pattern_str_end_p = pattern_start_p + pattern_start_size; + const lit_utf8_byte_t *pattern_str_curr_p = pattern_start.ptr; + const lit_utf8_byte_t *pattern_str_end_p = pattern_start.ptr + pattern_start.size; while (pattern_str_curr_p < pattern_str_end_p) { @@ -182,8 +182,6 @@ ecma_op_escape_regexp_pattern (ecma_string_t *pattern_str_p) /**< RegExp pattern } } - ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size); - return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); } /* ecma_op_escape_regexp_pattern */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c index 8616fbf5a5..323bc5b448 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c @@ -589,35 +589,32 @@ ecma_builtin_string_prototype_object_replace_helper (ecma_value_t this_value, /* } } - uint8_t input_flags = ECMA_STRING_FLAG_IS_ASCII; - replace_ctx.string_p = ecma_string_get_chars (input_str_p, &(replace_ctx.string_size), NULL, NULL, &input_flags); + ECMA_STRING_TO_UTF8_STRING (input_str_p, string); + replace_ctx.string_p = string.ptr; + replace_ctx.string_size = string.size; - lit_utf8_size_t search_size; - lit_utf8_size_t search_length; - uint8_t search_flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *search_buf_p = - ecma_string_get_chars (search_str_p, &search_size, &search_length, NULL, &search_flags); + ECMA_STRING_TO_UTF8_STRING_AND_LENGTH (search_str_p, search); ecma_string_t *result_string_p = NULL; - if (replace_ctx.string_size >= search_size) + if (replace_ctx.string_size >= search.size) { replace_ctx.builder = ecma_stringbuilder_create (); - replace_ctx.matched_size = search_size; + replace_ctx.matched_size = search.size; const lit_utf8_byte_t *const input_end_p = replace_ctx.string_p + replace_ctx.string_size; - const lit_utf8_byte_t *const loop_end_p = input_end_p - search_size; + const lit_utf8_byte_t *const loop_end_p = input_end_p - search.size; const lit_utf8_byte_t *last_match_end_p = replace_ctx.string_p; const lit_utf8_byte_t *curr_p = replace_ctx.string_p; lit_utf8_size_t pos = 0; while (curr_p <= loop_end_p) { - if (!memcmp (curr_p, search_buf_p, search_size)) + if (!memcmp (curr_p, search.ptr, search.size)) { const lit_utf8_size_t prefix_size = (lit_utf8_size_t) (curr_p - last_match_end_p); ecma_stringbuilder_append_raw (&replace_ctx.builder, last_match_end_p, prefix_size); - last_match_end_p = curr_p + search_size; + last_match_end_p = curr_p + search.size; if (replace_ctx.replace_str_p == NULL) { @@ -661,7 +658,7 @@ ecma_builtin_string_prototype_object_replace_helper (ecma_value_t this_value, /* break; } - if (search_size != 0) + if (search.size != 0) { curr_p = last_match_end_p; pos += search_length; @@ -688,15 +685,6 @@ ecma_builtin_string_prototype_object_replace_helper (ecma_value_t this_value, /* result = ecma_make_string_value (result_string_p); cleanup_replace: - if (input_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) replace_ctx.string_p, replace_ctx.string_size); - } - - if (search_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) search_buf_p, search_size); - } if (replace_ctx.replace_str_p != NULL) { @@ -967,22 +955,18 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_value, /**< this a goto cleanup_separator; } - lit_utf8_size_t string_size; - uint8_t string_flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *string_buffer_p = ecma_string_get_chars (string_p, &string_size, NULL, NULL, &string_flags); - lit_utf8_size_t separator_size; - uint8_t separator_flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *separator_buffer_p = - ecma_string_get_chars (separator_p, &separator_size, NULL, NULL, &separator_flags); + ECMA_STRING_TO_UTF8_STRING (string_p, string); + + ECMA_STRING_TO_UTF8_STRING (separator_p, separator); - const lit_utf8_byte_t *const string_end_p = string_buffer_p + string_size; - const lit_utf8_byte_t *const compare_end_p = JERRY_MIN (string_end_p - separator_size + 1, string_end_p); - const lit_utf8_byte_t *current_p = string_buffer_p; - const lit_utf8_byte_t *last_str_begin_p = string_buffer_p; + const lit_utf8_byte_t *const string_end_p = string.ptr + string.size; + const lit_utf8_byte_t *const compare_end_p = JERRY_MIN (string_end_p - separator.size + 1, string_end_p); + const lit_utf8_byte_t *current_p = string.ptr; + const lit_utf8_byte_t *last_str_begin_p = string.ptr; while (current_p < compare_end_p) { - if (!memcmp (current_p, separator_buffer_p, separator_size) && (last_str_begin_p != current_p + separator_size)) + if (!memcmp (current_p, separator.ptr, separator.size) && (last_str_begin_p != current_p + separator.size)) { ecma_string_t *substr_p = ecma_new_ecma_string_from_utf8 (last_str_begin_p, (lit_utf8_size_t) (current_p - last_str_begin_p)); @@ -998,7 +982,7 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_value, /**< this a goto cleanup_buffers; } - current_p += separator_size; + current_p += separator.size; last_str_begin_p = current_p; continue; } @@ -1016,16 +1000,6 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_value, /**< this a ecma_deref_ecma_string (end_substr_p); cleanup_buffers: - if (string_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) string_buffer_p, string_size); - } - - if (separator_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) separator_buffer_p, separator_size); - } - cleanup_separator: ecma_deref_ecma_string (separator_p); cleanup_string: @@ -1115,10 +1089,10 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_string_t *input_str { ecma_stringbuilder_t builder = ecma_stringbuilder_create (); - ECMA_STRING_TO_UTF8_STRING (input_string_p, input_start_p, input_start_size); + ECMA_STRING_TO_UTF8_STRING (input_string_p, input_start); - const lit_utf8_byte_t *input_curr_p = input_start_p; - const lit_utf8_byte_t *input_str_end_p = input_start_p + input_start_size; + const lit_utf8_byte_t *input_curr_p = input_start.ptr; + const lit_utf8_byte_t *input_str_end_p = input_start.ptr + input_start.size; while (input_curr_p < input_str_end_p) { @@ -1144,8 +1118,6 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_string_t *input_str } } - ECMA_FINALIZE_UTF8_STRING (input_start_p, input_start_size); - return ecma_make_string_value (ecma_stringbuilder_finalize (&builder)); } /* ecma_builtin_string_prototype_object_conversion_helper */ diff --git a/jerry-core/ecma/operations/ecma-bigint.c b/jerry-core/ecma/operations/ecma-bigint.c index 7a4464e0c9..b9a9b05ade 100644 --- a/jerry-core/ecma/operations/ecma-bigint.c +++ b/jerry-core/ecma/operations/ecma-bigint.c @@ -198,10 +198,9 @@ ecma_bigint_parse_string_value (ecma_value_t string, /**< ecma string */ { JERRY_ASSERT (ecma_is_value_string (string)); - ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (string), string_buffer_p, string_buffer_size); + ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (string), string_buffer); - ecma_value_t result = ecma_bigint_parse_string (string_buffer_p, string_buffer_size, options); - ECMA_FINALIZE_UTF8_STRING (string_buffer_p, string_buffer_size); + ecma_value_t result = ecma_bigint_parse_string (string_buffer.ptr, string_buffer.size, options); return result; } /* ecma_bigint_parse_string_value */ diff --git a/jerry-core/ecma/operations/ecma-regexp-object.c b/jerry-core/ecma/operations/ecma-regexp-object.c index e5b276aeae..c0f3da093c 100644 --- a/jerry-core/ecma/operations/ecma-regexp-object.c +++ b/jerry-core/ecma/operations/ecma-regexp-object.c @@ -63,10 +63,10 @@ ecma_regexp_parse_flags (ecma_string_t *flags_str_p, /**< Input string with flag ecma_value_t ret_value = ECMA_VALUE_EMPTY; uint16_t result_flags = RE_FLAG_EMPTY; - ECMA_STRING_TO_UTF8_STRING (flags_str_p, flags_start_p, flags_start_size); + ECMA_STRING_TO_UTF8_STRING (flags_str_p, flags_start); - const lit_utf8_byte_t *flags_str_curr_p = flags_start_p; - const lit_utf8_byte_t *flags_str_end_p = flags_start_p + flags_start_size; + const lit_utf8_byte_t *flags_str_curr_p = flags_start.ptr; + const lit_utf8_byte_t *flags_str_end_p = flags_start.ptr + flags_start.size; while (flags_str_curr_p < flags_str_end_p) { @@ -119,8 +119,6 @@ ecma_regexp_parse_flags (ecma_string_t *flags_str_p, /**< Input string with flag result_flags = (uint16_t) (result_flags | flag); } - ECMA_FINALIZE_UTF8_STRING (flags_start_p, flags_start_size); - *flags_p = result_flags; return ret_value; } /* ecma_regexp_parse_flags */ @@ -1601,17 +1599,13 @@ ecma_regexp_exec_helper (ecma_object_t *regexp_object_p, /**< RegExp object */ re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, ext_object_p->u.cls.u3.value); /* 3. */ - lit_utf8_size_t input_size; - lit_utf8_size_t input_length; - uint8_t input_flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *input_buffer_p = - ecma_string_get_chars (input_string_p, &input_size, &input_length, NULL, &input_flags); + ECMA_STRING_TO_UTF8_STRING_AND_LENGTH (input_string_p, input); - const lit_utf8_byte_t *input_curr_p = input_buffer_p; - const lit_utf8_byte_t *input_end_p = input_buffer_p + input_size; + const lit_utf8_byte_t *input_curr_p = input.ptr; + const lit_utf8_byte_t *input_end_p = input.ptr + input.size; ecma_regexp_ctx_t re_ctx; - ecma_regexp_initialize_context (&re_ctx, bc_p, input_buffer_p, input_end_p); + ecma_regexp_initialize_context (&re_ctx, bc_p, input.ptr, input_end_p); /* 4. */ ecma_length_t index = 0; @@ -1778,11 +1772,6 @@ ecma_regexp_exec_helper (ecma_object_t *regexp_object_p, /**< RegExp object */ cleanup_context: ecma_regexp_cleanup_context (&re_ctx); - if (input_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) input_buffer_p, input_size); - } - return ret_value; } /* ecma_regexp_exec_helper */ @@ -1970,17 +1959,14 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */ goto cleanup_string; } - lit_utf8_size_t flags_size; - uint8_t flags_str_flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *flags_buffer_p = - ecma_string_get_chars (flags_str_p, &flags_size, NULL, NULL, &flags_str_flags); + ECMA_STRING_TO_UTF8_STRING (flags_str_p, flags_buffer); bool unicode = false; bool sticky = false; /* 9-11. */ - const lit_utf8_byte_t *const flags_end_p = flags_buffer_p + flags_size; - for (const lit_utf8_byte_t *current_p = flags_buffer_p; current_p < flags_end_p; ++current_p) + const lit_utf8_byte_t *const flags_end_p = flags_buffer.ptr + flags_buffer.size; + for (const lit_utf8_byte_t *current_p = flags_buffer.ptr; current_p < flags_end_p; ++current_p) { switch (*current_p) { @@ -1997,11 +1983,6 @@ ecma_regexp_split_helper (ecma_value_t this_arg, /**< this value */ } } - if (flags_str_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) flags_buffer_p, flags_size); - } - /* 12. */ if (!sticky) { @@ -2270,9 +2251,9 @@ ecma_regexp_replace_helper_fast (ecma_replace_context_t *ctx_p, /**string_p = ecma_string_get_chars (string_p, &(ctx_p->string_size), &string_length, NULL, &string_flags); + ECMA_STRING_TO_UTF8_STRING_AND_LENGTH (string_p, string); + ctx_p->string_p = string.ptr; + ctx_p->string_size = string.size; const lit_utf8_byte_t *const string_end_p = ctx_p->string_p + ctx_p->string_size; const uint8_t *const bc_start_p = (const uint8_t *) (bc_p + 1); @@ -2485,11 +2466,6 @@ ecma_regexp_replace_helper_fast (ecma_replace_context_t *ctx_p, /**string_p, ctx_p->string_size); - } - return result; } /* ecma_regexp_replace_helper_fast */ @@ -2554,8 +2530,6 @@ ecma_regexp_replace_helper (ecma_value_t this_arg, /**< this argument */ ecma_free_value (result); - const lit_utf8_size_t string_length = ecma_string_get_length (string_p); - /* 10. */ if (replace_ctx.flags & RE_FLAG_GLOBAL) { @@ -2722,8 +2696,9 @@ ecma_regexp_replace_helper (ecma_value_t this_arg, /**< this argument */ } } - uint8_t string_flags = ECMA_STRING_FLAG_IS_ASCII; - replace_ctx.string_p = ecma_string_get_chars (string_p, &(replace_ctx.string_size), NULL, NULL, &string_flags); + ECMA_STRING_TO_UTF8_STRING_AND_LENGTH (string_p, string); + replace_ctx.string_p = string.ptr; + replace_ctx.string_size = string.size; /* 14. */ replace_ctx.builder = ecma_stringbuilder_create (); @@ -2941,10 +2916,6 @@ ecma_regexp_replace_helper (ecma_value_t this_arg, /**< this argument */ ecma_stringbuilder_destroy (&replace_ctx.builder); cleanup_chars: - if (string_flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) replace_ctx.string_p, replace_ctx.string_size); - } cleanup_results: ecma_collection_free (results_p); diff --git a/jerry-core/lit/lit-char-helpers.c b/jerry-core/lit/lit-char-helpers.c index ca36a488fb..2b6af1f97f 100644 --- a/jerry-core/lit/lit-char-helpers.c +++ b/jerry-core/lit/lit-char-helpers.c @@ -974,10 +974,10 @@ bool lit_find_char_in_string (ecma_string_t *str_p, /**< source string */ lit_utf8_byte_t c) /**< character to find*/ { - ECMA_STRING_TO_UTF8_STRING (str_p, start_p, start_size); + ECMA_STRING_TO_UTF8_STRING (str_p, start); - const lit_utf8_byte_t *str_curr_p = start_p; - const lit_utf8_byte_t *str_end_p = start_p + start_size; + const lit_utf8_byte_t *str_curr_p = start.ptr; + const lit_utf8_byte_t *str_end_p = start.ptr + start.size; bool have_char = false; while (str_curr_p < str_end_p) @@ -989,7 +989,5 @@ lit_find_char_in_string (ecma_string_t *str_p, /**< source string */ } } - ECMA_FINALIZE_UTF8_STRING (start_p, start_size); - return have_char; } /* lit_find_char_in_string */ diff --git a/jerry-core/lit/lit-globals.h b/jerry-core/lit/lit-globals.h index a970eee18e..2a3d78865a 100644 --- a/jerry-core/lit/lit-globals.h +++ b/jerry-core/lit/lit-globals.h @@ -118,4 +118,13 @@ typedef uint32_t lit_code_point_t; */ typedef uint32_t lit_string_hash_t; +/** + * An UTF-8 string + */ +typedef struct +{ + const lit_utf8_byte_t *ptr; /**< pointer to UTF-8/CESU-8 string */ + lit_utf8_size_t size; /**< string size excluding '\0' terminator */ +} lit_utf8_string_t; + #endif /* !LIT_GLOBALS_H */ diff --git a/jerry-core/parser/js/common.c b/jerry-core/parser/js/common.c index eafd167704..ae1b4af2cf 100644 --- a/jerry-core/parser/js/common.c +++ b/jerry-core/parser/js/common.c @@ -254,9 +254,8 @@ util_print_literal_value (ecma_compiled_code_t *compiled_code_p, /**< compiled c JERRY_DEBUG_MSG ("string("); - ECMA_STRING_TO_UTF8_STRING (literal_p, chars_p, literal_size); - util_print_chars (chars_p, literal_size); - ECMA_FINALIZE_UTF8_STRING (chars_p, literal_size); + ECMA_STRING_TO_UTF8_STRING (literal_p, chars); + util_print_chars (chars.ptr, chars.size); } JERRY_DEBUG_MSG (")"); diff --git a/jerry-core/parser/js/js-parser-internal.h b/jerry-core/parser/js/js-parser-internal.h index c6fb9004a4..f2e8e5b606 100644 --- a/jerry-core/parser/js/js-parser-internal.h +++ b/jerry-core/parser/js/js-parser-internal.h @@ -540,10 +540,8 @@ typedef struct parser_saved_context_t *last_context_p; /**< last saved context */ parser_stack_iterator_t last_statement; /**< last statement position */ cbc_script_t *script_p; /**< current script */ - const uint8_t *source_start_p; /**< source start */ - lit_utf8_size_t source_size; /**< source size */ - const uint8_t *arguments_start_p; /**< function argument list start */ - lit_utf8_size_t arguments_size; /**< function argument list size */ + lit_utf8_string_t source; /**< source start */ + lit_utf8_string_t arguments; /**< function argument list */ ecma_value_t script_value; /**< current script as value */ ecma_value_t argument_list; /**< current argument list as value */ ecma_value_t user_value; /**< current user value */ diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index 8f241b6a1a..dad4db6c18 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -916,15 +916,15 @@ parser_post_processing (parser_context_t *context_p) /**< context */ { extended_info |= CBC_EXTENDED_CODE_FLAGS_HAS_SOURCE_CODE_RANGE; - const uint8_t *start_p = context_p->source_start_p; + const uint8_t *start_p = context_p->source.ptr; const uint8_t *function_start_p = context_p->last_context_p->function_start_p; - if (function_start_p < start_p || function_start_p >= start_p + context_p->source_size) + if (function_start_p < start_p || function_start_p >= start_p + context_p->source.size) { - JERRY_ASSERT (context_p->arguments_start_p != NULL && function_start_p >= context_p->arguments_start_p - && function_start_p < context_p->arguments_start_p + context_p->arguments_size); + JERRY_ASSERT (context_p->arguments.ptr != NULL && function_start_p >= context_p->arguments.ptr + && function_start_p < context_p->arguments.ptr + context_p->arguments.size); - start_p = context_p->arguments_start_p; + start_p = context_p->arguments.ptr; extended_info |= CBC_EXTENDED_CODE_FLAGS_SOURCE_CODE_IN_ARGUMENTS; } @@ -1355,11 +1355,11 @@ parser_post_processing (parser_context_t *context_p) /**< context */ #if JERRY_FUNCTION_TO_STRING if (context_p->last_context_p != NULL) { - const uint8_t *start_p = context_p->source_start_p; + const uint8_t *start_p = context_p->source.ptr; if (extended_info & CBC_EXTENDED_CODE_FLAGS_SOURCE_CODE_IN_ARGUMENTS) { - start_p = context_p->arguments_start_p; + start_p = context_p->arguments.ptr; } const uint8_t *function_start_p = context_p->last_context_p->function_start_p; @@ -1999,8 +1999,8 @@ parser_parse_source (void *source_p, /**< source code */ context.stack_limit = 0; context.options_p = options_p; context.script_p = NULL; - context.arguments_start_p = NULL; - context.arguments_size = 0; + context.arguments.ptr = NULL; + context.arguments.size = 0; #if JERRY_MODULE_SYSTEM if (context.global_status_flags & ECMA_PARSE_MODULE) { @@ -2040,7 +2040,7 @@ parser_parse_source (void *source_p, /**< source code */ ecma_string_t *string_p = ecma_get_string_from_value (context.argument_list); uint8_t flags = ECMA_STRING_FLAG_EMPTY; - context.arguments_start_p = ecma_string_get_chars (string_p, &context.arguments_size, NULL, NULL, &flags); + ecma_string_get_chars (string_p, &context.arguments, NULL, &flags); if (flags & ECMA_STRING_FLAG_MUST_BE_FREED) { @@ -2050,8 +2050,8 @@ parser_parse_source (void *source_p, /**< source code */ if (!(context.global_status_flags & ECMA_PARSE_HAS_SOURCE_VALUE)) { - context.source_start_p = ((parser_source_char_t *) source_p)->source_p; - context.source_size = (lit_utf8_size_t) ((parser_source_char_t *) source_p)->source_size; + context.source.ptr = ((parser_source_char_t *) source_p)->source_p; + context.source.size = (lit_utf8_size_t) ((parser_source_char_t *) source_p)->source_size; } else { @@ -2062,7 +2062,7 @@ parser_parse_source (void *source_p, /**< source code */ ecma_string_t *string_p = ecma_get_string_from_value (source); uint8_t flags = ECMA_STRING_FLAG_EMPTY; - context.source_start_p = ecma_string_get_chars (string_p, &context.source_size, NULL, NULL, &flags); + ecma_string_get_chars (string_p, &context.source, NULL, &flags); if (flags & ECMA_STRING_FLAG_MUST_BE_FREED) { @@ -2075,8 +2075,8 @@ parser_parse_source (void *source_p, /**< source code */ { jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE, JERRY_DEBUGGER_NO_SUBTYPE, - context.source_start_p, - context.source_size); + context.source.ptr, + context.source.size); } #endif /* JERRY_DEBUGGER */ @@ -2160,7 +2160,7 @@ parser_parse_source (void *source_p, /**< source code */ if (context.is_show_opcodes) { - JERRY_DEBUG_MSG ("\n--- %s parsing start ---\n\n", (context.arguments_start_p == NULL) ? "Script" : "Function"); + JERRY_DEBUG_MSG ("\n--- %s parsing start ---\n\n", (context.arguments.ptr == NULL) ? "Script" : "Function"); } #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ @@ -2176,15 +2176,15 @@ parser_parse_source (void *source_p, /**< source code */ return NULL; } - if (context.arguments_start_p == NULL) + if (context.arguments.ptr == NULL) { - context.source_p = context.source_start_p; - context.source_end_p = context.source_start_p + context.source_size; + context.source_p = context.source.ptr; + context.source_end_p = context.source.ptr + context.source.size; } else { - context.source_p = context.arguments_start_p; - context.source_end_p = context.arguments_start_p + context.arguments_size; + context.source_p = context.arguments.ptr; + context.source_end_p = context.arguments.ptr + context.arguments.size; } context.u.allocated_buffer_p = NULL; @@ -2234,15 +2234,15 @@ parser_parse_source (void *source_p, /**< source code */ * lexer_next_token() must be immediately called. */ lexer_next_token (&context); - if (context.arguments_start_p != NULL) + if (context.arguments.ptr != NULL) { parser_parse_function_arguments (&context, LEXER_EOS); JERRY_ASSERT (context.next_scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS); scanner_release_next (&context, sizeof (scanner_info_t)); - context.source_p = context.source_start_p; - context.source_end_p = context.source_start_p + context.source_size; + context.source_p = context.source.ptr; + context.source_end_p = context.source.ptr + context.source.size; lexer_init_line_info (&context); lexer_next_token (&context); @@ -2261,7 +2261,7 @@ parser_parse_source (void *source_p, /**< source code */ #endif /* JERRY_MODULE_SYSTEM */ else { - JERRY_ASSERT (context.next_scanner_info_p->source_p == context.source_start_p + JERRY_ASSERT (context.next_scanner_info_p->source_p == context.source.ptr && context.next_scanner_info_p->type == SCANNER_TYPE_FUNCTION); if (scanner_is_context_needed (&context, PARSER_CHECK_GLOBAL_CONTEXT)) @@ -2300,7 +2300,7 @@ parser_parse_source (void *source_p, /**< source code */ && context.stack.first_p != NULL && context.stack.first_p->next_p == NULL && context.stack.last_p == NULL); - JERRY_ASSERT (context.arguments_start_p != NULL || !(context.status_flags & PARSER_ARGUMENTS_NEEDED)); + JERRY_ASSERT (context.arguments.ptr != NULL || !(context.status_flags & PARSER_ARGUMENTS_NEEDED)); context.script_p->refs_and_type -= CBC_SCRIPT_REF_ONE; @@ -2327,11 +2327,11 @@ parser_parse_source (void *source_p, /**< source code */ if (context.global_status_flags & ECMA_PARSE_INTERNAL_HAS_4_BYTE_MARKER) { - string_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (context.source_start_p, context.source_size); + string_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (context.source.ptr, context.source.size); } else { - string_p = ecma_new_ecma_string_from_utf8 (context.source_start_p, context.source_size); + string_p = ecma_new_ecma_string_from_utf8 (context.source.ptr, context.source.size); } context.script_p->source_code = ecma_make_string_value (string_p); @@ -2359,7 +2359,7 @@ parser_parse_source (void *source_p, /**< source code */ if (context.is_show_opcodes) { JERRY_DEBUG_MSG ("\n%s parsing successfully completed. Total byte code size: %d bytes\n", - (context.arguments_start_p == NULL) ? "Script" : "Function", + (context.arguments.ptr == NULL) ? "Script" : "Function", (int) context.total_byte_code_size); } #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ @@ -2410,7 +2410,7 @@ parser_parse_source (void *source_p, /**< source code */ #if JERRY_PARSER_DUMP_BYTE_CODE if (context.is_show_opcodes) { - JERRY_DEBUG_MSG ("\n--- %s parsing end ---\n\n", (context.arguments_start_p == NULL) ? "Script" : "Function"); + JERRY_DEBUG_MSG ("\n--- %s parsing end ---\n\n", (context.arguments.ptr == NULL) ? "Script" : "Function"); } #endif /* JERRY_PARSER_DUMP_BYTE_CODE */ @@ -2418,12 +2418,12 @@ parser_parse_source (void *source_p, /**< source code */ if (context.global_status_flags & ECMA_PARSE_INTERNAL_FREE_SOURCE) { - jmem_heap_free_block ((void *) context.source_start_p, context.source_size); + jmem_heap_free_block ((void *) context.source.ptr, context.source.size); } if (context.global_status_flags & ECMA_PARSE_INTERNAL_FREE_ARG_LIST) { - jmem_heap_free_block ((void *) context.arguments_start_p, context.arguments_size); + jmem_heap_free_block ((void *) context.arguments.ptr, context.arguments.size); } if (compiled_code_p != NULL) @@ -3360,12 +3360,9 @@ parser_parse_script (void *source_p, /**< source code */ return bytecode_p; #else /* !JERRY_PARSER */ - JERRY_UNUSED (arg_list_p); - JERRY_UNUSED (arg_list_size); JERRY_UNUSED (source_p); - JERRY_UNUSED (source_size); JERRY_UNUSED (parse_opts); - JERRY_UNUSED (source_name); + JERRY_UNUSED (options_p); ecma_raise_syntax_error (ECMA_ERR_PARSER_NOT_SUPPORTED); return NULL; diff --git a/jerry-core/parser/js/js-scanner.c b/jerry-core/parser/js/js-scanner.c index 30d6e977c6..8c6c8f36d1 100644 --- a/jerry-core/parser/js/js-scanner.c +++ b/jerry-core/parser/js/js-scanner.c @@ -2434,10 +2434,10 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ PARSER_TRY (context_p->try_buffer) { - if (context_p->arguments_start_p == NULL) + if (context_p->arguments.ptr == NULL) { - context_p->source_p = context_p->source_start_p; - context_p->source_end_p = context_p->source_start_p + context_p->source_size; + context_p->source_p = context_p->source.ptr; + context_p->source_end_p = context_p->source.ptr + context_p->source.size; uint16_t status_flags = (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_NO_ARGUMENTS | SCANNER_LITERAL_POOL_CAN_EVAL); @@ -2448,7 +2448,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ } scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, &scanner_context, status_flags); - literal_pool_p->source_p = context_p->source_start_p; + literal_pool_p->source_p = context_p->source.ptr; parser_stack_push_uint8 (context_p, SCAN_STACK_SCRIPT); @@ -2457,8 +2457,8 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ } else { - context_p->source_p = context_p->arguments_start_p; - context_p->source_end_p = context_p->arguments_start_p + context_p->arguments_size; + context_p->source_p = context_p->arguments.ptr; + context_p->source_end_p = context_p->arguments.ptr + context_p->arguments.size; uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION; @@ -3066,8 +3066,8 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ scanner_context.end_arguments_p = scanner_info_p; context_p->next_scanner_info_p = scanner_info_p; - context_p->source_p = context_p->source_start_p; - context_p->source_end_p = context_p->source_start_p + context_p->source_size; + context_p->source_p = context_p->source.ptr; + context_p->source_end_p = context_p->source.ptr + context_p->source.size; lexer_init_line_info (context_p); scanner_filter_arguments (context_p, &scanner_context); @@ -3445,7 +3445,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ { scanner_info_t *info_p = context_p->next_scanner_info_p; const uint8_t *source_start_p = - (context_p->arguments_start_p == NULL ? context_p->source_start_p : context_p->arguments_start_p); + (context_p->arguments.ptr == NULL ? context_p->source.ptr : context_p->arguments.ptr); while (info_p->type != SCANNER_TYPE_END) { @@ -3457,7 +3457,7 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ case SCANNER_TYPE_END_ARGUMENTS: { JERRY_DEBUG_MSG (" END_ARGUMENTS\n"); - source_start_p = context_p->source_start_p; + source_start_p = context_p->source.ptr; break; } case SCANNER_TYPE_FUNCTION: diff --git a/jerry-core/parser/regexp/re-compiler.c b/jerry-core/parser/regexp/re-compiler.c index a495616b5f..ea964b3cfa 100644 --- a/jerry-core/parser/regexp/re-compiler.c +++ b/jerry-core/parser/regexp/re-compiler.c @@ -121,18 +121,16 @@ re_compile_bytecode (ecma_string_t *pattern_str_p, /**< pattern */ re_initialize_regexp_bytecode (&re_ctx); - ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start_p, pattern_start_size); + ECMA_STRING_TO_UTF8_STRING (pattern_str_p, pattern_start); - re_ctx.input_start_p = pattern_start_p; - re_ctx.input_curr_p = (lit_utf8_byte_t *) pattern_start_p; - re_ctx.input_end_p = pattern_start_p + pattern_start_size; + re_ctx.input_start_p = pattern_start.ptr; + re_ctx.input_curr_p = (lit_utf8_byte_t *) pattern_start.ptr; + re_ctx.input_end_p = pattern_start.ptr + pattern_start.size; re_ctx.groups_count = -1; /* Parse RegExp pattern */ ecma_value_t result = re_parse_alternative (&re_ctx, true); - ECMA_FINALIZE_UTF8_STRING (pattern_start_p, pattern_start_size); - if (ECMA_IS_VALUE_ERROR (result)) { /* Compilation failed, free bytecode. */