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
@@ -831,6 +831,19 @@ ecma_string_raw_chars (const ecma_string_t *string_p, /**< ecma-string */
return result_p;
} /* ecma_string_raw_chars */
/**
* Checks whether ecma string is empty or not
*
* @return true - if empty
* false - otherwise
*/
bool
ecma_string_is_empty (const ecma_string_t *str_p) /**< ecma-string */
{
return (ECMA_STRING_GET_CONTAINER (str_p) == ECMA_STRING_CONTAINER_MAGIC_STRING
&& str_p->u.magic_string_id == LIT_MAGIC_STRING__EMPTY);
} /* ecma_string_is_empty */
/**
* Long path part of ecma-string to ecma-string comparison routine
*
+1
View File
@@ -179,6 +179,7 @@ ecma_string_copy_to_utf8_buffer (const ecma_string_t *, lit_utf8_byte_t *, lit_u
extern void ecma_string_to_utf8_bytes (const ecma_string_t *, lit_utf8_byte_t *, lit_utf8_size_t);
extern const lit_utf8_byte_t *ecma_string_raw_chars (const ecma_string_t *, lit_utf8_size_t *, bool *);
extern void ecma_init_ecma_string_from_uint32 (ecma_string_t *, uint32_t);
extern bool ecma_string_is_empty (const ecma_string_t *);
extern bool ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *, const ecma_string_t *);
extern bool ecma_compare_ecma_strings (const ecma_string_t *, const ecma_string_t *);
@@ -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))
{
+1 -1
View File
@@ -222,7 +222,7 @@ ecma_op_to_boolean (ecma_value_t value) /**< ecma value */
{
ecma_string_t *str_p = ecma_get_string_from_value (value);
return ecma_string_get_length (str_p) != 0;
return !ecma_string_is_empty (str_p);
}
JERRY_ASSERT (ecma_is_value_object (value));