Skip to content

Commit 603cd88

Browse files
rerobikadbatyai
authored andcommitted
Use custom dispatcher for String.prototype routines (#2964)
Binary size gain: - Intel: ~1.3KB (gcc-7.3) - Arm: ~650B (arm-linux-gnueabi-gcc-7.3) Co-authored-by: Marko Fabo mfabo@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent a21a419 commit 603cd88

4 files changed

Lines changed: 921 additions & 1111 deletions

File tree

jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -552,27 +552,12 @@ ecma_builtin_helper_string_index_normalize (ecma_number_t index, /**< index */
552552
* boolean value
553553
*/
554554
ecma_value_t
555-
ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**< this argument */
555+
ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_str_p, /**< this argument */
556556
ecma_value_t arg1, /**< routine's first argument */
557557
ecma_value_t arg2, /**< routine's second argument */
558558
ecma_string_index_of_mode_t mode) /**< routine's mode */
559559
{
560-
/* 1 */
561-
if (ECMA_IS_VALUE_ERROR (ecma_op_check_object_coercible (this_arg)))
562-
{
563-
return ECMA_VALUE_ERROR;
564-
}
565-
566-
/* 2 */
567-
ecma_value_t to_str_val = ecma_op_to_string (this_arg);
568-
569-
if (ECMA_IS_VALUE_ERROR (to_str_val))
570-
{
571-
return to_str_val;
572-
}
573-
574-
/* 5 (indexOf), 6 (lastIndexOf), 11 (startsWith, includes) */
575-
ecma_string_t *original_str_p = ecma_get_string_from_value (to_str_val);
560+
/* 5 (indexOf) -- 6 (lastIndexOf) */
576561
const ecma_length_t original_len = ecma_string_get_length (original_str_p);
577562

578563
#if ENABLED (JERRY_ES2015_BUILTIN)
@@ -582,7 +567,6 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
582567
&& ecma_object_class_is (ecma_get_object_from_value (arg1), LIT_MAGIC_STRING_REGEXP_UL)))
583568
{
584569
JERRY_ASSERT (ECMA_STRING_LAST_INDEX_OF < mode && mode <= ECMA_STRING_ENDS_WITH);
585-
ecma_deref_ecma_string (original_str_p);
586570
return ecma_raise_type_error (ECMA_ERR_MSG ("Search string can't be of type: RegExp"));
587571
}
588572
#endif /* ENABLED (JERRY_ES2015_BUILTIN) */
@@ -592,7 +576,6 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
592576

593577
if (ECMA_IS_VALUE_ERROR (search_str_val))
594578
{
595-
ecma_deref_ecma_string (original_str_p);
596579
return search_str_val;
597580
}
598581

@@ -606,7 +589,6 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
606589
/* 10 (startsWith, includes), 11 (endsWith) */
607590
if (ECMA_IS_VALUE_ERROR (ret_value))
608591
{
609-
ecma_deref_ecma_string (original_str_p);
610592
ecma_deref_ecma_string (search_str_p);
611593
return ret_value;
612594
}
@@ -692,7 +674,6 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
692674
}
693675

694676
ecma_deref_ecma_string (search_str_p);
695-
ecma_deref_ecma_string (original_str_p);
696677

697678
return ret_value;
698679
} /* ecma_builtin_helper_string_prototype_object_index_of */

jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ecma_builtin_helper_array_index_normalize (ecma_number_t index, uint32_t length)
5252
uint32_t
5353
ecma_builtin_helper_string_index_normalize (ecma_number_t index, uint32_t length, bool nan_to_zero);
5454
ecma_value_t
55-
ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, ecma_value_t arg1,
55+
ecma_builtin_helper_string_prototype_object_index_of (ecma_string_t *original_str_p, ecma_value_t arg1,
5656
ecma_value_t arg2, ecma_string_index_of_mode_t mode);
5757
bool
5858
ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, ecma_string_t *search_str_p, bool first_index,

0 commit comments

Comments
 (0)