Skip to content

Commit 38de786

Browse files
committed
update:
* change the struct of typedarray object * change the if-else-branch in set/get prop method
1 parent 4cfe58b commit 38de786

30 files changed

+285
-181
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
308308
#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
309309
if (ecma_is_typedarray (ecma_make_object_value (object_p)))
310310
{
311-
ecma_typedarray_info_t *info_p = ecma_typedarray_get_info (object_p);
312-
ecma_gc_set_object_visited (info_p->viewed_arraybuffer_p, true);
311+
ecma_gc_set_object_visited (ecma_typedarray_get_arraybuffer (object_p), true);
313312
}
314313
#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */
315314
break;
@@ -490,7 +489,13 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
490489
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
491490
case LIT_MAGIC_STRING_INT8_ARRAY_UL:
492491
{
493-
size_t size = sizeof (ecma_extended_object_t) + sizeof (ecma_typedarray_info_t);
492+
size_t size = sizeof (ecma_extended_object_t);
493+
494+
if (ext_object_p->u.class_prop.class_type == ECMA_CLASS_TYPE_TYPEDARRAY_WITH_INFO)
495+
{
496+
size = size + sizeof (ecma_typedarray_info_t);
497+
}
498+
494499
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p, size);
495500
return;
496501
}

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ typedef enum
7979
ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */
8080
ECMA_SIMPLE_VALUE_NULL, /**< null value */
8181
ECMA_SIMPLE_VALUE_NOT_FOUND, /**< a special value returned by ecma_op_object_find */
82-
ECMA_SIMPLE_VALUE_NOT_FOUND_AND_STOP, /** not found and not search the proto chain */
8382
ECMA_SIMPLE_VALUE_REGISTER_REF, /**< register reference, a special "base" value for vm */
8483
ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma values */
8584
} ecma_simple_value_t;
@@ -526,6 +525,18 @@ typedef enum
526525
ECMA_OBJECT_TYPE__MAX = ECMA_OBJECT_TYPE_ARGUMENTS /**< maximum value */
527526
} ecma_object_type_t;
528527

528+
/**
529+
* Types of objects with class property
530+
*/
531+
typedef enum
532+
{
533+
ECMA_CLASS_TYPE_GENERAL = 0, /**< all class type objects that are not TypedArray */
534+
ECMA_CLASS_TYPE_TYPEDARRAY = 1, /**< TypedArray which does NOT need extra space to store length and offset */
535+
ECMA_CLASS_TYPE_TYPEDARRAY_WITH_INFO = 2, /**< TypedArray which NEEDS extra space to store length and offset */
536+
537+
ECMA_CLASS_TYPE__MAX = ECMA_CLASS_TYPE_TYPEDARRAY_WITH_INFO /**< maximum value */
538+
} ecma_object_class_type_t;
539+
529540
/**
530541
* Types of lexical environments
531542
*/
@@ -641,13 +652,15 @@ typedef struct
641652
struct
642653
{
643654
uint16_t class_id; /**< class id of the object */
655+
uint8_t class_type; /**< the type of the class (ecma_object_class_type_t)*/
656+
uint8_t extra_info; /**< extra infos about the class type object */
644657
/*
645658
* Description of extra fields. These extra fields depends on the class_id.
646659
*/
647660
union
648661
{
649662
ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
650-
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
663+
uint32_t length; /**< length related property*/
651664
} u;
652665
} class_prop;
653666

@@ -1140,12 +1153,10 @@ typedef struct
11401153
*/
11411154
typedef struct
11421155
{
1143-
/** The arraybuffer object behind the typedarray */
1144-
ecma_object_t *viewed_arraybuffer_p;
11451156
/** the byteoffset of the above arraybuffer */
11461157
ecma_length_t byte_offset;
1147-
/** the size of each element in the typedarray */
1148-
ecma_length_t bytes_per_element;
1158+
/** the array length */
1159+
ecma_length_t array_length;
11491160
} ecma_typedarray_info_t;
11501161

11511162
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ ecma_is_value_false (ecma_value_t value) /**< ecma value */
229229
inline bool __attr_pure___ __attr_always_inline___
230230
ecma_is_value_found (ecma_value_t value) /**< ecma value */
231231
{
232-
return (value != ecma_make_simple_value (ECMA_SIMPLE_VALUE_NOT_FOUND)
233-
&& value != ecma_make_simple_value (ECMA_SIMPLE_VALUE_NOT_FOUND_AND_STOP));
232+
return value != ecma_make_simple_value (ECMA_SIMPLE_VALUE_NOT_FOUND);
234233
} /* ecma_is_value_found */
235234

236235
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
485485

486486
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
487487
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_UNDEFINED;
488+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
488489

489490
ecma_deref_object (prototype_obj_p);
490491

@@ -549,6 +550,7 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
549550
}
550551

551552
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_DATE_UL;
553+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
552554

553555
ecma_number_t *date_num_p = ecma_alloc_number ();
554556
*date_num_p = prim_value_num;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ecma_builtin_int8array_dispatch_construct (const ecma_value_t *arguments_list_p,
7676
ecma_value_t val = ecma_op_create_typedarray (arguments_list_p,
7777
arguments_list_len,
7878
prototype_obj_p,
79-
1,
79+
0,
8080
LIT_MAGIC_STRING_INT8_ARRAY_UL);
8181

8282
ecma_deref_object (prototype_obj_p);

jerry-core/ecma/builtin-objects/ecma-builtin-typedarray-prototype.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ ecma_builtin_typedarray_prototype_buffer_getter (ecma_value_t this_arg) /**< thi
5858
{
5959
if (ecma_is_typedarray (this_arg))
6060
{
61-
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
62-
ecma_typedarray_info_t *info_p = ecma_typedarray_get_info (object_p);
63-
ecma_ref_object (info_p->viewed_arraybuffer_p);
64-
return ecma_make_object_value (info_p->viewed_arraybuffer_p);
61+
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
62+
ecma_object_t *obj_p = ecma_typedarray_get_arraybuffer (typedarray_p);
63+
ecma_ref_object (obj_p);
64+
65+
return ecma_make_object_value (obj_p);
6566
}
6667

6768
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));
@@ -81,11 +82,10 @@ ecma_builtin_typedarray_prototype_bytelength_getter (ecma_value_t this_arg) /**<
8182
{
8283
if (ecma_is_typedarray (this_arg))
8384
{
84-
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
85-
ecma_typedarray_info_t *info_p = ecma_typedarray_get_info (object_p);
86-
ecma_length_t length = ecma_typedarray_get_length (object_p);
85+
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
86+
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
8787

88-
return ecma_make_uint32_value (length * info_p->bytes_per_element);
88+
return ecma_make_uint32_value (ecma_typedarray_get_length (typedarray_p) << shift);
8989
}
9090

9191
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));
@@ -105,10 +105,9 @@ ecma_builtin_typedarray_prototype_byteoffset_getter (ecma_value_t this_arg) /**<
105105
{
106106
if (ecma_is_typedarray (this_arg))
107107
{
108-
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
109-
ecma_typedarray_info_t *info_p = ecma_typedarray_get_info (object_p);
108+
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
110109

111-
return ecma_make_uint32_value (info_p->byte_offset);
110+
return ecma_make_uint32_value (ecma_typedarray_get_offset (typedarray_p));
112111
}
113112

114113
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));
@@ -128,10 +127,9 @@ ecma_builtin_typedarray_prototype_length_getter (ecma_value_t this_arg) /**< thi
128127
{
129128
if (ecma_is_typedarray (this_arg))
130129
{
131-
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
132-
ecma_length_t length = ecma_typedarray_get_length (object_p);
130+
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
133131

134-
return ecma_make_uint32_value (length);
132+
return ecma_make_uint32_value (ecma_typedarray_get_length (typedarray_p));
135133
}
136134

137135
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
224224
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
225225

226226
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_STRING_UL;
227+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
227228
ecma_string_t *prim_prop_str_value_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
228229
ext_object_p->u.class_prop.u.value = ecma_make_string_value (prim_prop_str_value_p);
229230
break;
@@ -237,6 +238,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
237238
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
238239

239240
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_NUMBER_UL;
241+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
240242
ext_object_p->u.class_prop.u.value = ecma_make_integer_value (0);
241243
break;
242244
}
@@ -249,6 +251,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
249251
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
250252

251253
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_BOOLEAN_UL;
254+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
252255
ext_object_p->u.class_prop.u.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
253256
break;
254257
}
@@ -261,6 +264,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
261264
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
262265

263266
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_DATE_UL;
267+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
264268

265269
ecma_number_t *prim_prop_num_value_p = ecma_alloc_number ();
266270
*prim_prop_num_value_p = ecma_number_make_nan ();
@@ -276,6 +280,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
276280
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
277281

278282
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL;
283+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
279284
ext_object_p->u.class_prop.u.value = ECMA_NULL_POINTER;
280285
break;
281286
}

jerry-core/ecma/operations/ecma-arraybuffer-object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ecma_arraybuffer_new_object (ecma_length_t length) /**< length of the arraybuffe
9393
ecma_deref_object (prototype_obj_p);
9494
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
9595
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_ARRAY_BUFFER_UL;
96+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
9697
ext_object_p->u.class_prop.u.length = length;
9798

9899
lit_utf8_byte_t *buf = (lit_utf8_byte_t *) (ext_object_p + 1);

jerry-core/ecma/operations/ecma-boolean-object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ecma_op_create_boolean_object (ecma_value_t arg) /**< argument passed to the Boo
5757

5858
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
5959
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_BOOLEAN_UL;
60+
ext_object_p->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
6061
ext_object_p->u.class_prop.u.value = ecma_make_boolean_value (boolean_value);
6162

6263
return ecma_make_object_value (object_p);

jerry-core/ecma/operations/ecma-exceptions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ ecma_new_standard_error (ecma_standard_error_t error_type) /**< native error typ
9898
ecma_deref_object (prototype_obj_p);
9999

100100
((ecma_extended_object_t *) new_error_obj_p)->u.class_prop.class_id = LIT_MAGIC_STRING_ERROR_UL;
101+
((ecma_extended_object_t *) new_error_obj_p)->u.class_prop.class_type = ECMA_CLASS_TYPE_GENERAL;
101102

102103
return new_error_obj_p;
103104
} /* ecma_new_standard_error */

0 commit comments

Comments
 (0)