Improve the construction of "length" built-in strings.

The "length" property name is the most frequently used built-in string
and also frequently created by various hot-paths. New functions are
added to improve the speed of the "length" string creation.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2016-07-13 04:50:47 -07:00
parent b4bba2ef70
commit 6f1ce8d6bb
17 changed files with 131 additions and 84 deletions
@@ -60,7 +60,7 @@ ecma_builtin_array_prototype_helper_set_length (ecma_object_t *object, /**< obje
ecma_number_t length) /**< new length */
{
ecma_value_t ret_value;
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
ecma_value_t length_value = ecma_make_number_value (length);
ret_value = ecma_op_object_put (object,
@@ -145,7 +145,7 @@ ecma_builtin_array_prototype_object_to_locale_string (const ecma_value_t this_ar
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
ecma_string_t *length_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_magic_string_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (length_value,
@@ -369,7 +369,7 @@ ecma_builtin_array_prototype_join (const ecma_value_t this_arg, /**< this argume
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
ecma_string_t *length_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_magic_string_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (length_value,
@@ -474,7 +474,7 @@ ecma_builtin_array_prototype_object_pop (ecma_value_t this_arg) /**< this argume
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -555,7 +555,7 @@ ecma_builtin_array_prototype_object_push (ecma_value_t this_arg, /**< this argum
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this_value);
/* 2. */
ecma_string_t *length_str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_str_p = ecma_new_ecma_length_string ();
ECMA_TRY_CATCH (length_value, ecma_op_object_get (obj_p, length_str_p), ret_value);
@@ -624,7 +624,7 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg) /**< this ar
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -720,7 +720,7 @@ ecma_builtin_array_prototype_object_shift (ecma_value_t this_arg) /**< this argu
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -835,7 +835,7 @@ ecma_builtin_array_prototype_object_slice (ecma_value_t this_arg, /**< 'this' ar
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *length_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_magic_string_p = ecma_new_ecma_length_string ();
ECMA_TRY_CATCH (len_value,
ecma_op_object_get (obj_p, length_magic_string_p),
@@ -1205,7 +1205,7 @@ ecma_builtin_array_prototype_object_sort (ecma_value_t this_arg, /**< this argum
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
ECMA_TRY_CATCH (len_value,
ecma_op_object_get (obj_p, magic_string_length_p),
@@ -1359,7 +1359,7 @@ ecma_builtin_array_prototype_object_splice (ecma_value_t this_arg, /**< this arg
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
/* 3. */
ecma_string_t *length_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_magic_string_p = ecma_new_ecma_length_string ();
ECMA_TRY_CATCH (len_value,
ecma_op_object_get (obj_p, length_magic_string_p),
@@ -1646,7 +1646,7 @@ ecma_builtin_array_prototype_object_unshift (ecma_value_t this_arg, /**< this ar
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -1742,7 +1742,7 @@ ecma_builtin_array_prototype_object_index_of (ecma_value_t this_arg, /**< this a
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -1838,7 +1838,7 @@ ecma_builtin_array_prototype_object_last_index_of (ecma_value_t this_arg, /**< t
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -1983,7 +1983,7 @@ ecma_builtin_array_prototype_object_every (ecma_value_t this_arg, /**< this argu
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -2081,7 +2081,7 @@ ecma_builtin_array_prototype_object_some (ecma_value_t this_arg, /**< this argum
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -2178,7 +2178,7 @@ ecma_builtin_array_prototype_object_for_each (ecma_value_t this_arg, /**< this a
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -2270,7 +2270,7 @@ ecma_builtin_array_prototype_object_map (ecma_value_t this_arg, /**< this argume
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -2380,7 +2380,7 @@ ecma_builtin_array_prototype_object_filter (ecma_value_t this_arg, /**< this arg
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -2501,7 +2501,7 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -2643,7 +2643,7 @@ ecma_builtin_array_prototype_object_reduce_right (ecma_value_t this_arg, /**< th
ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 2. */
ECMA_TRY_CATCH (len_value,
@@ -110,7 +110,7 @@ ecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this a
else
{
ecma_object_t *obj_p = ecma_get_object_from_value (arg2);
ecma_string_t *length_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_magic_string_p = ecma_new_ecma_length_string ();
/* 4. */
ECMA_TRY_CATCH (length_value,
@@ -286,7 +286,7 @@ ecma_builtin_function_prototype_object_bind (ecma_value_t this_arg, /**< this ar
/* 16. */
ecma_number_t length = ECMA_NUMBER_ZERO;
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 15. */
if (ecma_object_get_class_name (this_arg_obj_p) == LIT_MAGIC_STRING_FUNCTION_UL)
@@ -335,7 +335,7 @@ ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, /**< array */
if (ecma_is_value_object (value)
&& (ecma_object_get_class_name (ecma_get_object_from_value (value)) == LIT_MAGIC_STRING_ARRAY_UL))
{
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
/* 5.b.ii */
ECMA_TRY_CATCH (arg_len_value,
ecma_op_object_get (ecma_get_object_from_value (value),
@@ -825,7 +825,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
/* 4.b */
else if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_ARRAY_UL)
{
ecma_string_t *length_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_str_p = ecma_new_ecma_length_string ();
ECMA_TRY_CATCH (array_length,
ecma_op_object_get (obj_p, length_str_p),
@@ -1624,7 +1624,7 @@ ecma_builtin_json_array (ecma_object_t *obj_p, /**< the array object*/
/* 5. */
ecma_collection_header_t *partial_p = ecma_new_values_collection (NULL, 0, true);
ecma_string_t *length_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_str_p = ecma_new_ecma_length_string ();
/* 6. */
ECMA_TRY_CATCH (array_length,
@@ -774,7 +774,7 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se
ecma_value_t match_value) /**< returned match value */
{
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_string_t *length_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *length_string_p = ecma_new_ecma_length_string ();
ecma_object_t *match_object_p = ecma_get_object_from_value (match_value);
ECMA_TRY_CATCH (match_length_value,
@@ -1818,7 +1818,7 @@ ecma_builtin_string_prototype_object_split (ecma_value_t this_arg, /**< this arg
/* 13.c.iii.5 */
start_pos = end_pos + match_str_length;
ecma_string_t *magic_length_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *magic_length_str_p = ecma_new_ecma_length_string ();
ECMA_TRY_CATCH (array_length_val,
ecma_op_object_get (match_array_obj_p, magic_length_str_p),
@@ -135,6 +135,22 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
/** Initializing [[PrimitiveValue]] properties of built-in prototype objects */
switch (obj_builtin_id)
{
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
case ECMA_BUILTIN_ID_ARRAY_PROTOTYPE:
{
ecma_string_t *length_str_p = ecma_new_ecma_length_string ();
ecma_property_t *length_prop_p = ecma_create_named_data_property (obj_p,
length_str_p,
ECMA_PROPERTY_FLAG_WRITABLE);
ecma_set_named_data_property_value (length_prop_p, ecma_make_integer_value (0));
ecma_deref_ecma_string (length_str_p);
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
case ECMA_BUILTIN_ID_STRING_PROTOTYPE:
{
@@ -352,13 +368,7 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
&& ecma_builtin_function_is_routine (object_p))
{
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
bool is_length_property = ecma_compare_ecma_strings (string_p, magic_string_length_p);
ecma_deref_ecma_string (magic_string_length_p);
if (is_length_property)
if (ecma_string_is_length (string_p))
{
/*
* Lazy instantiation of 'length' property
@@ -589,7 +599,7 @@ ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in
ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
ecma_string_t *name_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
ecma_string_t *name_p = ecma_new_ecma_length_string ();
ecma_append_to_values_collection (for_non_enumerable_p, ecma_make_string_value (name_p), true);
ecma_deref_ecma_string (name_p);
}