Change string length into a virtual property. (#1395)

Reduces the memory consumption of String objects.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg 2016-10-18 11:11:00 +02:00 committed by GitHub
parent e8428383f1
commit 6af70e5899
2 changed files with 32 additions and 18 deletions

View File

@ -86,6 +86,22 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
{
if (type == ECMA_OBJECT_TYPE_STRING)
{
if (ecma_string_is_length (property_name_p))
{
if (options & ECMA_PROPERTY_GET_VALUE)
{
ecma_value_t *prim_value_p = ecma_get_internal_property (object_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
ecma_string_t *prim_value_str_p = ecma_get_string_from_value (*prim_value_p);
ecma_length_t length = ecma_string_get_length (prim_value_str_p);
property_ref_p->virtual_value = ecma_make_uint32_value (length);
}
return ECMA_PROPERTY_TYPE_VIRTUAL;
}
uint32_t index;
if (ecma_string_get_array_index (property_name_p, &index))
@ -316,6 +332,17 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */
{
if (type == ECMA_OBJECT_TYPE_STRING)
{
if (ecma_string_is_length (property_name_p))
{
ecma_value_t *prim_value_p = ecma_get_internal_property (object_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
ecma_string_t *prim_value_str_p = ecma_get_string_from_value (*prim_value_p);
ecma_length_t length = ecma_string_get_length (prim_value_str_p);
return ecma_make_uint32_value (length);
}
uint32_t index;
if (ecma_string_get_array_index (property_name_p, &index))

View File

@ -49,12 +49,9 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of
ecma_string_t *prim_prop_str_value_p;
ecma_number_t length_value;
if (arguments_list_len == 0)
{
prim_prop_str_value_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING__EMPTY);
length_value = ECMA_NUMBER_ZERO;
}
else
{
@ -70,9 +67,6 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of
JERRY_ASSERT (ecma_is_value_string (to_str_arg_value));
prim_prop_str_value_p = ecma_get_string_from_value (to_str_arg_value);
ecma_length_t string_len = ecma_string_get_length (prim_prop_str_value_p);
length_value = ((ecma_number_t) (uint32_t) string_len);
}
}
@ -98,16 +92,6 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of
ECMA_INTERNAL_PROPERTY_ECMA_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_new_ecma_length_string ();
ecma_property_value_t *length_prop_value_p = ecma_create_named_data_property (obj_p,
length_magic_string_p,
ECMA_PROPERTY_FIXED,
NULL);
ecma_deref_ecma_string (length_magic_string_p);
length_prop_value_p->value = ecma_make_number_value (length_value);
return ecma_make_object_value (obj_p);
} /* ecma_op_create_string_object */
@ -136,8 +120,7 @@ ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p, /**< a String obj
ecma_collection_header_t *for_enumerable_p = main_collection_p;
ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? main_collection_p : non_enum_collection_p;
JERRY_UNUSED (for_non_enumerable_p);
ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
ecma_value_t *prim_value_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
@ -154,6 +137,10 @@ ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p, /**< a String obj
ecma_deref_ecma_string (name_p);
}
ecma_string_t *length_str_p = ecma_new_ecma_length_string ();
ecma_append_to_values_collection (for_non_enumerable_p, ecma_make_string_value (length_str_p), true);
ecma_deref_ecma_string (length_str_p);
} /* ecma_op_string_list_lazy_property_names */
/**