Skip to content

Commit 2027cae

Browse files
committed
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
1 parent 94f8879 commit 2027cae

30 files changed

+202
-242
lines changed

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

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* 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 */
810811
return bytes_copied;
811812
} /* ecma_uint32_to_utf8_string */
812813

813-
/**
814-
* ECMA-defined conversion of UInt32 value to Number value
815-
*
816-
* @return number - result of conversion.
817-
*/
818-
ecma_number_t
819-
ecma_uint32_to_number (uint32_t value) /**< unsigned 32-bit integer value */
820-
{
821-
return (ecma_number_t) value;
822-
} /* ecma_uint32_to_number */
823-
824-
/**
825-
* ECMA-defined conversion of Int32 value to Number value
826-
*
827-
* @return number - result of conversion.
828-
*/
829-
ecma_number_t
830-
ecma_int32_to_number (int32_t value) /**< signed 32-bit integer value */
831-
{
832-
return (ecma_number_t) value;
833-
} /* ecma_int32_to_number */
834-
835814
/**
836815
* ECMA-defined conversion of Number value to UInt32 value
837816
*
@@ -1344,7 +1323,8 @@ ecma_number_to_utf8_string (ecma_number_t num, /**< ecma-number */
13441323

13451324
// 5.
13461325
uint32_t num_uint32 = ecma_number_to_uint32 (num);
1347-
if (ecma_uint32_to_number (num_uint32) == num)
1326+
1327+
if (((ecma_number_t) num_uint32) == num)
13481328
{
13491329
size = ecma_uint32_to_utf8_string (num_uint32, dst_p, buffer_size);
13501330
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ ecma_number_get_sign_field (ecma_number_t num) /**< ecma-number */
230230
fraction is filled with anything but not all zero bits,
231231
* false - otherwise
232232
*/
233-
bool
233+
bool __attr_always_inline___
234234
ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
235235
{
236236
bool is_nan = (num != num);
@@ -283,7 +283,7 @@ ecma_number_make_infinity (bool sign) /**< true - for negative Infinity,
283283
* @return true - if sign bit of ecma-number is set
284284
* false - otherwise
285285
*/
286-
bool
286+
bool __attr_always_inline___
287287
ecma_number_is_negative (ecma_number_t num) /**< ecma-number */
288288
{
289289
JERRY_ASSERT (!ecma_number_is_nan (num));

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ ecma_string_t *
238238
ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */
239239
{
240240
uint32_t uint32_num = ecma_number_to_uint32 (num);
241-
if (num == ecma_uint32_to_number (uint32_num))
241+
if (num == ((ecma_number_t) uint32_num))
242242
{
243243
return ecma_new_ecma_string_from_uint32 (uint32_num);
244244
}
@@ -533,7 +533,7 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */
533533
{
534534
uint32_t uint32_number = str_p->u.uint32_number;
535535

536-
return ecma_uint32_to_number (uint32_number);
536+
return ((ecma_number_t) uint32_number);
537537
}
538538

539539
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
@@ -1002,36 +1002,13 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
10021002
return is_equal;
10031003
} /* ecma_compare_ecma_strings_longpath */
10041004

1005-
/**
1006-
* Compare ecma-string to ecma-string if they're hashes are equal
1007-
*
1008-
* @return true - if strings are equal;
1009-
* false - may be.
1010-
*/
1011-
bool
1012-
ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *string1_p, /* ecma-string */
1013-
const ecma_string_t *string2_p) /* ecma-string */
1014-
{
1015-
JERRY_ASSERT (string1_p->hash == string2_p->hash);
1016-
1017-
if (ECMA_STRING_GET_CONTAINER (string1_p) == ECMA_STRING_GET_CONTAINER (string2_p)
1018-
&& string1_p->u.common_field == string2_p->u.common_field)
1019-
{
1020-
return true;
1021-
}
1022-
else
1023-
{
1024-
return false;
1025-
}
1026-
} /* ecma_compare_ecma_strings_equal_hashes */
1027-
10281005
/**
10291006
* Compare ecma-string to ecma-string
10301007
*
10311008
* @return true - if strings are equal;
10321009
* false - otherwise.
10331010
*/
1034-
bool
1011+
bool __attr_always_inline___
10351012
ecma_compare_ecma_strings (const ecma_string_t *string1_p, /* ecma-string */
10361013
const ecma_string_t *string2_p) /* ecma-string */
10371014
{
@@ -1042,14 +1019,13 @@ ecma_compare_ecma_strings (const ecma_string_t *string1_p, /* ecma-string */
10421019
return false;
10431020
}
10441021

1045-
if (ecma_compare_ecma_strings_equal_hashes (string1_p, string2_p))
1022+
if (ECMA_STRING_GET_CONTAINER (string1_p) == ECMA_STRING_GET_CONTAINER (string2_p)
1023+
&& string1_p->u.common_field == string2_p->u.common_field)
10461024
{
10471025
return true;
10481026
}
1049-
else
1050-
{
1051-
return ecma_compare_ecma_strings_longpath (string1_p, string2_p);
1052-
}
1027+
1028+
return ecma_compare_ecma_strings_longpath (string1_p, string2_p);
10531029
} /* ecma_compare_ecma_strings */
10541030

10551031
/**

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

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* 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 */
397398
/**
398399
* Copy ecma value.
399400
*
400-
* Note:
401-
* Operation algorithm.
402-
* switch (valuetype)
403-
* case simple:
404-
* simply return the value as it was passed;
405-
* case number:
406-
* copy the number
407-
* and return new ecma value
408-
* pointing to copy of the number;
409-
* case string:
410-
* increase reference counter of the string
411-
* and return the value as it was passed.
412-
* case object;
413-
* increase reference counter of the object if do_ref_if_object is true
414-
* and return the value as it was passed.
415-
*
416-
* @return See note.
401+
* @return copy of the given value
417402
*/
418403
ecma_value_t
419-
ecma_copy_value (ecma_value_t value, /**< ecma value */
420-
bool do_ref_if_object) /**< if the value is object value,
421-
increment reference counter of the object */
404+
ecma_copy_value (ecma_value_t value) /**< value description */
422405
{
423-
ecma_value_t value_copy = 0;
424-
425406
switch (ecma_get_value_type_field (value))
426407
{
427408
case ECMA_TYPE_SIMPLE:
428409
{
429-
value_copy = value;
430-
431-
break;
410+
return value;
432411
}
433412
case ECMA_TYPE_NUMBER:
434413
{
@@ -437,38 +416,38 @@ ecma_copy_value (ecma_value_t value, /**< ecma value */
437416
ecma_number_t *number_copy_p = ecma_alloc_number ();
438417
*number_copy_p = *num_p;
439418

440-
value_copy = ecma_make_number_value (number_copy_p);
441-
442-
break;
419+
return ecma_make_number_value (number_copy_p);
443420
}
444421
case ECMA_TYPE_STRING:
445422
{
446-
ecma_string_t *string_p = ecma_get_string_from_value (value);
447-
448-
string_p = ecma_copy_or_ref_ecma_string (string_p);
449-
450-
value_copy = ecma_make_string_value (string_p);
451-
452-
break;
423+
return ecma_make_string_value (ecma_copy_or_ref_ecma_string (ecma_get_string_from_value (value)));
453424
}
454425
case ECMA_TYPE_OBJECT:
455426
{
456-
ecma_object_t *obj_p = ecma_get_object_from_value (value);
457-
458-
if (do_ref_if_object)
459-
{
460-
ecma_ref_object (obj_p);
461-
}
462-
463-
value_copy = value;
464-
465-
break;
427+
ecma_ref_object (ecma_get_object_from_value (value));
428+
return value;
466429
}
467430
}
468431

469-
return value_copy;
432+
JERRY_UNREACHABLE ();
470433
} /* ecma_copy_value */
471434

435+
/**
436+
* Copy the ecma value if not an object
437+
*
438+
* @return copy of the given value
439+
*/
440+
ecma_value_t
441+
ecma_copy_value_if_not_object (ecma_value_t value) /**< value description */
442+
{
443+
if (ecma_get_value_type_field (value) != ECMA_TYPE_OBJECT)
444+
{
445+
return ecma_copy_value (value);
446+
}
447+
448+
return value;
449+
} /* ecma_copy_value_if_not_object */
450+
472451
/**
473452
* Free the ecma value
474453
*/

jerry-core/ecma/base/ecma-helpers-values-collection.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
1+
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* 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
6768

6869
JERRY_ASSERT (cur_value_buf_iter_p + 1 <= cur_value_buf_end_p);
6970

70-
*cur_value_buf_iter_p++ = ecma_copy_value (values_buffer[value_index], do_ref_if_object);
71+
if (do_ref_if_object)
72+
{
73+
*cur_value_buf_iter_p++ = ecma_copy_value (values_buffer[value_index]);
74+
}
75+
else
76+
{
77+
*cur_value_buf_iter_p++ = ecma_copy_value_if_not_object (values_buffer[value_index]);
78+
}
7179
}
7280

7381
*next_chunk_cp_p = ECMA_NULL_POINTER;
@@ -189,7 +197,14 @@ ecma_append_to_values_collection (ecma_collection_header_t *header_p, /**< colle
189197

190198
JERRY_ASSERT ((uint8_t *) (values_p + pos_of_new_value_in_chunk + 1) <= (uint8_t *) (chunk_p + 1));
191199

192-
values_p[pos_of_new_value_in_chunk] = ecma_copy_value (v, do_ref_if_object);
200+
if (do_ref_if_object)
201+
{
202+
values_p[pos_of_new_value_in_chunk] = ecma_copy_value (v);
203+
}
204+
else
205+
{
206+
values_p[pos_of_new_value_in_chunk] = ecma_copy_value_if_not_object (v);
207+
}
193208
} /* ecma_append_to_values_collection */
194209

195210
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ ecma_named_data_property_assign_value (ecma_object_t *obj_p, /**< object */
10011001
ecma_value_t v = ecma_get_named_data_property_value (prop_p);
10021002
ecma_free_value_if_not_object (v);
10031003

1004-
ecma_set_named_data_property_value (prop_p, ecma_copy_value (value, false));
1004+
ecma_set_named_data_property_value (prop_p, ecma_copy_value_if_not_object (value));
10051005
}
10061006
} /* ecma_named_data_property_assign_value */
10071007

@@ -1283,7 +1283,7 @@ ecma_get_property_descriptor_from_property (ecma_property_t *prop_p) /**< proper
12831283

12841284
if (prop_p->flags & ECMA_PROPERTY_FLAG_NAMEDDATA)
12851285
{
1286-
prop_desc.value = ecma_copy_value (ecma_get_named_data_property_value (prop_p), true);
1286+
prop_desc.value = ecma_copy_value (ecma_get_named_data_property_value (prop_p));
12871287
prop_desc.is_value_defined = true;
12881288
prop_desc.is_writable = ecma_is_property_writable (prop_p);
12891289
prop_desc.is_writable_defined = true;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ extern ecma_number_t *ecma_get_number_from_value (ecma_value_t) __attr_pure___;
8080
extern ecma_string_t *ecma_get_string_from_value (ecma_value_t) __attr_pure___;
8181
extern ecma_object_t *ecma_get_object_from_value (ecma_value_t) __attr_pure___;
8282
extern ecma_value_t ecma_get_value_from_error_value (ecma_value_t) __attr_pure___;
83-
extern ecma_value_t ecma_copy_value (ecma_value_t, bool);
83+
extern ecma_value_t ecma_copy_value (ecma_value_t);
84+
extern ecma_value_t ecma_copy_value_if_not_object (ecma_value_t);
8485
extern void ecma_free_value (ecma_value_t);
8586
extern void ecma_free_value_if_not_object (ecma_value_t);
8687

@@ -243,8 +244,6 @@ extern ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *, lit_ut
243244
extern lit_utf8_size_t ecma_uint32_to_utf8_string (uint32_t, lit_utf8_byte_t *, lit_utf8_size_t);
244245
extern uint32_t ecma_number_to_uint32 (ecma_number_t);
245246
extern int32_t ecma_number_to_int32 (ecma_number_t);
246-
extern ecma_number_t ecma_int32_to_number (int32_t);
247-
extern ecma_number_t ecma_uint32_to_number (uint32_t);
248247
extern lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t, lit_utf8_byte_t *, lit_utf8_size_t);
249248

250249
#endif /* !ECMA_HELPERS_H */

jerry-core/ecma/base/ecma-lcache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
1+
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* 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 */
256257
ecma_string_t *entry_prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
257258
ecma_lcache_hash_table[hash_key][i].prop_name_cp);
258259

259-
if (ecma_compare_ecma_strings_equal_hashes (prop_name_p, entry_prop_name_p))
260+
JERRY_ASSERT (prop_name_p->hash == entry_prop_name_p->hash);
261+
262+
if (ECMA_STRING_GET_CONTAINER (prop_name_p) == ECMA_STRING_GET_CONTAINER (entry_prop_name_p)
263+
&& prop_name_p->u.common_field == entry_prop_name_p->u.common_field)
260264
{
261265
ecma_property_t *prop_p = ECMA_GET_POINTER (ecma_property_t, ecma_lcache_hash_table[hash_key][i].prop_cp);
262266
JERRY_ASSERT (prop_p == NULL || ecma_is_property_lcached (prop_p));

0 commit comments

Comments
 (0)