ecma_ref_ecma_string -> ecma_copy_or_ref_ecma_string: copying ecma-string when the string's reference counter reaches maximum value.

This commit is contained in:
Ruben Ayrapetyan
2014-10-13 18:59:07 +04:00
parent 9a15286aad
commit 6430a104b3
8 changed files with 42 additions and 17 deletions
+29 -7
View File
@@ -265,8 +265,8 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
string_desc_p->length = (ecma_length_t) length;
}
ecma_ref_ecma_string (string1_p);
ecma_ref_ecma_string (string2_p);
string1_p = ecma_copy_or_ref_ecma_string (string1_p);
string2_p = ecma_copy_or_ref_ecma_string (string2_p);
ECMA_SET_NON_NULL_POINTER (string_desc_p->u.concatenation.string1_cp, string1_p);
ECMA_SET_NON_NULL_POINTER (string_desc_p->u.concatenation.string2_cp, string2_p);
@@ -278,18 +278,40 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
* Increase reference counter of ecma-string.
*
* @return pointer to same ecma-string descriptor with increased reference counter
* or the ecma-string's copy with reference counter set to 1
*/
void
ecma_ref_ecma_string (ecma_string_t *string_desc_p) /**< string descriptor */
ecma_string_t*
ecma_copy_or_ref_ecma_string (ecma_string_t *string_desc_p) /**< string descriptor */
{
JERRY_ASSERT (string_desc_p != NULL);
JERRY_ASSERT (string_desc_p->refs > 0);
string_desc_p->refs++;
/* Check for overflow */
JERRY_ASSERT (string_desc_p->refs > 0);
} /* ecma_ref_ecma_string */
if (unlikely (string_desc_p->refs == 0))
{
string_desc_p->refs--;
if (string_desc_p->container == ECMA_STRING_CONTAINER_CHARS_IN_DESC
|| string_desc_p->container == ECMA_STRING_CONTAINER_LIT_TABLE
|| string_desc_p->container == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
{
ecma_string_t *new_str_p = ecma_alloc_string ();
*new_str_p = *string_desc_p;
new_str_p->refs = 1;
return new_str_p;
}
else
{
JERRY_UNIMPLEMENTED ();
}
}
return string_desc_p;
} /* ecma_copy_or_ref_ecma_string */
/**
* Decrease reference counter and deallocate ecma-string if
+6 -2
View File
@@ -212,9 +212,13 @@ ecma_copy_value (const ecma_value_t value, /**< ecma-value */
ecma_string_t *string_p = ECMA_GET_POINTER(value.value);
JERRY_ASSERT(string_p != NULL);
ecma_ref_ecma_string (string_p);
string_p = ecma_copy_or_ref_ecma_string (string_p);
value_copy = value;
value_copy = (ecma_value_t)
{
.value_type = ECMA_TYPE_STRING
};
ECMA_SET_NON_NULL_POINTER(value_copy.value, string_p);
break;
}
+2 -2
View File
@@ -454,7 +454,7 @@ ecma_create_named_data_property (ecma_object_t *obj_p, /**< object */
prop_p->type = ECMA_PROPERTY_NAMEDDATA;
ecma_ref_ecma_string (name_p);
name_p = ecma_copy_or_ref_ecma_string (name_p);
ECMA_SET_NON_NULL_POINTER(prop_p->u.named_data_property.name_p, name_p);
prop_p->u.named_data_property.writable = writable;
@@ -490,7 +490,7 @@ ecma_create_named_accessor_property (ecma_object_t *obj_p, /**< object */
prop_p->type = ECMA_PROPERTY_NAMEDACCESSOR;
ecma_ref_ecma_string (name_p);
name_p = ecma_copy_or_ref_ecma_string (name_p);
ECMA_SET_NON_NULL_POINTER(prop_p->u.named_accessor_property.name_p, name_p);
ECMA_SET_POINTER(prop_p->u.named_accessor_property.get_p, get_p);
+1 -1
View File
@@ -102,7 +102,7 @@ extern ecma_string_t* ecma_new_ecma_string_from_number (ecma_number_t number);
extern ecma_string_t* ecma_new_ecma_string_from_lit_index (literal_index_t lit_index);
extern ecma_string_t* ecma_new_ecma_string_from_magic_string_id (ecma_magic_string_id_t id);
extern ecma_string_t* ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p);
extern void ecma_ref_ecma_string (ecma_string_t *string_desc_p);
extern ecma_string_t* ecma_copy_or_ref_ecma_string (ecma_string_t *string_desc_p);
extern void ecma_deref_ecma_string (ecma_string_t *string_p);
extern ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
extern ssize_t ecma_string_to_zt_string (const ecma_string_t *string_desc_p,