Replace array of literals with literal storage.
JerryScript-DCO-1.0-Signed-off-by: Evgeny Gavrin e.gavrin@samsung.com JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
@@ -15,9 +15,7 @@
|
||||
|
||||
#include "linked-list.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
#include "jrt.h"
|
||||
#include "mem-heap.h"
|
||||
#include "lp-string.h"
|
||||
|
||||
typedef struct linked_list_header
|
||||
{
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
|
||||
#include "lit-id-hash-table.h"
|
||||
#include "bytecode-data.h"
|
||||
#include "mem-heap.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
|
||||
lit_id_hash_table *
|
||||
lit_id_hash_table_init (size_t buckets_count, size_t blocks_count)
|
||||
@@ -24,11 +22,11 @@ lit_id_hash_table_init (size_t buckets_count, size_t blocks_count)
|
||||
size_t size = mem_heap_recommend_allocation_size (sizeof (lit_id_hash_table));
|
||||
lit_id_hash_table *table = (lit_id_hash_table *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
|
||||
memset (table, 0, size);
|
||||
size = mem_heap_recommend_allocation_size (sizeof (literal_index_t) * buckets_count);
|
||||
table->raw_buckets = (literal_index_t *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
|
||||
size = mem_heap_recommend_allocation_size (sizeof (lit_cpointer_t) * buckets_count);
|
||||
table->raw_buckets = (lit_cpointer_t *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
|
||||
memset (table->raw_buckets, 0, size);
|
||||
size = mem_heap_recommend_allocation_size (sizeof (literal_index_t *) * blocks_count);
|
||||
table->buckets = (literal_index_t **) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
|
||||
size = mem_heap_recommend_allocation_size (sizeof (lit_cpointer_t *) * blocks_count);
|
||||
table->buckets = (lit_cpointer_t **) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM);
|
||||
memset (table->buckets, 0, size);
|
||||
table->current_bucket_pos = 0;
|
||||
return table;
|
||||
@@ -44,7 +42,7 @@ lit_id_hash_table_free (lit_id_hash_table *table)
|
||||
}
|
||||
|
||||
void
|
||||
lit_id_hash_table_insert (lit_id_hash_table *table, idx_t uid, opcode_counter_t oc, literal_index_t lit_id)
|
||||
lit_id_hash_table_insert (lit_id_hash_table *table, idx_t uid, opcode_counter_t oc, lit_cpointer_t lit_cp)
|
||||
{
|
||||
JERRY_ASSERT (table);
|
||||
size_t block_id = oc / BLOCK_SIZE;
|
||||
@@ -52,11 +50,11 @@ lit_id_hash_table_insert (lit_id_hash_table *table, idx_t uid, opcode_counter_t
|
||||
{
|
||||
table->buckets[block_id] = table->raw_buckets + table->current_bucket_pos;
|
||||
}
|
||||
table->buckets[block_id][uid] = lit_id;
|
||||
table->buckets[block_id][uid] = lit_cp;
|
||||
table->current_bucket_pos++;
|
||||
}
|
||||
|
||||
literal_index_t
|
||||
lit_cpointer_t
|
||||
lit_id_hash_table_lookup (lit_id_hash_table *table, idx_t uid, opcode_counter_t oc)
|
||||
{
|
||||
JERRY_ASSERT (table);
|
||||
|
||||
@@ -19,17 +19,18 @@
|
||||
#include "jrt.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "opcodes.h"
|
||||
#include "lit-literal.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t current_bucket_pos;
|
||||
literal_index_t *raw_buckets;
|
||||
literal_index_t **buckets;
|
||||
lit_cpointer_t *raw_buckets;
|
||||
lit_cpointer_t **buckets;
|
||||
} lit_id_hash_table;
|
||||
|
||||
lit_id_hash_table *lit_id_hash_table_init (size_t, size_t);
|
||||
void lit_id_hash_table_free (lit_id_hash_table *);
|
||||
void lit_id_hash_table_insert (lit_id_hash_table *, idx_t, opcode_counter_t, literal_index_t);
|
||||
literal_index_t lit_id_hash_table_lookup (lit_id_hash_table *, idx_t, opcode_counter_t);
|
||||
void lit_id_hash_table_insert (lit_id_hash_table *, idx_t, opcode_counter_t, lit_cpointer_t);
|
||||
lit_cpointer_t lit_id_hash_table_lookup (lit_id_hash_table *, idx_t, opcode_counter_t);
|
||||
|
||||
#endif /* LIT_ID_HASH_TABLE */
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* 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 "lp-string.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
|
||||
bool
|
||||
lp_string_equal (lp_string s1, lp_string s2)
|
||||
{
|
||||
if (s1.length != s2.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ecma_length_t i = 0; i < s1.length; i++)
|
||||
{
|
||||
JERRY_ASSERT (s1.str[i] != '\0' && s1.str[i] != '\0');
|
||||
if (s1.str[i] != s2.str[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
lp_string_equal_s (lp_string lp, const char *s)
|
||||
{
|
||||
return lp_string_equal_zt (lp, (const ecma_char_t *) s);
|
||||
}
|
||||
|
||||
bool
|
||||
lp_string_equal_zt (lp_string lp, const ecma_char_t *s)
|
||||
{
|
||||
for (ecma_length_t i = 0; i < lp.length; i++)
|
||||
{
|
||||
JERRY_ASSERT (lp.str[i] != '\0');
|
||||
if (lp.str[i] != s[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (s[lp.length] != '\0')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* 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 LP_STRING
|
||||
#define LP_STRING
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/* Length-prefixed or "pascal" string. */
|
||||
typedef struct
|
||||
{
|
||||
const ecma_char_t *str;
|
||||
ecma_length_t length;
|
||||
ecma_string_hash_t hash;
|
||||
} lp_string;
|
||||
|
||||
bool lp_string_equal (lp_string, lp_string);
|
||||
bool lp_string_equal_s (lp_string, const char *);
|
||||
bool lp_string_equal_zt (lp_string, const ecma_char_t *);
|
||||
|
||||
#endif /* LP_STRING */
|
||||
Reference in New Issue
Block a user