Skip to content

Commit 2725311

Browse files
committed
Remove allocator functions which stores size.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 823e4d0 commit 2725311

File tree

6 files changed

+8
-41
lines changed

6 files changed

+8
-41
lines changed

jerry-core/jmem/jmem-heap.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -408,26 +408,6 @@ jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory siz
408408
return jmem_heap_gc_and_alloc_block (size, true);
409409
} /* jmem_heap_alloc_block_null_on_error */
410410

411-
/**
412-
* Allocate block and store block size.
413-
*
414-
* Note: block will only be aligned to 4 bytes.
415-
*/
416-
inline void * __attr_always_inline___
417-
jmem_heap_alloc_block_store_size (size_t size) /**< required size */
418-
{
419-
if (unlikely (size == 0))
420-
{
421-
return NULL;
422-
}
423-
424-
size += sizeof (jmem_heap_free_t);
425-
426-
jmem_heap_free_t *const data_space_p = (jmem_heap_free_t *) jmem_heap_alloc_block (size);
427-
data_space_p->size = (uint32_t) size;
428-
return (void *) (data_space_p + 1);
429-
} /* jmem_heap_alloc_block_store_size */
430-
431411
/**
432412
* Free the memory block.
433413
*/
@@ -540,17 +520,6 @@ jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the
540520
JMEM_HEAP_STAT_FREE (size);
541521
} /* jmem_heap_free_block */
542522

543-
/**
544-
* Free block with stored size
545-
*/
546-
inline void __attr_always_inline___
547-
jmem_heap_free_block_size_stored (void *ptr) /**< pointer to the memory block */
548-
{
549-
jmem_heap_free_t *const original_p = ((jmem_heap_free_t *) ptr) - 1;
550-
JERRY_ASSERT (original_p + 1 == ptr);
551-
jmem_heap_free_block (original_p, original_p->size);
552-
} /* jmem_heap_free_block_size_stored */
553-
554523
/**
555524
* Compress pointer
556525
*

jerry-core/jmem/jmem-heap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ extern void jmem_heap_finalize (void);
3434
extern void *jmem_heap_alloc_block (const size_t);
3535
extern void *jmem_heap_alloc_block_null_on_error (const size_t);
3636
extern void jmem_heap_free_block (void *, const size_t);
37-
extern void *jmem_heap_alloc_block_store_size (size_t);
38-
extern void jmem_heap_free_block_size_stored (void *);
3937
extern uintptr_t jmem_heap_compress_pointer (const void *);
4038
extern void *jmem_heap_decompress_pointer (uintptr_t);
4139
extern bool jmem_is_heap_pointer (const void *);

jerry-core/parser/js/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ util_free_literal (lexer_literal_t *literal_p) /**< literal */
3838
{
3939
if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
4040
{
41-
jmem_heap_free_block_size_stored ((void *) literal_p->u.char_p);
41+
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
4242
}
4343
}
4444
else if ((literal_p->type == LEXER_FUNCTION_LITERAL)

jerry-core/parser/js/js-lexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ lexer_process_char_literal (parser_context_t *context_p, /**< context */
12021202

12031203
if (has_escape)
12041204
{
1205-
literal_p->u.char_p = (uint8_t *) jmem_heap_alloc_block_store_size (length);
1205+
literal_p->u.char_p = (uint8_t *) jmem_heap_alloc_block (length);
12061206
memcpy ((uint8_t *) literal_p->u.char_p, char_p, length);
12071207
}
12081208
else

jerry-core/parser/js/js-parser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
100100

101101
if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
102102
{
103-
jmem_heap_free_block_size_stored ((void *) char_p);
103+
jmem_heap_free_block ((void *) char_p, literal_p->prop.length);
104104
}
105105
}
106106
}
@@ -522,7 +522,7 @@ parser_generate_initializers (parser_context_t *context_p, /**< context */
522522
if (!context_p->is_show_opcodes
523523
&& !(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
524524
{
525-
jmem_heap_free_block_size_stored ((void *) literal_p->u.char_p);
525+
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
526526
}
527527
#else /* !PARSER_DUMP_BYTE_CODE */
528528
literal_pool_p[literal_p->prop.index] = literal_p->u.value;
@@ -1693,7 +1693,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
16931693
if ((literal_p->type == LEXER_IDENT_LITERAL || literal_p->type == LEXER_STRING_LITERAL)
16941694
&& !(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
16951695
{
1696-
jmem_heap_free_block_size_stored ((void *) literal_p->u.char_p);
1696+
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
16971697
}
16981698
}
16991699
}

tests/unit/test-heap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ test_heap_give_some_memory_back (jmem_free_unused_memory_severity_t severity)
6161
TEST_ASSERT (ptrs[i][k] == 0);
6262
}
6363

64-
jmem_heap_free_block_size_stored (ptrs[i]);
64+
jmem_heap_free_block (ptrs[i], sizes[i]);
6565
ptrs[i] = NULL;
6666
}
6767
}
@@ -86,7 +86,7 @@ main ()
8686
for (uint32_t j = 0; j < test_sub_iters; j++)
8787
{
8888
size_t size = (size_t) rand () % test_threshold_block_size;
89-
ptrs[j] = (uint8_t *) jmem_heap_alloc_block_store_size (size);
89+
ptrs[j] = (uint8_t *) jmem_heap_alloc_block (size);
9090
sizes[j] = size;
9191

9292
TEST_ASSERT (sizes[j] == 0 || ptrs[j] != NULL);
@@ -104,7 +104,7 @@ main ()
104104
TEST_ASSERT (ptrs[j][k] == 0);
105105
}
106106

107-
jmem_heap_free_block_size_stored (ptrs[j]);
107+
jmem_heap_free_block (ptrs[j], sizes[j]);
108108

109109
ptrs[j] = NULL;
110110
}

0 commit comments

Comments
 (0)