Improve empty checks of ecma strings

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-05-31 14:38:36 +02:00
parent 2324617928
commit 7f153c799a
8 changed files with 29 additions and 17 deletions
@@ -123,12 +123,12 @@ ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this
ecma_string_t *ret_str_p;
if (ecma_string_get_length (name_string_p) == 0)
if (ecma_string_is_empty (name_string_p))
{
ret_str_p = msg_string_p;
ecma_ref_ecma_string (ret_str_p);
}
else if (ecma_string_get_length (msg_string_p) == 0)
else if (ecma_string_is_empty (msg_string_p))
{
ret_str_p = name_string_p;
ecma_ref_ecma_string (ret_str_p);
@@ -1495,9 +1495,7 @@ ecma_builtin_json_object (ecma_object_t *obj_p, /**< the object*/
member_str_p = tmp_str_p;
/* 8.b.iii */
bool is_gap_empty = (ecma_string_get_length (context_p->gap_str_p) == 0);
if (!is_gap_empty)
if (!ecma_string_is_empty (context_p->gap_str_p))
{
ecma_string_t *space_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_SPACE_CHAR);
@@ -1548,10 +1546,8 @@ ecma_builtin_json_object (ecma_object_t *obj_p, /**< the object*/
/* 10. */
else
{
bool is_gap_empty = (ecma_string_get_length (context_p->gap_str_p) == 0);
/* 10.a */
if (is_gap_empty)
if (ecma_string_is_empty (context_p->gap_str_p))
{
ecma_string_t *left_brace_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LEFT_BRACE_CHAR);
ecma_string_t *right_brace_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_RIGHT_BRACE_CHAR);
@@ -1688,9 +1684,8 @@ ecma_builtin_json_array (ecma_object_t *obj_p, /**< the array object*/
/* 10. */
else
{
bool is_gap_empty = (ecma_string_get_length (context_p->gap_str_p) == 0);
/* 10.a */
if (is_gap_empty)
if (ecma_string_is_empty (context_p->gap_str_p))
{
ecma_string_t *left_square_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LEFT_SQUARE_CHAR);
ecma_string_t *right_square_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_RIGHT_SQUARE_CHAR);
@@ -162,7 +162,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument
ecma_op_to_string (pattern_arg),
ret_value);
if (ecma_string_get_length (ecma_get_string_from_value (regexp_str_value)) == 0)
if (ecma_string_is_empty (ecma_get_string_from_value (regexp_str_value)))
{
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
}
@@ -103,7 +103,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
ecma_op_to_string (pattern_value),
ret_value);
if (ecma_string_get_length (ecma_get_string_from_value (regexp_str_value)) == 0)
if (ecma_string_is_empty (ecma_get_string_from_value (regexp_str_value)))
{
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
}
@@ -1670,9 +1670,6 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_arg, /**< this arg
}
else /* if (!ecma_is_value_undefined (arg1)) */
{
/* 6. */
const ecma_length_t string_length = ecma_string_get_length (ecma_get_string_from_value (this_to_string_val));
/* 8. */
ecma_value_t separator = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
@@ -1692,8 +1689,11 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_arg, /**< this arg
ECMA_FINALIZE (separator_to_string_val);
}
const ecma_string_t *this_to_string_p = ecma_get_string_from_value (this_to_string_val);
/* 11. */
if (string_length == 0 && ecma_is_value_empty (ret_value))
if (ecma_string_is_empty (this_to_string_p)
&& ecma_is_value_empty (ret_value))
{
/* 11.a */
ecma_value_t match_result = ecma_builtin_helper_split_match (this_to_string_val,
@@ -1741,6 +1741,9 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_arg, /**< this arg
bool separator_is_empty = false;
/* 6. */
const ecma_length_t string_length = ecma_string_get_length (this_to_string_p);
/* 13. */
while (curr_pos < string_length && !should_return && ecma_is_value_empty (ret_value))
{