Skip to content

Commit 24e3074

Browse files
committed
Optimize block size calculation in functions working with linked list.
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
1 parent af56cd8 commit 24e3074

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

jerry-core/parser/js/collections/linked-list.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ do { \
2929
JERRY_ASSERT (header); \
3030
} while (0);
3131

32-
static size_t linked_list_block_size (uint16_t element_size)
32+
static size_t linked_list_block_size ()
3333
{
34-
return jsp_mm_recommend_size (sizeof (linked_list_header) + element_size) - sizeof (linked_list_header);
34+
return jsp_mm_recommend_size (sizeof (linked_list_header) + 1) - sizeof (linked_list_header);
3535
}
3636

3737
linked_list
3838
linked_list_init (uint16_t element_size)
3939
{
40-
size_t size = sizeof (linked_list_header) + linked_list_block_size (element_size);
40+
JERRY_ASSERT (element_size <= linked_list_block_size ());
41+
size_t size = sizeof (linked_list_header) + linked_list_block_size ();
4142
linked_list list = (linked_list) jsp_mm_alloc (size);
4243
if (list == null_list)
4344
{
@@ -68,7 +69,7 @@ linked_list_element (linked_list list, size_t element_num)
6869
{
6970
ASSERT_LIST (list);
7071
linked_list_header *header = (linked_list_header *) list;
71-
size_t block_size = linked_list_block_size (header->element_size);
72+
size_t block_size = linked_list_block_size ();
7273
linked_list raw = list + sizeof (linked_list_header);
7374
if (block_size < header->element_size * (element_num + 1))
7475
{
@@ -91,7 +92,7 @@ linked_list_set_element (linked_list list, size_t element_num, void *element)
9192
{
9293
ASSERT_LIST (list);
9394
linked_list_header *header = (linked_list_header *) list;
94-
size_t block_size = linked_list_block_size (header->element_size);
95+
size_t block_size = linked_list_block_size ();
9596
uint8_t *raw = (uint8_t *) (header + 1);
9697
if (block_size < header->element_size * (element_num + 1))
9798
{

0 commit comments

Comments
 (0)