Skip to content

Commit c45735f

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 c45735f

File tree

3 files changed

+64
-20
lines changed

3 files changed

+64
-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: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,53 @@ 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+
76+
do
77+
{
78+
ecma_string_t *property_name_p = NULL;
79+
ecma_string_t uint32_string;
80+
81+
if (ecma_is_value_integer_number (property))
82+
{
83+
ecma_integer_value_t int_value = ecma_get_integer_from_value (property);
84+
85+
if (int_value < 0)
86+
{
87+
break;
88+
}
89+
90+
/* Statically allocated string for searching. */
91+
ecma_init_ecma_string_from_uint32 (&uint32_string, (uint32_t) int_value);
92+
property_name_p = &uint32_string;
93+
}
94+
else if (ecma_is_value_string (property))
95+
{
96+
property_name_p = ecma_get_string_from_value (property);
97+
}
98+
else
99+
{
100+
break;
101+
}
102+
103+
JERRY_ASSERT (property_name_p != NULL);
104+
105+
ecma_property_t *property_p = ecma_lcache_lookup (object_p, property_name_p);
106+
107+
if (property_p != NULL &&
108+
ECMA_PROPERTY_GET_TYPE (property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA)
109+
{
110+
return ecma_fast_copy_value (ecma_get_named_data_property_value (property_p));
111+
}
112+
113+
/* There is no need to free the name. */
114+
return ecma_op_get_value_object_base (object, property_name_p);
115+
}
116+
while (0);
117+
}
118+
72119
if (unlikely (ecma_is_value_undefined (object) || ecma_is_value_null (object)))
73120
{
74121
return ecma_raise_type_error (ECMA_ERR_MSG (""));
@@ -83,20 +130,6 @@ vm_op_get_value (ecma_value_t object, /**< base object */
83130

84131
ecma_string_t *property_name_p = ecma_get_string_from_value (prop_to_string_result);
85132

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-
100133
ecma_value_t get_value_result = ecma_op_get_value_object_base (object, property_name_p);
101134

102135
ecma_deref_ecma_string (property_name_p);

0 commit comments

Comments
 (0)