New External Magic String API to save heap memory

JerryScript-DCO-1.0-Signed-off-by: SaeHie Park saehie.park@samsung.com
This commit is contained in:
SaeHie Park
2015-06-08 09:03:25 +09:00
parent 603fa56acf
commit 723924f36f
13 changed files with 457 additions and 12 deletions
+12 -2
View File
@@ -133,6 +133,16 @@ string_equals_to_literal (const ecma_char_t *str_p, /**< characters buffer */
return true;
}
}
else if (lit.type == LIT_MAGIC_STR_EX)
{
const char *magic_str_p = (const char *) ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id);
if (strlen (magic_str_p) == length
&& strncmp (magic_str_p, (const char*) str_p, length) == 0)
{
return true;
}
}
return false;
} /* string_equals_to_literal */
@@ -194,7 +204,7 @@ convert_string_to_token (token_type tt, /**< token type */
for (literal_index_t i = 0; i < STACK_SIZE (literals); i++)
{
const literal lit = STACK_ELEMENT (literals, i);
if ((lit.type == LIT_STR || lit.type == LIT_MAGIC_STR)
if ((lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX)
&& string_equals_to_literal (str_p, length, lit))
{
return create_token (tt, i);
@@ -202,7 +212,7 @@ convert_string_to_token (token_type tt, /**< token type */
}
literal lit = create_literal_from_str (str_p, length);
JERRY_ASSERT (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR);
JERRY_ASSERT (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX);
if (lit.type == LIT_STR)
{
lit = add_string_to_string_cache (str_p, length);
+36 -2
View File
@@ -79,6 +79,27 @@ create_literal_from_zt (const ecma_char_t *s, ecma_length_t len)
}
}
uint32_t ex_count = ecma_get_magic_string_ex_count ();
for (ecma_magic_string_ex_id_t msi = (ecma_magic_string_ex_id_t) 0;
msi < ex_count;
msi = (ecma_magic_string_id_t) (msi + 1))
{
const ecma_char_t* ex_string = ecma_get_magic_string_ex_zt (msi);
if (ecma_zt_string_length (ex_string) != len)
{
continue;
}
if (!strncmp ((const char *) s, (const char *) ex_string, len))
{
literal ret;
ret.type = LIT_MAGIC_STR_EX;
ret.data.magic_str_ex_id = msi;
return ret;
}
}
literal ret;
ret.type = LIT_STR;
@@ -108,7 +129,7 @@ literal_equal_type_s (literal lit, const char *s)
bool
literal_equal_type_zt (literal lit, const ecma_char_t *s)
{
if (lit.type != LIT_STR && lit.type != LIT_MAGIC_STR)
if (lit.type != LIT_STR && lit.type != LIT_MAGIC_STR && lit.type != LIT_MAGIC_STR_EX)
{
return false;
}
@@ -142,6 +163,10 @@ literal_equal_lp (literal lit, lp_string lp)
{
return lp_string_equal_zt (lp, ecma_get_magic_string_zt (lit.data.magic_str_id));
}
case LIT_MAGIC_STR_EX:
{
return lp_string_equal_zt (lp, ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id));
}
case LIT_NUMBER:
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
@@ -172,6 +197,10 @@ literal_equal (literal lit1, literal lit2)
{
return literal_equal_zt (lit1, ecma_get_magic_string_zt (lit2.data.magic_str_id));
}
case LIT_MAGIC_STR_EX:
{
return literal_equal_zt (lit1, ecma_get_magic_string_ex_zt (lit2.data.magic_str_ex_id));
}
case LIT_NUMBER:
{
return literal_equal_num (lit1, lit2.data.num);
@@ -206,6 +235,10 @@ literal_equal_zt (literal lit, const ecma_char_t *s)
{
return ecma_compare_zt_strings (s, ecma_get_magic_string_zt (lit.data.magic_str_id));
}
case LIT_MAGIC_STR_EX:
{
return ecma_compare_zt_strings (s, ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id));
}
case LIT_NUMBER:
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
@@ -230,12 +263,13 @@ literal_equal_num (literal lit, ecma_number_t num)
const ecma_char_t *
literal_to_zt (literal lit)
{
JERRY_ASSERT (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR);
JERRY_ASSERT (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX);
switch (lit.type)
{
case LIT_STR: return lit.data.lp.str;
case LIT_MAGIC_STR: return ecma_get_magic_string_zt (lit.data.magic_str_id);
case LIT_MAGIC_STR_EX: return ecma_get_magic_string_ex_zt (lit.data.magic_str_ex_id);
default: JERRY_UNREACHABLE ();
}
}
+2
View File
@@ -24,6 +24,7 @@ typedef enum __attr_packed___
LIT_UNKNOWN,
LIT_STR,
LIT_MAGIC_STR,
LIT_MAGIC_STR_EX,
LIT_NUMBER
} literal_type;
@@ -32,6 +33,7 @@ typedef struct
union
{
ecma_magic_string_id_t magic_str_id;
ecma_magic_string_ex_id_t magic_str_ex_id;
ecma_number_t num;
lp_string lp;
void *none;
+4 -4
View File
@@ -1099,7 +1099,7 @@ dump_prop_name_and_value (operand name, operand value)
JERRY_ASSERT (name.type == OPERAND_LITERAL);
const literal lit = lexer_get_literal_by_id (name.data.lit_id);
operand tmp;
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR)
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX)
{
tmp = dump_string_assignment_res (name.data.lit_id);
}
@@ -1132,7 +1132,7 @@ dump_prop_getter_decl (operand name, operand func)
JERRY_ASSERT (func.type == OPERAND_TMP);
const literal lit = lexer_get_literal_by_id (name.data.lit_id);
operand tmp;
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR)
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX)
{
tmp = dump_string_assignment_res (name.data.lit_id);
}
@@ -1152,7 +1152,7 @@ dump_prop_setter_decl (operand name, operand func)
JERRY_ASSERT (func.type == OPERAND_TMP);
const literal lit = lexer_get_literal_by_id (name.data.lit_id);
operand tmp;
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR)
if (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX)
{
tmp = dump_string_assignment_res (name.data.lit_id);
}
@@ -1348,7 +1348,7 @@ dump_delete (operand res, operand op, bool is_strict, locus loc)
case OPERAND_LITERAL:
{
const literal lit = lexer_get_literal_by_id (op.data.lit_id);
if (lit.type == LIT_MAGIC_STR || lit.type == LIT_STR)
if (lit.type == LIT_MAGIC_STR || lit.type == LIT_MAGIC_STR_EX || lit.type == LIT_STR)
{
syntax_check_delete (is_strict, loc);
switch (res.type)
+2 -2
View File
@@ -180,12 +180,12 @@ syntax_check_for_syntax_errors_in_formal_param_list (bool is_strict, locus loc _
{
JERRY_ASSERT (STACK_ELEMENT (props, i).type == VARG);
const literal previous = STACK_ELEMENT (props, i).lit;
JERRY_ASSERT (previous.type == LIT_STR || previous.type == LIT_MAGIC_STR);
JERRY_ASSERT (previous.type == LIT_STR || previous.type == LIT_MAGIC_STR || previous.type == LIT_MAGIC_STR_EX);
for (uint8_t j = STACK_TOP (U8); j < i; j = (uint8_t) (j + 1))
{
JERRY_ASSERT (STACK_ELEMENT (props, j).type == VARG);
const literal current = STACK_ELEMENT (props, j).lit;
JERRY_ASSERT (current.type == LIT_STR || current.type == LIT_MAGIC_STR);
JERRY_ASSERT (current.type == LIT_STR || current.type == LIT_MAGIC_STR || current.type == LIT_MAGIC_STR_EX);
if (literal_equal_type (previous, current))
{
PARSE_ERROR_VARG ("Duplication of literal '%s' in FormalParameterList is not allowed in strict mode",