Eliminate the allocation of spread object (#3333)

ECMA_VALUE_SPREAD_ELEMENT can be used to represent that the next argument needs to be spreaded, therefore no allocation is needed.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-11-19 18:16:43 +01:00
committed by Dániel Bátyai
parent 70566a52fb
commit 830011c033
10 changed files with 49 additions and 207 deletions
-20
View File
@@ -465,17 +465,6 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
break;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
#if ENABLED (JERRY_ES2015)
case ECMA_PSEUDO_SPREAD_OBJECT:
{
ecma_value_t spread_value = ext_object_p->u.pseudo_array.u2.spread_value;
if (ecma_is_value_object (spread_value))
{
ecma_gc_set_object_visited (ecma_get_object_from_value (spread_value));
}
break;
}
#endif /* ENABLED (JERRY_ES2015) */
default:
{
JERRY_ASSERT (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS);
@@ -967,15 +956,6 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
break;
}
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
#if ENABLED (JERRY_ES2015)
case ECMA_PSEUDO_SPREAD_OBJECT:
{
ecma_value_t spread_value = ext_object_p->u.pseudo_array.u2.spread_value;
ecma_free_value_if_not_object (spread_value);
break;
}
#endif /* ENABLED (JERRY_ES2015) */
default:
{
JERRY_ASSERT (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_TYPEDARRAY
+3 -2
View File
@@ -190,6 +190,8 @@ enum
* a special "base" value for vm */
ECMA_VALUE_IMPLICIT_CONSTRUCTOR = ECMA_MAKE_VALUE (9), /**< special value for bound class constructors */
ECMA_VALUE_UNINITIALIZED = ECMA_MAKE_VALUE (10), /**< a special value for uninitialized let/const declarations */
ECMA_VALUE_SPREAD_ELEMENT = ECMA_MAKE_VALUE (11), /**< a special value for spread elements in array initialization
* or function call argument list */
};
#if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
@@ -630,8 +632,7 @@ typedef enum
ECMA_PSEUDO_SET_ITERATOR = 4, /**< Set iterator object (ECMAScript v6, 23.2.5.1) */
ECMA_PSEUDO_MAP_ITERATOR = 5, /**< Map iterator object (ECMAScript v6, 23.1.5.1) */
ECMA_PSEUDO_STRING_ITERATOR = 6, /**< String iterator object (ECMAScript v6, 22.1.5.1) */
ECMA_PSEUDO_SPREAD_OBJECT = 7, /**< spread object */
ECMA_PSEUDO_ARRAY__MAX = ECMA_PSEUDO_SPREAD_OBJECT /**< maximum value */
ECMA_PSEUDO_ARRAY__MAX = ECMA_PSEUDO_STRING_ITERATOR /**< maximum value */
} ecma_pseudo_array_type_t;
/**
@@ -1,88 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-spread-object.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaspreadeanobject ECMA Spread object related routines
* @{
*/
/**
* Spread object creation operation.
*
* @return pseudo array object as an ecma value
* Returned value must be freed with ecma_free_value
*/
ecma_value_t
ecma_op_create_spread_object (ecma_value_t element) /**< value to spread */
{
ecma_object_t *object_p = ecma_create_object (NULL,
sizeof (ecma_extended_object_t),
ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ext_object_p->u.pseudo_array.type = ECMA_PSEUDO_SPREAD_OBJECT;
ext_object_p->u.pseudo_array.u2.spread_value = ecma_copy_value_if_not_object (element);
return ecma_make_object_value (object_p);
} /* ecma_op_create_spread_object */
/**
* Spread object creation operation.
*
* @return true - if the argument is a spread object
* false, otherwise
*/
bool
ecma_op_is_spread_object (ecma_value_t value) /**< value to check */
{
if (ecma_is_value_object (value))
{
ecma_object_t *object_p = ecma_get_object_from_value (value);
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_PSEUDO_ARRAY)
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
return ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_SPREAD_OBJECT;
}
}
return false;
} /* ecma_op_is_spread_object */
/**
* Get the referenced element by the spread object
*
* @return element referenced by the spread object as an ecma-value
*/
ecma_value_t
ecma_op_spread_object_get_spreaded_element (ecma_object_t *object_p) /**< spread object */
{
JERRY_ASSERT (ecma_op_is_spread_object (ecma_make_object_value (object_p)));
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
return ecma_copy_value (ext_object_p->u.pseudo_array.u2.spread_value);
} /* ecma_op_spread_object_get_spreaded_element */
/**
* @}
* @}
*/
@@ -1,42 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMA_SPREAD_OBJECT_H
#define ECMA_SPREAD_OBJECT_H
#include "ecma-globals.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaspreadobject ECMA Spread object related routines
* @{
*/
ecma_value_t
ecma_op_create_spread_object (ecma_value_t arg);
bool
ecma_op_is_spread_object (ecma_value_t value);
ecma_value_t
ecma_op_spread_object_get_spreaded_element (ecma_object_t *object_p);
/**
* @}
* @}
*/
#endif /* !ECMA_SPREAD_OBJECT_H */