Skip to content

Commit 6a48d45

Browse files
committed
Improve get-value.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent 495b24e commit 6a48d45

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

jerry-core/ecma/base/ecma-helpers-string.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,11 @@ ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit) /**< code unit */
222222
} /* ecma_new_ecma_string_from_code_unit */
223223

224224
/**
225-
* Allocate new ecma-string and fill it with ecma-number
226-
*
227-
* @return pointer to ecma-string descriptor
225+
* Initialize an ecma-string with an ecma-number
228226
*/
229-
ecma_string_t *
230-
ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< UInt32-represented ecma-number */
227+
inline void __attr_always_inline___
228+
ecma_init_ecma_string_from_uint32 (ecma_string_t *string_desc_p, /**< ecma-string */
229+
uint32_t uint32_number) /**< uint32 value of the string */
231230
{
232231
lit_utf8_byte_t byte_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32];
233232
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
245244

246245
lit_utf8_size_t size = (lit_utf8_size_t) (byte_buf + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 - buf_p);
247246

248-
ecma_string_t *string_desc_p = ecma_alloc_string ();
249247
string_desc_p->refs_and_container = ECMA_STRING_CONTAINER_UINT32_IN_DESC | ECMA_STRING_REF_ONE;
250248
string_desc_p->hash = lit_utf8_string_calc_hash (buf_p, size);
251249

252250
string_desc_p->u.common_field = 0;
253251
string_desc_p->u.uint32_number = uint32_number;
252+
} /* ecma_init_ecma_string_from_uint32 */
253+
254+
/**
255+
* Allocate new ecma-string and fill it with ecma-number
256+
*
257+
* @return pointer to ecma-string descriptor
258+
*/
259+
ecma_string_t *
260+
ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< uint32 value of the string */
261+
{
262+
ecma_string_t *string_desc_p = ecma_alloc_string ();
254263

264+
ecma_init_ecma_string_from_uint32 (string_desc_p, uint32_number);
255265
return string_desc_p;
256266
} /* ecma_new_ecma_string_from_uint32 */
257267

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ extern bool ecma_string_get_array_index (const ecma_string_t *, uint32_t *);
179179
extern lit_utf8_size_t __attr_return_value_should_be_checked___
180180
ecma_string_to_utf8_string (const ecma_string_t *, lit_utf8_byte_t *, lit_utf8_size_t);
181181
extern const lit_utf8_byte_t *ecma_string_raw_chars (const ecma_string_t *, lit_utf8_size_t *, bool *);
182+
extern void ecma_init_ecma_string_from_uint32 (ecma_string_t *, uint32_t);
182183

183184
extern bool ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *, const ecma_string_t *);
184185
extern bool ecma_compare_ecma_strings (const ecma_string_t *, const ecma_string_t *);

jerry-core/vm/vm.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,43 @@ static ecma_value_t
6969
vm_op_get_value (ecma_value_t object, /**< base object */
7070
ecma_value_t property) /**< property name */
7171
{
72+
if (ecma_is_value_object (object))
73+
{
74+
ecma_object_t *object_p = ecma_get_object_from_value (object);
75+
ecma_string_t *property_name_p = NULL;
76+
ecma_string_t uint32_string;
77+
78+
if (ecma_is_value_integer_number (property))
79+
{
80+
ecma_integer_value_t int_value = ecma_get_integer_from_value (property);
81+
82+
if (int_value >= 0)
83+
{
84+
/* Statically allocated string for searching. */
85+
ecma_init_ecma_string_from_uint32 (&uint32_string, (uint32_t) int_value);
86+
property_name_p = &uint32_string;
87+
}
88+
}
89+
else if (ecma_is_value_string (property))
90+
{
91+
property_name_p = ecma_get_string_from_value (property);
92+
}
93+
94+
if (property_name_p != NULL)
95+
{
96+
ecma_property_t *property_p = ecma_lcache_lookup (object_p, property_name_p);
97+
98+
if (property_p != NULL &&
99+
ECMA_PROPERTY_GET_TYPE (property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA)
100+
{
101+
return ecma_fast_copy_value (ecma_get_named_data_property_value (property_p));
102+
}
103+
104+
/* There is no need to free the name. */
105+
return ecma_op_get_value_object_base (object, property_name_p);
106+
}
107+
}
108+
72109
if (unlikely (ecma_is_value_undefined (object) || ecma_is_value_null (object)))
73110
{
74111
return ecma_raise_type_error (ECMA_ERR_MSG (""));
@@ -83,20 +120,6 @@ vm_op_get_value (ecma_value_t object, /**< base object */
83120

84121
ecma_string_t *property_name_p = ecma_get_string_from_value (prop_to_string_result);
85122

86-
if (ecma_is_value_object (object))
87-
{
88-
ecma_object_t *object_p = ecma_get_object_from_value (object);
89-
90-
ecma_property_t *property_p = ecma_lcache_lookup (object_p, property_name_p);
91-
92-
if (property_p != NULL &&
93-
ECMA_PROPERTY_GET_TYPE (property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA)
94-
{
95-
ecma_deref_ecma_string (property_name_p);
96-
return ecma_fast_copy_value (ecma_get_named_data_property_value (property_p));
97-
}
98-
}
99-
100123
ecma_value_t get_value_result = ecma_op_get_value_object_base (object, property_name_p);
101124

102125
ecma_deref_ecma_string (property_name_p);

0 commit comments

Comments
 (0)