From 243e14ac21b355a7f458f680dc93f690024d373e Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Thu, 7 Feb 2019 16:07:13 +0100 Subject: [PATCH] Reduce the memory allocations while getting a string's length property (#2736) This patch reduces the number of string to string object conversion during property managing operations, via access the length property directly from the string instead of the newly created string object. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu --- jerry-core/ecma/operations/ecma-get-put-value.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jerry-core/ecma/operations/ecma-get-put-value.c b/jerry-core/ecma/operations/ecma-get-put-value.c index 826193bd5..cb8a0819a 100644 --- a/jerry-core/ecma/operations/ecma-get-put-value.c +++ b/jerry-core/ecma/operations/ecma-get-put-value.c @@ -99,6 +99,15 @@ ecma_op_get_value_object_base (ecma_value_t base_value, /**< base value */ || ECMA_ASSERT_VALUE_IS_SYMBOL (base_value) || ecma_is_value_string (base_value)); + /* Fast path for the strings length property. The length of the string + can be obtained directly from the ecma-string. */ + if (ecma_is_value_string (base_value) && ecma_string_is_length (property_name_p)) + { + ecma_string_t *string_p = ecma_get_string_from_value (base_value); + + return ecma_make_uint32_value (ecma_string_get_length (string_p)); + } + ecma_value_t object_base = ecma_op_to_object (base_value); JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (object_base));