Skip to content

Improve get-value #1136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions jerry-core/ecma/base/ecma-helpers-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */

Expand Down
1 change: 1 addition & 0 deletions jerry-core/ecma/base/ecma-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
51 changes: 37 additions & 14 deletions jerry-core/vm/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (""));
Expand All @@ -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);
Expand Down