Optimize the copying/freeing of ecma values (#4602)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
@@ -51,7 +51,7 @@ JERRY_STATIC_ASSERT (sizeof (ecma_extended_object_t) - sizeof (ecma_object_t) <=
|
||||
*
|
||||
* @return pointer to allocated memory
|
||||
*/
|
||||
ecma_number_t *
|
||||
extern inline ecma_number_t * JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_alloc_number (void)
|
||||
{
|
||||
return (ecma_number_t *) jmem_pools_alloc (sizeof (ecma_number_t));
|
||||
@@ -60,7 +60,7 @@ ecma_alloc_number (void)
|
||||
/**
|
||||
* Dealloc memory from an ecma-number
|
||||
*/
|
||||
void
|
||||
extern inline void JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_dealloc_number (ecma_number_t *number_p) /**< number to be freed */
|
||||
{
|
||||
jmem_pools_free ((uint8_t *) number_p, sizeof (ecma_number_t));
|
||||
|
||||
@@ -127,8 +127,8 @@ ecma_init_gc_info (ecma_object_t *object_p) /**< object */
|
||||
/**
|
||||
* Increase reference counter of an object
|
||||
*/
|
||||
void
|
||||
ecma_ref_object (ecma_object_t *object_p) /**< object */
|
||||
extern inline void JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_ref_object_inline (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
if (JERRY_LIKELY (object_p->type_flags_refs < ECMA_OBJECT_MAX_REF))
|
||||
{
|
||||
@@ -138,6 +138,15 @@ ecma_ref_object (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
jerry_fatal (ERR_REF_COUNT_LIMIT);
|
||||
}
|
||||
} /* ecma_ref_object_inline */
|
||||
|
||||
/**
|
||||
* Increase reference counter of an object
|
||||
*/
|
||||
void
|
||||
ecma_ref_object (ecma_object_t *object_p) /**< object */
|
||||
{
|
||||
ecma_ref_object_inline (object_p);
|
||||
} /* ecma_ref_object */
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
void ecma_init_gc_info (ecma_object_t *object_p);
|
||||
void ecma_ref_object (ecma_object_t *object_p);
|
||||
void ecma_ref_object_inline (ecma_object_t *object_p);
|
||||
void ecma_deref_object (ecma_object_t *object_p);
|
||||
void ecma_gc_free_properties (ecma_object_t *object_p);
|
||||
void ecma_gc_run (void);
|
||||
|
||||
@@ -843,17 +843,13 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
|
||||
} /* ecma_concat_ecma_strings */
|
||||
|
||||
/**
|
||||
* Increase reference counter of ecma-string.
|
||||
* Increase reference counter of non-direct ecma-string.
|
||||
*/
|
||||
void
|
||||
ecma_ref_ecma_string (ecma_string_t *string_p) /**< string descriptor */
|
||||
extern inline void JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_ref_ecma_string_non_direct (ecma_string_t *string_p) /**< string descriptor */
|
||||
{
|
||||
JERRY_ASSERT (string_p != NULL);
|
||||
|
||||
if (ECMA_IS_DIRECT_STRING (string_p))
|
||||
{
|
||||
return;
|
||||
}
|
||||
JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string_p));
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
if (ECMA_STRING_IS_STATIC (string_p))
|
||||
@@ -873,14 +869,13 @@ ecma_ref_ecma_string (ecma_string_t *string_p) /**< string descriptor */
|
||||
{
|
||||
jerry_fatal (ERR_REF_COUNT_LIMIT);
|
||||
}
|
||||
} /* ecma_ref_ecma_string */
|
||||
} /* ecma_ref_ecma_string_non_direct */
|
||||
|
||||
/**
|
||||
* Decrease reference counter and deallocate ecma-string
|
||||
* if the counter becomes zero.
|
||||
* Increase reference counter of ecma-string.
|
||||
*/
|
||||
void
|
||||
ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
|
||||
ecma_ref_ecma_string (ecma_string_t *string_p) /**< string descriptor */
|
||||
{
|
||||
JERRY_ASSERT (string_p != NULL);
|
||||
|
||||
@@ -889,6 +884,18 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
|
||||
return;
|
||||
}
|
||||
|
||||
ecma_ref_ecma_string_non_direct (string_p);
|
||||
} /* ecma_ref_ecma_string */
|
||||
|
||||
/**
|
||||
* Decrease reference counter and deallocate a non-direct ecma-string
|
||||
* if the counter becomes zero.
|
||||
*/
|
||||
extern inline void JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_deref_ecma_string_non_direct (ecma_string_t *string_p) /**< ecma-string */
|
||||
{
|
||||
JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string_p));
|
||||
|
||||
#ifdef JERRY_NDEBUG
|
||||
if (ECMA_STRING_IS_STATIC (string_p))
|
||||
{
|
||||
@@ -907,6 +914,23 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
|
||||
}
|
||||
|
||||
ecma_destroy_ecma_string (string_p);
|
||||
} /* ecma_deref_ecma_string_non_direct */
|
||||
|
||||
/**
|
||||
* Decrease reference counter and deallocate ecma-string
|
||||
* if the counter becomes zero.
|
||||
*/
|
||||
void
|
||||
ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
|
||||
{
|
||||
JERRY_ASSERT (string_p != NULL);
|
||||
|
||||
if (ECMA_IS_DIRECT_STRING (string_p))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string_non_direct (string_p);
|
||||
} /* ecma_deref_ecma_string */
|
||||
|
||||
/**
|
||||
|
||||
@@ -536,7 +536,7 @@ ecma_create_float_number (ecma_number_t ecma_number) /**< value of the float num
|
||||
*
|
||||
* @return ecma-value
|
||||
*/
|
||||
ecma_value_t
|
||||
extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_make_float_value (ecma_number_t *ecma_num_p) /**< pointer to the float number */
|
||||
{
|
||||
return ecma_pointer_to_ecma_value (ecma_num_p) | ECMA_TYPE_FLOAT;
|
||||
@@ -899,21 +899,21 @@ ecma_copy_value (ecma_value_t value) /**< value description */
|
||||
case ECMA_TYPE_FLOAT:
|
||||
{
|
||||
ecma_number_t *num_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (value);
|
||||
ecma_number_t *new_num_p = ecma_alloc_number ();
|
||||
|
||||
return ecma_create_float_number (*num_p);
|
||||
}
|
||||
case ECMA_TYPE_STRING:
|
||||
{
|
||||
ecma_ref_ecma_string (ecma_get_string_from_value (value));
|
||||
return value;
|
||||
*new_num_p = *num_p;
|
||||
|
||||
return ecma_make_float_value (new_num_p);
|
||||
}
|
||||
#if JERRY_ESNEXT
|
||||
case ECMA_TYPE_SYMBOL:
|
||||
#endif /* JERRY_ESNEXT */
|
||||
case ECMA_TYPE_STRING:
|
||||
{
|
||||
ecma_ref_ecma_string (ecma_get_symbol_from_value (value));
|
||||
ecma_string_t *string_p = (ecma_string_t *) ecma_get_pointer_from_ecma_value (value);
|
||||
ecma_ref_ecma_string_non_direct (string_p);
|
||||
return value;
|
||||
}
|
||||
#endif /* JERRY_ESNEXT */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
case ECMA_TYPE_BIGINT:
|
||||
{
|
||||
@@ -926,7 +926,7 @@ ecma_copy_value (ecma_value_t value) /**< value description */
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
case ECMA_TYPE_OBJECT:
|
||||
{
|
||||
ecma_ref_object (ecma_get_object_from_value (value));
|
||||
ecma_ref_object_inline (ecma_get_object_from_value (value));
|
||||
return value;
|
||||
}
|
||||
default:
|
||||
@@ -1131,26 +1131,20 @@ ecma_free_value (ecma_value_t value) /**< value description */
|
||||
ecma_dealloc_number (number_p);
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_TYPE_STRING:
|
||||
{
|
||||
ecma_string_t *string_p = ecma_get_string_from_value (value);
|
||||
ecma_deref_ecma_string (string_p);
|
||||
break;
|
||||
}
|
||||
#if JERRY_ESNEXT
|
||||
case ECMA_TYPE_SYMBOL:
|
||||
#endif /* JERRY_ESNEXT */
|
||||
case ECMA_TYPE_STRING:
|
||||
{
|
||||
ecma_deref_ecma_string (ecma_get_symbol_from_value (value));
|
||||
ecma_string_t *string_p = (ecma_string_t *) ecma_get_pointer_from_ecma_value (value);
|
||||
ecma_deref_ecma_string_non_direct (string_p);
|
||||
break;
|
||||
}
|
||||
#endif /* JERRY_ESNEXT */
|
||||
case ECMA_TYPE_OBJECT:
|
||||
{
|
||||
ecma_deref_object (ecma_get_object_from_value (value));
|
||||
break;
|
||||
}
|
||||
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
case ECMA_TYPE_BIGINT:
|
||||
{
|
||||
@@ -1158,10 +1152,10 @@ ecma_free_value (ecma_value_t value) /**< value description */
|
||||
{
|
||||
ecma_deref_bigint (ecma_get_extended_primitive_from_value (value));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT
|
||||
|
||||
@@ -321,7 +321,9 @@ ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_p,
|
||||
lit_utf8_size_t cesu8_string2_length);
|
||||
ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p);
|
||||
void ecma_ref_ecma_string (ecma_string_t *string_p);
|
||||
void ecma_ref_ecma_string_non_direct (ecma_string_t *string_p);
|
||||
void ecma_deref_ecma_string (ecma_string_t *string_p);
|
||||
void ecma_deref_ecma_string_non_direct (ecma_string_t *string_p);
|
||||
void ecma_destroy_ecma_string (ecma_string_t *string_p);
|
||||
ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
|
||||
uint32_t ecma_string_get_array_index (const ecma_string_t *str_p);
|
||||
|
||||
Reference in New Issue
Block a user