Performance optimizations
* inline some hot function * add 'ecma_copy_value_if_not_object' similer to 'ecma_value_free_if_not_object' * remove unnecessary helpers * improve 'do_number_bitwise_logic' JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -810,28 +811,6 @@ ecma_uint32_to_utf8_string (uint32_t value, /**< value to convert */
|
||||
return bytes_copied;
|
||||
} /* ecma_uint32_to_utf8_string */
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion of UInt32 value to Number value
|
||||
*
|
||||
* @return number - result of conversion.
|
||||
*/
|
||||
ecma_number_t
|
||||
ecma_uint32_to_number (uint32_t value) /**< unsigned 32-bit integer value */
|
||||
{
|
||||
return (ecma_number_t) value;
|
||||
} /* ecma_uint32_to_number */
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion of Int32 value to Number value
|
||||
*
|
||||
* @return number - result of conversion.
|
||||
*/
|
||||
ecma_number_t
|
||||
ecma_int32_to_number (int32_t value) /**< signed 32-bit integer value */
|
||||
{
|
||||
return (ecma_number_t) value;
|
||||
} /* ecma_int32_to_number */
|
||||
|
||||
/**
|
||||
* ECMA-defined conversion of Number value to UInt32 value
|
||||
*
|
||||
@@ -1344,7 +1323,8 @@ ecma_number_to_utf8_string (ecma_number_t num, /**< ecma-number */
|
||||
|
||||
// 5.
|
||||
uint32_t num_uint32 = ecma_number_to_uint32 (num);
|
||||
if (ecma_uint32_to_number (num_uint32) == num)
|
||||
|
||||
if (((ecma_number_t) num_uint32) == num)
|
||||
{
|
||||
size = ecma_uint32_to_utf8_string (num_uint32, dst_p, buffer_size);
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ ecma_number_get_sign_field (ecma_number_t num) /**< ecma-number */
|
||||
fraction is filled with anything but not all zero bits,
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
bool __attr_always_inline___
|
||||
ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
bool is_nan = (num != num);
|
||||
@@ -283,7 +283,7 @@ ecma_number_make_infinity (bool sign) /**< true - for negative Infinity,
|
||||
* @return true - if sign bit of ecma-number is set
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
bool __attr_always_inline___
|
||||
ecma_number_is_negative (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
JERRY_ASSERT (!ecma_number_is_nan (num));
|
||||
|
||||
@@ -238,7 +238,7 @@ ecma_string_t *
|
||||
ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */
|
||||
{
|
||||
uint32_t uint32_num = ecma_number_to_uint32 (num);
|
||||
if (num == ecma_uint32_to_number (uint32_num))
|
||||
if (num == ((ecma_number_t) uint32_num))
|
||||
{
|
||||
return ecma_new_ecma_string_from_uint32 (uint32_num);
|
||||
}
|
||||
@@ -533,7 +533,7 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */
|
||||
{
|
||||
uint32_t uint32_number = str_p->u.uint32_number;
|
||||
|
||||
return ecma_uint32_to_number (uint32_number);
|
||||
return ((ecma_number_t) uint32_number);
|
||||
}
|
||||
|
||||
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
|
||||
@@ -1002,36 +1002,13 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
|
||||
return is_equal;
|
||||
} /* ecma_compare_ecma_strings_longpath */
|
||||
|
||||
/**
|
||||
* Compare ecma-string to ecma-string if they're hashes are equal
|
||||
*
|
||||
* @return true - if strings are equal;
|
||||
* false - may be.
|
||||
*/
|
||||
bool
|
||||
ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *string1_p, /* ecma-string */
|
||||
const ecma_string_t *string2_p) /* ecma-string */
|
||||
{
|
||||
JERRY_ASSERT (string1_p->hash == string2_p->hash);
|
||||
|
||||
if (ECMA_STRING_GET_CONTAINER (string1_p) == ECMA_STRING_GET_CONTAINER (string2_p)
|
||||
&& string1_p->u.common_field == string2_p->u.common_field)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} /* ecma_compare_ecma_strings_equal_hashes */
|
||||
|
||||
/**
|
||||
* Compare ecma-string to ecma-string
|
||||
*
|
||||
* @return true - if strings are equal;
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
bool __attr_always_inline___
|
||||
ecma_compare_ecma_strings (const ecma_string_t *string1_p, /* ecma-string */
|
||||
const ecma_string_t *string2_p) /* ecma-string */
|
||||
{
|
||||
@@ -1042,14 +1019,13 @@ ecma_compare_ecma_strings (const ecma_string_t *string1_p, /* ecma-string */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ecma_compare_ecma_strings_equal_hashes (string1_p, string2_p))
|
||||
if (ECMA_STRING_GET_CONTAINER (string1_p) == ECMA_STRING_GET_CONTAINER (string2_p)
|
||||
&& string1_p->u.common_field == string2_p->u.common_field)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_compare_ecma_strings_longpath (string1_p, string2_p);
|
||||
}
|
||||
|
||||
return ecma_compare_ecma_strings_longpath (string1_p, string2_p);
|
||||
} /* ecma_compare_ecma_strings */
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -397,38 +398,16 @@ ecma_get_value_from_error_value (ecma_value_t value) /**< ecma value */
|
||||
/**
|
||||
* Copy ecma value.
|
||||
*
|
||||
* Note:
|
||||
* Operation algorithm.
|
||||
* switch (valuetype)
|
||||
* case simple:
|
||||
* simply return the value as it was passed;
|
||||
* case number:
|
||||
* copy the number
|
||||
* and return new ecma value
|
||||
* pointing to copy of the number;
|
||||
* case string:
|
||||
* increase reference counter of the string
|
||||
* and return the value as it was passed.
|
||||
* case object;
|
||||
* increase reference counter of the object if do_ref_if_object is true
|
||||
* and return the value as it was passed.
|
||||
*
|
||||
* @return See note.
|
||||
* @return copy of the given value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_copy_value (ecma_value_t value, /**< ecma value */
|
||||
bool do_ref_if_object) /**< if the value is object value,
|
||||
increment reference counter of the object */
|
||||
ecma_copy_value (ecma_value_t value) /**< value description */
|
||||
{
|
||||
ecma_value_t value_copy = 0;
|
||||
|
||||
switch (ecma_get_value_type_field (value))
|
||||
{
|
||||
case ECMA_TYPE_SIMPLE:
|
||||
{
|
||||
value_copy = value;
|
||||
|
||||
break;
|
||||
return value;
|
||||
}
|
||||
case ECMA_TYPE_NUMBER:
|
||||
{
|
||||
@@ -437,38 +416,38 @@ ecma_copy_value (ecma_value_t value, /**< ecma value */
|
||||
ecma_number_t *number_copy_p = ecma_alloc_number ();
|
||||
*number_copy_p = *num_p;
|
||||
|
||||
value_copy = ecma_make_number_value (number_copy_p);
|
||||
|
||||
break;
|
||||
return ecma_make_number_value (number_copy_p);
|
||||
}
|
||||
case ECMA_TYPE_STRING:
|
||||
{
|
||||
ecma_string_t *string_p = ecma_get_string_from_value (value);
|
||||
|
||||
string_p = ecma_copy_or_ref_ecma_string (string_p);
|
||||
|
||||
value_copy = ecma_make_string_value (string_p);
|
||||
|
||||
break;
|
||||
return ecma_make_string_value (ecma_copy_or_ref_ecma_string (ecma_get_string_from_value (value)));
|
||||
}
|
||||
case ECMA_TYPE_OBJECT:
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
if (do_ref_if_object)
|
||||
{
|
||||
ecma_ref_object (obj_p);
|
||||
}
|
||||
|
||||
value_copy = value;
|
||||
|
||||
break;
|
||||
ecma_ref_object (ecma_get_object_from_value (value));
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return value_copy;
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* ecma_copy_value */
|
||||
|
||||
/**
|
||||
* Copy the ecma value if not an object
|
||||
*
|
||||
* @return copy of the given value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_copy_value_if_not_object (ecma_value_t value) /**< value description */
|
||||
{
|
||||
if (ecma_get_value_type_field (value) != ECMA_TYPE_OBJECT)
|
||||
{
|
||||
return ecma_copy_value (value);
|
||||
}
|
||||
|
||||
return value;
|
||||
} /* ecma_copy_value_if_not_object */
|
||||
|
||||
/**
|
||||
* Free the ecma value
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -67,7 +68,14 @@ ecma_new_values_collection (const ecma_value_t values_buffer[], /**< ecma values
|
||||
|
||||
JERRY_ASSERT (cur_value_buf_iter_p + 1 <= cur_value_buf_end_p);
|
||||
|
||||
*cur_value_buf_iter_p++ = ecma_copy_value (values_buffer[value_index], do_ref_if_object);
|
||||
if (do_ref_if_object)
|
||||
{
|
||||
*cur_value_buf_iter_p++ = ecma_copy_value (values_buffer[value_index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
*cur_value_buf_iter_p++ = ecma_copy_value_if_not_object (values_buffer[value_index]);
|
||||
}
|
||||
}
|
||||
|
||||
*next_chunk_cp_p = ECMA_NULL_POINTER;
|
||||
@@ -189,7 +197,14 @@ ecma_append_to_values_collection (ecma_collection_header_t *header_p, /**< colle
|
||||
|
||||
JERRY_ASSERT ((uint8_t *) (values_p + pos_of_new_value_in_chunk + 1) <= (uint8_t *) (chunk_p + 1));
|
||||
|
||||
values_p[pos_of_new_value_in_chunk] = ecma_copy_value (v, do_ref_if_object);
|
||||
if (do_ref_if_object)
|
||||
{
|
||||
values_p[pos_of_new_value_in_chunk] = ecma_copy_value (v);
|
||||
}
|
||||
else
|
||||
{
|
||||
values_p[pos_of_new_value_in_chunk] = ecma_copy_value_if_not_object (v);
|
||||
}
|
||||
} /* ecma_append_to_values_collection */
|
||||
|
||||
/**
|
||||
|
||||
@@ -1001,7 +1001,7 @@ ecma_named_data_property_assign_value (ecma_object_t *obj_p, /**< object */
|
||||
ecma_value_t v = ecma_get_named_data_property_value (prop_p);
|
||||
ecma_free_value_if_not_object (v);
|
||||
|
||||
ecma_set_named_data_property_value (prop_p, ecma_copy_value (value, false));
|
||||
ecma_set_named_data_property_value (prop_p, ecma_copy_value_if_not_object (value));
|
||||
}
|
||||
} /* ecma_named_data_property_assign_value */
|
||||
|
||||
@@ -1283,7 +1283,7 @@ ecma_get_property_descriptor_from_property (ecma_property_t *prop_p) /**< proper
|
||||
|
||||
if (prop_p->flags & ECMA_PROPERTY_FLAG_NAMEDDATA)
|
||||
{
|
||||
prop_desc.value = ecma_copy_value (ecma_get_named_data_property_value (prop_p), true);
|
||||
prop_desc.value = ecma_copy_value (ecma_get_named_data_property_value (prop_p));
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.is_writable = ecma_is_property_writable (prop_p);
|
||||
prop_desc.is_writable_defined = true;
|
||||
|
||||
@@ -80,7 +80,8 @@ extern ecma_number_t *ecma_get_number_from_value (ecma_value_t) __attr_pure___;
|
||||
extern ecma_string_t *ecma_get_string_from_value (ecma_value_t) __attr_pure___;
|
||||
extern ecma_object_t *ecma_get_object_from_value (ecma_value_t) __attr_pure___;
|
||||
extern ecma_value_t ecma_get_value_from_error_value (ecma_value_t) __attr_pure___;
|
||||
extern ecma_value_t ecma_copy_value (ecma_value_t, bool);
|
||||
extern ecma_value_t ecma_copy_value (ecma_value_t);
|
||||
extern ecma_value_t ecma_copy_value_if_not_object (ecma_value_t);
|
||||
extern void ecma_free_value (ecma_value_t);
|
||||
extern void ecma_free_value_if_not_object (ecma_value_t);
|
||||
|
||||
@@ -243,8 +244,6 @@ extern ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *, lit_ut
|
||||
extern lit_utf8_size_t ecma_uint32_to_utf8_string (uint32_t, lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
extern uint32_t ecma_number_to_uint32 (ecma_number_t);
|
||||
extern int32_t ecma_number_to_int32 (ecma_number_t);
|
||||
extern ecma_number_t ecma_int32_to_number (int32_t);
|
||||
extern ecma_number_t ecma_uint32_to_number (uint32_t);
|
||||
extern lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t, lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
|
||||
#endif /* !ECMA_HELPERS_H */
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -256,7 +257,10 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
|
||||
ecma_string_t *entry_prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
ecma_lcache_hash_table[hash_key][i].prop_name_cp);
|
||||
|
||||
if (ecma_compare_ecma_strings_equal_hashes (prop_name_p, entry_prop_name_p))
|
||||
JERRY_ASSERT (prop_name_p->hash == entry_prop_name_p->hash);
|
||||
|
||||
if (ECMA_STRING_GET_CONTAINER (prop_name_p) == ECMA_STRING_GET_CONTAINER (entry_prop_name_p)
|
||||
&& prop_name_p->u.common_field == entry_prop_name_p->u.common_field)
|
||||
{
|
||||
ecma_property_t *prop_p = ECMA_GET_POINTER (ecma_property_t, ecma_lcache_hash_table[hash_key][i].prop_cp);
|
||||
JERRY_ASSERT (prop_p == NULL || ecma_is_property_lcached (prop_p));
|
||||
|
||||
Reference in New Issue
Block a user