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:
@@ -103,7 +103,7 @@ ecma_op_create_array_object (const ecma_value_t *arguments_list_p, /**< list of
|
||||
* See also: ecma_object_get_class_name
|
||||
*/
|
||||
|
||||
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_property_t *length_prop_p = ecma_create_named_data_property (obj_p,
|
||||
length_magic_string_p,
|
||||
@@ -157,7 +157,7 @@ ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array o
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
|
||||
|
||||
// 1.
|
||||
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_property_t *len_prop_p = ecma_op_object_get_own_property (obj_p, magic_string_length_p);
|
||||
JERRY_ASSERT (len_prop_p != NULL && ECMA_PROPERTY_GET_TYPE (len_prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA);
|
||||
|
||||
@@ -214,7 +214,7 @@ ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array o
|
||||
if (new_len_uint32 >= old_len_uint32)
|
||||
{
|
||||
// i.
|
||||
magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
magic_string_length_p = ecma_new_ecma_length_string ();
|
||||
ret_value = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&new_len_property_desc,
|
||||
@@ -248,7 +248,7 @@ ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array o
|
||||
}
|
||||
|
||||
// j.
|
||||
magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
magic_string_length_p = ecma_new_ecma_length_string ();
|
||||
ecma_value_t succeeded = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&new_len_property_desc,
|
||||
@@ -329,7 +329,7 @@ ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array o
|
||||
}
|
||||
|
||||
// 3.
|
||||
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 completion = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&new_len_property_desc,
|
||||
@@ -363,7 +363,7 @@ ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array o
|
||||
prop_desc_not_writable.is_writable = false;
|
||||
|
||||
ecma_value_t completion_set_not_writable;
|
||||
magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
magic_string_length_p = ecma_new_ecma_length_string ();
|
||||
completion_set_not_writable = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&prop_desc_not_writable,
|
||||
|
||||
@@ -255,7 +255,7 @@ ecma_op_function_list_lazy_property_names (bool separate_enumerable, /**< true -
|
||||
ecma_string_t *name_p;
|
||||
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 13.2.5) */
|
||||
name_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
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);
|
||||
|
||||
@@ -282,13 +282,7 @@ ecma_op_function_try_lazy_instantiate_property (ecma_object_t *obj_p, /**< the f
|
||||
{
|
||||
JERRY_ASSERT (!ecma_get_object_is_builtin (obj_p));
|
||||
|
||||
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
|
||||
bool is_length_property = ecma_compare_ecma_strings (magic_string_length_p, property_name_p);
|
||||
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
|
||||
if (is_length_property)
|
||||
if (ecma_string_is_length (property_name_p))
|
||||
{
|
||||
/* ECMA-262 v5, 13.2, 14-15 */
|
||||
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
@@ -85,7 +85,7 @@ ecma_op_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function
|
||||
ECMA_PROPERTY_VALUE_PTR (class_prop_p)->value = LIT_MAGIC_STRING_ARGUMENTS_UL;
|
||||
|
||||
// 7.
|
||||
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_value_t completion = ecma_builtin_helper_def_prop (obj_p,
|
||||
length_magic_string_p,
|
||||
ecma_make_uint32_value (arguments_number),
|
||||
|
||||
@@ -245,25 +245,6 @@ ecma_op_general_object_get_property (ecma_object_t *obj_p, /**< the object */
|
||||
}
|
||||
} /* ecma_op_general_object_get_property */
|
||||
|
||||
/**
|
||||
* Checks whether the property name is "length".
|
||||
*
|
||||
* @return true if the property name is length
|
||||
* false otherwise
|
||||
*/
|
||||
static inline bool __attr_always_inline___
|
||||
ecma_op_general_object_property_name_is_length (ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
|
||||
bool property_name_is_length = ecma_compare_ecma_strings (property_name_p,
|
||||
magic_string_length_p);
|
||||
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
|
||||
return property_name_is_length;
|
||||
} /* ecma_op_general_object_property_name_is_length */
|
||||
|
||||
/**
|
||||
* [[Put]] ecma general object's operation
|
||||
*
|
||||
@@ -305,7 +286,7 @@ ecma_op_general_object_put (ecma_object_t *obj_p, /**< the object */
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
|
||||
if (type == ECMA_OBJECT_TYPE_ARGUMENTS
|
||||
|| (type == ECMA_OBJECT_TYPE_ARRAY && ecma_op_general_object_property_name_is_length (property_name_p)))
|
||||
|| (type == ECMA_OBJECT_TYPE_ARRAY && ecma_string_is_length (property_name_p)))
|
||||
{
|
||||
/* These cases cannot be optimized. */
|
||||
ecma_property_descriptor_t value_desc = ecma_make_empty_property_descriptor ();
|
||||
@@ -379,11 +360,12 @@ ecma_op_general_object_put (ecma_object_t *obj_p, /**< the object */
|
||||
/* Since the length of an array is a non-configurable named data
|
||||
* property, the prop_p must be a non-NULL pointer for all arrays. */
|
||||
|
||||
JERRY_ASSERT (!ecma_op_general_object_property_name_is_length (property_name_p));
|
||||
JERRY_ASSERT (!ecma_string_is_length (property_name_p));
|
||||
|
||||
ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
ecma_property_t *len_prop_p = ecma_op_object_get_own_property (obj_p, magic_string_length_p);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
ecma_string_t magic_string_length;
|
||||
ecma_init_ecma_length_string (&magic_string_length);
|
||||
|
||||
ecma_property_t *len_prop_p = ecma_op_object_get_own_property (obj_p, &magic_string_length);
|
||||
|
||||
JERRY_ASSERT (len_prop_p != NULL
|
||||
&& ECMA_PROPERTY_GET_TYPE (len_prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA);
|
||||
|
||||
@@ -1199,7 +1199,7 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
|
||||
ecma_deref_ecma_string (result_prop_str_p);
|
||||
|
||||
/* Set length property of the result array */
|
||||
result_prop_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
|
||||
result_prop_str_p = ecma_new_ecma_length_string ();
|
||||
{
|
||||
ecma_property_descriptor_t array_item_prop_desc = ecma_make_empty_property_descriptor ();
|
||||
array_item_prop_desc.is_value_defined = true;
|
||||
|
||||
@@ -99,7 +99,7 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of
|
||||
ecma_set_internal_property_value (prim_value_prop_p, ecma_make_string_value (prim_prop_str_value_p));
|
||||
|
||||
// 15.5.5.1
|
||||
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_property_t *length_prop_p = ecma_create_named_data_property (obj_p,
|
||||
length_magic_string_p,
|
||||
ECMA_PROPERTY_FIXED);
|
||||
|
||||
Reference in New Issue
Block a user