mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Improve get-value.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
parent
ce905487a0
commit
1eeed7e07e
@ -222,12 +222,11 @@ ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit) /**< code unit */
|
||||
} /* ecma_new_ecma_string_from_code_unit */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with ecma-number
|
||||
*
|
||||
* @return pointer to ecma-string descriptor
|
||||
* Initialize an ecma-string with an ecma-number
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< UInt32-represented ecma-number */
|
||||
inline void __attr_always_inline___
|
||||
ecma_init_ecma_string_from_uint32 (ecma_string_t *string_desc_p, /**< ecma-string */
|
||||
uint32_t uint32_number) /**< uint32 value of the string */
|
||||
{
|
||||
lit_utf8_byte_t byte_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32];
|
||||
lit_utf8_byte_t *buf_p = byte_buf + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32;
|
||||
@ -245,13 +244,24 @@ ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< UInt32-represente
|
||||
|
||||
lit_utf8_size_t size = (lit_utf8_size_t) (byte_buf + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 - buf_p);
|
||||
|
||||
ecma_string_t *string_desc_p = ecma_alloc_string ();
|
||||
string_desc_p->refs_and_container = ECMA_STRING_CONTAINER_UINT32_IN_DESC | ECMA_STRING_REF_ONE;
|
||||
string_desc_p->hash = lit_utf8_string_calc_hash (buf_p, size);
|
||||
|
||||
string_desc_p->u.common_field = 0;
|
||||
string_desc_p->u.uint32_number = uint32_number;
|
||||
} /* ecma_init_ecma_string_from_uint32 */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with ecma-number
|
||||
*
|
||||
* @return pointer to ecma-string descriptor
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< uint32 value of the string */
|
||||
{
|
||||
ecma_string_t *string_desc_p = ecma_alloc_string ();
|
||||
|
||||
ecma_init_ecma_string_from_uint32 (string_desc_p, uint32_number);
|
||||
return string_desc_p;
|
||||
} /* ecma_new_ecma_string_from_uint32 */
|
||||
|
||||
|
||||
@ -179,6 +179,7 @@ extern lit_utf8_size_t __attr_return_value_should_be_checked___
|
||||
ecma_string_copy_to_utf8_buffer (const ecma_string_t *, lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
extern void ecma_string_to_utf8_bytes (const ecma_string_t *, lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
extern const lit_utf8_byte_t *ecma_string_raw_chars (const ecma_string_t *, lit_utf8_size_t *, bool *);
|
||||
extern void ecma_init_ecma_string_from_uint32 (ecma_string_t *, uint32_t);
|
||||
|
||||
extern bool ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *, const ecma_string_t *);
|
||||
extern bool ecma_compare_ecma_strings (const ecma_string_t *, const ecma_string_t *);
|
||||
|
||||
@ -69,6 +69,43 @@ static ecma_value_t
|
||||
vm_op_get_value (ecma_value_t object, /**< base object */
|
||||
ecma_value_t property) /**< property name */
|
||||
{
|
||||
if (ecma_is_value_object (object))
|
||||
{
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (object);
|
||||
ecma_string_t *property_name_p = NULL;
|
||||
ecma_string_t uint32_string;
|
||||
|
||||
if (ecma_is_value_integer_number (property))
|
||||
{
|
||||
ecma_integer_value_t int_value = ecma_get_integer_from_value (property);
|
||||
|
||||
if (int_value >= 0)
|
||||
{
|
||||
/* Statically allocated string for searching. */
|
||||
ecma_init_ecma_string_from_uint32 (&uint32_string, (uint32_t) int_value);
|
||||
property_name_p = &uint32_string;
|
||||
}
|
||||
}
|
||||
else if (ecma_is_value_string (property))
|
||||
{
|
||||
property_name_p = ecma_get_string_from_value (property);
|
||||
}
|
||||
|
||||
if (property_name_p != NULL)
|
||||
{
|
||||
ecma_property_t *property_p = ecma_lcache_lookup (object_p, property_name_p);
|
||||
|
||||
if (property_p != NULL &&
|
||||
ECMA_PROPERTY_GET_TYPE (property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA)
|
||||
{
|
||||
return ecma_fast_copy_value (ecma_get_named_data_property_value (property_p));
|
||||
}
|
||||
|
||||
/* There is no need to free the name. */
|
||||
return ecma_op_get_value_object_base (object, property_name_p);
|
||||
}
|
||||
}
|
||||
|
||||
if (unlikely (ecma_is_value_undefined (object) || ecma_is_value_null (object)))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
@ -83,20 +120,6 @@ vm_op_get_value (ecma_value_t object, /**< base object */
|
||||
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (prop_to_string_result);
|
||||
|
||||
if (ecma_is_value_object (object))
|
||||
{
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (object);
|
||||
|
||||
ecma_property_t *property_p = ecma_lcache_lookup (object_p, property_name_p);
|
||||
|
||||
if (property_p != NULL &&
|
||||
ECMA_PROPERTY_GET_TYPE (property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA)
|
||||
{
|
||||
ecma_deref_ecma_string (property_name_p);
|
||||
return ecma_fast_copy_value (ecma_get_named_data_property_value (property_p));
|
||||
}
|
||||
}
|
||||
|
||||
ecma_value_t get_value_result = ecma_op_get_value_object_base (object, property_name_p);
|
||||
|
||||
ecma_deref_ecma_string (property_name_p);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user