Improve magic string handling. (#2221)
Remove unnecessary ref / deref calls when magic strings are used. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -79,19 +79,18 @@ ecma_builtin_promise_reject_or_resolve (ecma_value_t this_arg, /**< "this" argum
|
||||
return capability;
|
||||
}
|
||||
|
||||
ecma_string_t *str;
|
||||
ecma_string_t *property_str_p;
|
||||
|
||||
if (is_resolve)
|
||||
{
|
||||
str = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
property_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
str = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
property_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
}
|
||||
|
||||
ecma_value_t func = ecma_op_object_get (ecma_get_object_from_value (capability), str);
|
||||
ecma_deref_ecma_string (str);
|
||||
ecma_value_t func = ecma_op_object_get (ecma_get_object_from_value (capability), property_str_p);
|
||||
|
||||
ecma_value_t call_ret = ecma_op_function_call (ecma_get_object_from_value (func),
|
||||
ECMA_VALUE_UNDEFINED,
|
||||
@@ -107,9 +106,8 @@ ecma_builtin_promise_reject_or_resolve (ecma_value_t this_arg, /**< "this" argum
|
||||
|
||||
ecma_free_value (call_ret);
|
||||
|
||||
ecma_string_t *str_promise = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_value_t promise_new = ecma_op_object_get (ecma_get_object_from_value (capability), str_promise);
|
||||
ecma_deref_ecma_string (str_promise);
|
||||
ecma_string_t *promise_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_value_t promise_new = ecma_op_object_get (ecma_get_object_from_value (capability), promise_str_p);
|
||||
ecma_free_value (capability);
|
||||
|
||||
return promise_new;
|
||||
@@ -128,9 +126,8 @@ inline static ecma_value_t
|
||||
ecma_builtin_promise_reject_abrupt (ecma_value_t capability) /**< reject description */
|
||||
{
|
||||
ecma_value_t reason = JERRY_CONTEXT (error_value);
|
||||
ecma_string_t *str_reject = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
ecma_value_t reject = ecma_op_object_get (ecma_get_object_from_value (capability), str_reject);
|
||||
ecma_deref_ecma_string (str_reject);
|
||||
ecma_string_t *reject_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
ecma_value_t reject = ecma_op_object_get (ecma_get_object_from_value (capability), reject_str_p);
|
||||
|
||||
ecma_value_t call_ret = ecma_op_function_call (ecma_get_object_from_value (reject),
|
||||
ECMA_VALUE_UNDEFINED,
|
||||
@@ -145,9 +142,8 @@ ecma_builtin_promise_reject_abrupt (ecma_value_t capability) /**< reject descrip
|
||||
|
||||
ecma_free_value (call_ret);
|
||||
|
||||
ecma_string_t *str_promise = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_value_t promise_new = ecma_op_object_get (ecma_get_object_from_value (capability), str_promise);
|
||||
ecma_deref_ecma_string (str_promise);
|
||||
ecma_string_t *promise_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_value_t promise_new = ecma_op_object_get (ecma_get_object_from_value (capability), promise_str_p);
|
||||
|
||||
return promise_new;
|
||||
} /* ecma_builtin_promise_reject_abrupt */
|
||||
@@ -210,28 +206,28 @@ ecma_builtin_promise_do_race (ecma_value_t array, /**< the array for race */
|
||||
ecma_length_t len = (ecma_length_t) ecma_get_integer_from_value (len_value);
|
||||
ecma_fast_free_value (len_value);
|
||||
|
||||
ecma_string_t *str_promise = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_string_t *str_resolve = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
ecma_string_t *str_reject = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
ecma_string_t *promise_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_string_t *resolve_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
ecma_string_t *reject_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
|
||||
ecma_value_t resolve = ecma_op_object_get (ecma_get_object_from_value (capability),
|
||||
str_resolve);
|
||||
resolve_str_p);
|
||||
ecma_value_t reject = ecma_op_object_get (ecma_get_object_from_value (capability),
|
||||
str_reject);
|
||||
reject_str_p);
|
||||
|
||||
for (ecma_length_t index = 0; index <= len; index++)
|
||||
{
|
||||
/* b-d. */
|
||||
if (index == len)
|
||||
{
|
||||
ret = ecma_op_object_get (ecma_get_object_from_value (capability), str_promise);
|
||||
ret = ecma_op_object_get (ecma_get_object_from_value (capability), promise_str_p);
|
||||
break;
|
||||
}
|
||||
|
||||
/* e. */
|
||||
ecma_string_t *str_index = ecma_new_ecma_string_from_uint32 (index);
|
||||
ecma_value_t array_item = ecma_op_object_get (array_p, str_index);
|
||||
ecma_deref_ecma_string (str_index);
|
||||
ecma_string_t *index_to_str_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
ecma_value_t array_item = ecma_op_object_get (array_p, index_to_str_p);
|
||||
ecma_deref_ecma_string (index_to_str_p);
|
||||
|
||||
/* h. */
|
||||
ecma_value_t next_promise = ecma_builtin_promise_resolve (ctor, array_item);
|
||||
@@ -260,9 +256,6 @@ ecma_builtin_promise_do_race (ecma_value_t array, /**< the array for race */
|
||||
|
||||
ecma_free_value (reject);
|
||||
ecma_free_value (resolve);
|
||||
ecma_deref_ecma_string (str_promise);
|
||||
ecma_deref_ecma_string (str_resolve);
|
||||
ecma_deref_ecma_string (str_reject);
|
||||
|
||||
JERRY_ASSERT (!ecma_is_value_empty (ret));
|
||||
|
||||
@@ -323,8 +316,8 @@ ecma_builtin_promise_all_handler (const ecma_value_t function, /**< the function
|
||||
ecma_value_t ret = ECMA_VALUE_UNDEFINED;
|
||||
/* 1. */
|
||||
ecma_object_t *function_p = ecma_get_object_from_value (function);
|
||||
ecma_string_t *str_already_called = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_ALREADY_CALLED);
|
||||
ecma_value_t already_called = ecma_op_object_get (function_p, str_already_called);
|
||||
ecma_string_t *already_called_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_ALREADY_CALLED);
|
||||
ecma_value_t already_called = ecma_op_object_get (function_p, already_called_str_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (already_called));
|
||||
|
||||
@@ -332,46 +325,43 @@ ecma_builtin_promise_all_handler (const ecma_value_t function, /**< the function
|
||||
if (ecma_is_value_true (already_called))
|
||||
{
|
||||
ecma_fast_free_value (already_called);
|
||||
ecma_deref_ecma_string (str_already_called);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 3. */
|
||||
ecma_op_object_put (function_p,
|
||||
str_already_called,
|
||||
already_called_str_p,
|
||||
ecma_make_boolean_value (true),
|
||||
false);
|
||||
|
||||
ecma_string_t *str_index = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_INDEX);
|
||||
ecma_string_t *str_value = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_VALUE);
|
||||
ecma_string_t *str_capability = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_CAPABILITY);
|
||||
ecma_string_t *str_remaining = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REMAINING_ELEMENT);
|
||||
ecma_string_t *str_index_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_INDEX);
|
||||
ecma_string_t *str_value_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_VALUE);
|
||||
ecma_string_t *str_capability_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_CAPABILITY);
|
||||
ecma_string_t *str_remaining_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REMAINING_ELEMENT);
|
||||
|
||||
/* 4-7. */
|
||||
ecma_value_t index_val = ecma_op_object_get (function_p, str_index);
|
||||
ecma_value_t value_array = ecma_op_object_get (function_p, str_value);
|
||||
ecma_value_t capability = ecma_op_object_get (function_p, str_capability);
|
||||
ecma_value_t remaining = ecma_op_object_get (function_p, str_remaining);
|
||||
ecma_value_t index_val = ecma_op_object_get (function_p, str_index_p);
|
||||
ecma_value_t value_array = ecma_op_object_get (function_p, str_value_p);
|
||||
ecma_value_t capability = ecma_op_object_get (function_p, str_capability_p);
|
||||
ecma_value_t remaining = ecma_op_object_get (function_p, str_remaining_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_integer_number (index_val));
|
||||
|
||||
/* 8. */
|
||||
ecma_string_t *index_str = ecma_new_ecma_string_from_uint32 ((uint32_t) ecma_get_integer_from_value (index_val));
|
||||
ecma_string_t *index_to_str_p = ecma_new_ecma_string_from_uint32 ((uint32_t) ecma_get_integer_from_value (index_val));
|
||||
|
||||
ecma_op_object_put (ecma_get_object_from_value (value_array),
|
||||
index_str,
|
||||
index_to_str_p,
|
||||
argv[0],
|
||||
false);
|
||||
ecma_deref_ecma_string (index_str);
|
||||
ecma_deref_ecma_string (index_to_str_p);
|
||||
|
||||
/* 9-10. */
|
||||
if (ecma_builtin_promise_remaining_inc_or_dec (remaining, false) == 0)
|
||||
{
|
||||
ecma_string_t *str_resolve = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
ecma_value_t resolve = ecma_op_object_get (ecma_get_object_from_value (capability),
|
||||
str_resolve);
|
||||
ecma_deref_ecma_string (str_resolve);
|
||||
ecma_string_t *resolve_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
ecma_value_t resolve = ecma_op_object_get (ecma_get_object_from_value (capability), resolve_str_p);
|
||||
|
||||
ret = ecma_op_function_call (ecma_get_object_from_value (resolve),
|
||||
ECMA_VALUE_UNDEFINED,
|
||||
&value_array,
|
||||
@@ -384,11 +374,6 @@ ecma_builtin_promise_all_handler (const ecma_value_t function, /**< the function
|
||||
ecma_free_value (value_array);
|
||||
ecma_fast_free_value (index_val);
|
||||
ecma_fast_free_value (already_called);
|
||||
ecma_deref_ecma_string (str_already_called);
|
||||
ecma_deref_ecma_string (str_index);
|
||||
ecma_deref_ecma_string (str_value);
|
||||
ecma_deref_ecma_string (str_capability);
|
||||
ecma_deref_ecma_string (str_remaining);
|
||||
|
||||
return ret;
|
||||
} /* ecma_builtin_promise_all_handler */
|
||||
@@ -419,21 +404,21 @@ ecma_builtin_promise_do_all (ecma_value_t array, /**< the array for all */
|
||||
ecma_length_t len = (ecma_length_t) ecma_get_integer_from_value (len_value);
|
||||
ecma_fast_free_value (len_value);
|
||||
|
||||
ecma_string_t *str_promise = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_string_t *str_resolve = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
ecma_string_t *str_reject = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
ecma_string_t *str_already_called = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_ALREADY_CALLED);
|
||||
ecma_string_t *str_index = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_INDEX);
|
||||
ecma_string_t *str_value = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_VALUE);
|
||||
ecma_string_t *str_capability = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_CAPABILITY);
|
||||
ecma_string_t *str_remaining = ecma_new_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REMAINING_ELEMENT);
|
||||
ecma_string_t *promise_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_PROMISE);
|
||||
ecma_string_t *resolve_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_RESOLVE);
|
||||
ecma_string_t *reject_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REJECT);
|
||||
ecma_string_t *already_called_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_ALREADY_CALLED);
|
||||
ecma_string_t *index_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_INDEX);
|
||||
ecma_string_t *value_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_VALUE);
|
||||
ecma_string_t *capability_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_CAPABILITY);
|
||||
ecma_string_t *remaining_str_p = ecma_get_ecma_string_from_uint32 (ECMA_PROMISE_PROPERTY_REMAINING_ELEMENT);
|
||||
|
||||
ecma_value_t undefined_val = ECMA_VALUE_UNDEFINED;
|
||||
/* String '1' indicates [[Resolve]] and '2' indicates [[Reject]]. */
|
||||
ecma_value_t resolve = ecma_op_object_get (ecma_get_object_from_value (capability),
|
||||
str_resolve);
|
||||
resolve_str_p);
|
||||
ecma_value_t reject = ecma_op_object_get (ecma_get_object_from_value (capability),
|
||||
str_reject);
|
||||
reject_str_p);
|
||||
/* 3. */
|
||||
ecma_value_t result_array_length_val = ecma_make_uint32_value (0);
|
||||
ecma_value_t value_array = ecma_op_create_array_object (&result_array_length_val, 1, true);
|
||||
@@ -467,18 +452,18 @@ ecma_builtin_promise_do_all (ecma_value_t array, /**< the array for all */
|
||||
}
|
||||
|
||||
/* iv. */
|
||||
ret = ecma_op_object_get (ecma_get_object_from_value (capability), str_promise);
|
||||
ret = ecma_op_object_get (ecma_get_object_from_value (capability), promise_str_p);
|
||||
break;
|
||||
}
|
||||
|
||||
/* e. h. */
|
||||
ecma_string_t *index_str = ecma_new_ecma_string_from_uint32 (index);
|
||||
ecma_value_t array_item = ecma_op_object_get (array_p, index_str);
|
||||
ecma_string_t *index_to_str_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
ecma_value_t array_item = ecma_op_object_get (array_p, index_to_str_p);
|
||||
ecma_op_object_put (ecma_get_object_from_value (value_array),
|
||||
index_str,
|
||||
index_to_str_p,
|
||||
undefined_val,
|
||||
false);
|
||||
ecma_deref_ecma_string (index_str);
|
||||
ecma_deref_ecma_string (index_to_str_p);
|
||||
/* i. */
|
||||
ecma_value_t next_promise = ecma_builtin_promise_resolve (ctor, array_item);
|
||||
ecma_free_value (array_item);
|
||||
@@ -495,27 +480,27 @@ ecma_builtin_promise_do_all (ecma_value_t array, /**< the array for all */
|
||||
res_ele_p = ecma_op_create_external_function_object (ecma_builtin_promise_all_handler);
|
||||
/* l. */
|
||||
ecma_op_object_put (res_ele_p,
|
||||
str_already_called,
|
||||
already_called_str_p,
|
||||
ecma_make_boolean_value (false),
|
||||
false);
|
||||
/* m. */
|
||||
ecma_op_object_put (res_ele_p,
|
||||
str_index,
|
||||
index_str_p,
|
||||
ecma_make_uint32_value (index),
|
||||
false);
|
||||
/* n. */
|
||||
ecma_op_object_put (res_ele_p,
|
||||
str_value,
|
||||
value_str_p,
|
||||
value_array,
|
||||
false);
|
||||
/* o. */
|
||||
ecma_op_object_put (res_ele_p,
|
||||
str_capability,
|
||||
capability_str_p,
|
||||
capability,
|
||||
false);
|
||||
/* p. */
|
||||
ecma_op_object_put (res_ele_p,
|
||||
str_remaining,
|
||||
remaining_str_p,
|
||||
remaining,
|
||||
false);
|
||||
|
||||
@@ -543,14 +528,6 @@ ecma_builtin_promise_do_all (ecma_value_t array, /**< the array for all */
|
||||
ecma_free_value (resolve);
|
||||
ecma_free_value (remaining);
|
||||
ecma_free_value (value_array);
|
||||
ecma_deref_ecma_string (str_already_called);
|
||||
ecma_deref_ecma_string (str_index);
|
||||
ecma_deref_ecma_string (str_value);
|
||||
ecma_deref_ecma_string (str_capability);
|
||||
ecma_deref_ecma_string (str_remaining);
|
||||
ecma_deref_ecma_string (str_resolve);
|
||||
ecma_deref_ecma_string (str_reject);
|
||||
ecma_deref_ecma_string (str_promise);
|
||||
|
||||
JERRY_ASSERT (!ecma_is_value_empty (ret));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user