Optimize string concatenation. (#2141)

This patch adds two new string concatenation functions:
ecma_append_chars_to_string and ecma_append_magic_string_to_string

The former appends a cesu8 byte array and the latter appends a magic string
to the end of an ecma-string. These two free (dereference) their ecma-string
argument, and this change is also applied to the original ecma_concat_ecma_strings
function which simplifies string handling in most cases.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2017-12-19 13:45:48 +01:00
committed by GitHub
parent bd574956e3
commit a2d3ea61eb
16 changed files with 369 additions and 555 deletions
+16 -19
View File
@@ -176,8 +176,6 @@ ecma_raise_standard_error_with_format (ecma_standard_error_t error_type, /**< er
JERRY_ASSERT (format != NULL);
ecma_string_t *error_msg_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
ecma_string_t *string1_p;
ecma_string_t *string2_p;
const char *start_p = format;
const char *end_p = format;
@@ -193,12 +191,13 @@ ecma_raise_standard_error_with_format (ecma_standard_error_t error_type, /**< er
/* Concat template string. */
if (end_p > start_p)
{
string1_p = error_msg_p;
string2_p = ecma_new_ecma_string_from_utf8 ((const lit_utf8_byte_t *) start_p,
(lit_utf8_size_t) (end_p - start_p));
error_msg_p = ecma_concat_ecma_strings (string1_p, string2_p);
ecma_deref_ecma_string (string1_p);
ecma_deref_ecma_string (string2_p);
const lit_utf8_byte_t *chars_p = (const lit_utf8_byte_t *) start_p;
lit_utf8_size_t chars_size = (lit_utf8_size_t) (end_p - start_p);
error_msg_p = ecma_append_chars_to_string (error_msg_p,
chars_p,
chars_size,
lit_utf8_string_length (chars_p, chars_size));
}
/* Convert an argument to string without side effects. */
@@ -217,11 +216,8 @@ ecma_raise_standard_error_with_format (ecma_standard_error_t error_type, /**< er
}
/* Concat argument. */
string1_p = error_msg_p;
string2_p = arg_string_p;
error_msg_p = ecma_concat_ecma_strings (string1_p, string2_p);
ecma_deref_ecma_string (string1_p);
ecma_deref_ecma_string (string2_p);
error_msg_p = ecma_concat_ecma_strings (error_msg_p, arg_string_p);
ecma_deref_ecma_string (arg_string_p);
start_p = end_p + 1;
}
@@ -234,12 +230,13 @@ ecma_raise_standard_error_with_format (ecma_standard_error_t error_type, /**< er
/* Concat reset of template string. */
if (start_p < end_p)
{
string1_p = error_msg_p;
string2_p = ecma_new_ecma_string_from_utf8 ((const lit_utf8_byte_t *) start_p,
(lit_utf8_size_t) (end_p - start_p));
error_msg_p = ecma_concat_ecma_strings (string1_p, string2_p);
ecma_deref_ecma_string (string1_p);
ecma_deref_ecma_string (string2_p);
const lit_utf8_byte_t *chars_p = (const lit_utf8_byte_t *) start_p;
lit_utf8_size_t chars_size = (lit_utf8_size_t) (end_p - start_p);
error_msg_p = ecma_append_chars_to_string (error_msg_p,
chars_p,
chars_size,
lit_utf8_string_length (chars_p, chars_size));
}
ecma_object_t *error_obj_p = ecma_new_standard_error_with_message (error_type, error_msg_p);
@@ -284,6 +284,7 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
if (!ecma_is_value_object (prototype_obj_value))
{
ecma_free_value (prototype_obj_value);
return ecma_raise_type_error (ECMA_ERR_MSG ("Object expected."));
}