Improve magic string handling. (#2221)
Remove unnecessary ref / deref calls when magic strings are used. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -164,47 +164,35 @@ re_initialize_props (ecma_object_t *re_obj_p, /**< RegExp object */
|
||||
ecma_string_t *source_p, /**< source string */
|
||||
uint16_t flags) /**< flags */
|
||||
{
|
||||
/* Set source property. ECMA-262 v5, 15.10.7.1 */
|
||||
ecma_string_t *magic_string_p;
|
||||
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_SOURCE);
|
||||
/* Set source property. ECMA-262 v5, 15.10.7.1 */
|
||||
re_set_data_property (re_obj_p,
|
||||
magic_string_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_SOURCE),
|
||||
ECMA_PROPERTY_FIXED,
|
||||
ecma_make_string_value (source_p));
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
/* Set global property. ECMA-262 v5, 15.10.7.2 */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_GLOBAL);
|
||||
re_set_data_property (re_obj_p,
|
||||
magic_string_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_GLOBAL),
|
||||
ECMA_PROPERTY_FIXED,
|
||||
ecma_make_boolean_value (flags & RE_FLAG_GLOBAL));
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
/* Set ignoreCase property. ECMA-262 v5, 15.10.7.3 */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_IGNORECASE_UL);
|
||||
re_set_data_property (re_obj_p,
|
||||
magic_string_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_IGNORECASE_UL),
|
||||
ECMA_PROPERTY_FIXED,
|
||||
ecma_make_boolean_value (flags & RE_FLAG_IGNORE_CASE));
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
/* Set multiline property. ECMA-262 v5, 15.10.7.4 */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MULTILINE);
|
||||
re_set_data_property (re_obj_p,
|
||||
magic_string_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_MULTILINE),
|
||||
ECMA_PROPERTY_FIXED,
|
||||
ecma_make_boolean_value (flags & RE_FLAG_MULTILINE));
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
/* Set lastIndex property. ECMA-262 v5, 15.10.7.5 */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
|
||||
re_set_data_property (re_obj_p,
|
||||
magic_string_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
|
||||
ECMA_PROPERTY_FLAG_WRITABLE,
|
||||
ecma_make_integer_value (0));
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
} /* re_initialize_props */
|
||||
|
||||
/**
|
||||
@@ -1172,33 +1160,24 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
|
||||
int32_t index) /**< index of matching */
|
||||
{
|
||||
/* Set index property of the result array */
|
||||
ecma_string_t *result_prop_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INDEX);
|
||||
{
|
||||
ecma_builtin_helper_def_prop (array_obj_p,
|
||||
result_prop_str_p,
|
||||
ecma_make_int32_value (index),
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
true); /* Failure handling */
|
||||
}
|
||||
ecma_deref_ecma_string (result_prop_str_p);
|
||||
ecma_builtin_helper_def_prop (array_obj_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_INDEX),
|
||||
ecma_make_int32_value (index),
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
true); /* Failure handling */
|
||||
|
||||
/* Set input property of the result array */
|
||||
result_prop_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INPUT);
|
||||
|
||||
ecma_builtin_helper_def_prop (array_obj_p,
|
||||
result_prop_str_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_INPUT),
|
||||
ecma_make_string_value (input_str_p),
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
true); /* Failure handling */
|
||||
|
||||
ecma_deref_ecma_string (result_prop_str_p);
|
||||
|
||||
/* Set length property of the result array */
|
||||
result_prop_str_p = ecma_new_ecma_length_string ();
|
||||
{
|
||||
ecma_property_descriptor_t array_item_prop_desc = ecma_make_empty_property_descriptor ();
|
||||
array_item_prop_desc.is_value_defined = true;
|
||||
@@ -1206,11 +1185,10 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
|
||||
array_item_prop_desc.value = ecma_make_uint32_value (num_of_elements);
|
||||
|
||||
ecma_op_object_define_own_property (array_obj_p,
|
||||
result_prop_str_p,
|
||||
ecma_get_length_string (),
|
||||
&array_item_prop_desc,
|
||||
true);
|
||||
}
|
||||
ecma_deref_ecma_string (result_prop_str_p);
|
||||
} /* re_set_result_array_properties */
|
||||
|
||||
/**
|
||||
@@ -1321,8 +1299,6 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (lastindex_num);
|
||||
|
||||
ecma_fast_free_value (lastindex_value);
|
||||
|
||||
ecma_deref_ecma_string (magic_str_p);
|
||||
}
|
||||
|
||||
/* 2. Try to match */
|
||||
@@ -1335,9 +1311,10 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
{
|
||||
if (re_ctx.flags & RE_FLAG_GLOBAL)
|
||||
{
|
||||
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
|
||||
ecma_op_object_put (regexp_object_p, magic_str_p, ecma_make_integer_value (0), true);
|
||||
ecma_deref_ecma_string (magic_str_p);
|
||||
ecma_op_object_put (regexp_object_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
|
||||
ecma_make_integer_value (0),
|
||||
true);
|
||||
}
|
||||
|
||||
is_match = false;
|
||||
@@ -1369,7 +1346,6 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
|
||||
if (input_curr_p && (re_ctx.flags & RE_FLAG_GLOBAL))
|
||||
{
|
||||
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
|
||||
ecma_number_t lastindex_num;
|
||||
|
||||
if (sub_str_p != NULL
|
||||
@@ -1383,8 +1359,10 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
|
||||
lastindex_num = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
ecma_op_object_put (regexp_object_p, magic_str_p, ecma_make_number_value (lastindex_num), true);
|
||||
ecma_deref_ecma_string (magic_str_p);
|
||||
ecma_op_object_put (regexp_object_p,
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
|
||||
ecma_make_number_value (lastindex_num),
|
||||
true);
|
||||
}
|
||||
|
||||
/* 3. Fill the result array or return with 'undefiend' */
|
||||
|
||||
Reference in New Issue
Block a user