diff --git a/jerry-core/parser/js/lexer.cpp b/jerry-core/parser/js/lexer.cpp index d07becc02..dc2ac2949 100644 --- a/jerry-core/parser/js/lexer.cpp +++ b/jerry-core/parser/js/lexer.cpp @@ -166,9 +166,8 @@ adjust_string_ptrs (literal lit, size_t diff) } static literal -add_current_token_to_string_cache (void) +add_string_to_string_cache (const ecma_char_t* str, ecma_length_t length) { - const ecma_length_t length = (ecma_length_t) (buffer - token_start); if (strings_cache_used_size + length * sizeof (ecma_char_t) >= strings_cache_size) { strings_cache_size = mem_heap_recommend_allocation_size (strings_cache_used_size @@ -183,13 +182,19 @@ add_current_token_to_string_cache (void) } strings_cache = temp; } - strncpy ((char *) (strings_cache + strings_cache_used_size), token_start, length); + strncpy ((char *) (strings_cache + strings_cache_used_size), (const char*) str, length); (strings_cache + strings_cache_used_size)[length] = '\0'; const literal res = create_literal_from_zt (strings_cache + strings_cache_used_size, length); strings_cache_used_size = (size_t) (((size_t) length + 1) * sizeof (ecma_char_t) + strings_cache_used_size); return res; } +static literal +add_current_token_to_string_cache (void) +{ + return add_string_to_string_cache ((ecma_char_t*) token_start, (ecma_length_t) (buffer - token_start)); +} + static token convert_current_token_to_token (token_type tt) { @@ -535,7 +540,7 @@ lexer_get_strings_cache (void) } void -lexer_add_literal_if_not_present (literal lit) +lexer_add_keyword_or_numeric_literal_if_not_present (literal lit) { for (literal_index_t i = 0; i < STACK_SIZE (literals); i++) { @@ -544,6 +549,12 @@ lexer_add_literal_if_not_present (literal lit) return; } } + + if (lit.type == LIT_STR) + { + lit = add_string_to_string_cache (lit.data.lp.str, lit.data.lp.length); + } + STACK_PUSH (literals, lit); } diff --git a/jerry-core/parser/js/lexer.h b/jerry-core/parser/js/lexer.h index 2497a5551..40b3e4009 100644 --- a/jerry-core/parser/js/lexer.h +++ b/jerry-core/parser/js/lexer.h @@ -175,7 +175,7 @@ token lexer_prev_token (void); const literal *lexer_get_literals (void); const ecma_char_t *lexer_get_strings_cache (void); -void lexer_add_literal_if_not_present (literal); +void lexer_add_keyword_or_numeric_literal_if_not_present (literal); literal_index_t lexer_get_literals_count (void); literal lexer_get_literal_by_id (literal_index_t); literal_index_t lexer_lookup_literal_uid (literal lit); diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index a98573dc4..3babf7d87 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -226,14 +226,14 @@ parse_property_name (void) case TOK_SMALL_INT: { const literal lit = create_literal_from_num ((ecma_number_t) token_data ()); - lexer_add_literal_if_not_present (lit); + lexer_add_keyword_or_numeric_literal_if_not_present (lit); const literal_index_t lit_id = lexer_lookup_literal_uid (lit); return literal_operand (lit_id); } case TOK_KEYWORD: { const literal lit = create_literal_from_str_compute_len (lexer_keyword_to_string ((keyword) token_data ())); - lexer_add_literal_if_not_present (lit); + lexer_add_keyword_or_numeric_literal_if_not_present (lit); const literal_index_t lit_id = lexer_lookup_literal_uid (lit); return literal_operand (lit_id); } @@ -2486,7 +2486,8 @@ skip_braces (void) skip_newlines (); if (token_is (TOK_COLON)) { - lexer_add_literal_if_not_present (create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); + lexer_add_keyword_or_numeric_literal_if_not_present ( + create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); } else { @@ -2505,7 +2506,8 @@ skip_braces (void) skip_newlines (); if (token_is (TOK_OPEN_PAREN)) { - lexer_add_literal_if_not_present (create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); + lexer_add_keyword_or_numeric_literal_if_not_present ( + create_literal_from_str_compute_len (lexer_keyword_to_string (kw))); } else {