Skip to content

Commit bfa7692

Browse files
committed
Avoid unnecessary zero-ing of memory
1 parent fb526a8 commit bfa7692

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/prism.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7755,7 +7755,8 @@ parser_lex_magic_comment(pm_parser_t *parser, bool semantic_token_seen) {
77557755
pm_string_free(&key);
77567756

77577757
// Allocate a new magic comment node to append to the parser's list.
7758-
pm_magic_comment_t *magic_comment = (pm_magic_comment_t *) pm_arena_zalloc(&parser->metadata_arena, sizeof(pm_magic_comment_t), PRISM_ALIGNOF(pm_magic_comment_t));
7758+
pm_magic_comment_t *magic_comment = (pm_magic_comment_t *) pm_arena_alloc(&parser->metadata_arena, sizeof(pm_magic_comment_t), PRISM_ALIGNOF(pm_magic_comment_t));
7759+
magic_comment->node.next = NULL;
77597760
magic_comment->key = (pm_location_t) { .start = U32(key_start - parser->start), .length = U32(key_length) };
77607761
magic_comment->value = (pm_location_t) { .start = U32(value_start - parser->start), .length = value_length };
77617762
pm_list_append(&parser->magic_comment_list, (pm_list_node_t *) magic_comment);
@@ -9421,7 +9422,7 @@ parser_lex_callback(pm_parser_t *parser) {
94219422
*/
94229423
static inline pm_comment_t *
94239424
parser_comment(pm_parser_t *parser, pm_comment_type_t type) {
9424-
pm_comment_t *comment = (pm_comment_t *) pm_arena_zalloc(&parser->metadata_arena, sizeof(pm_comment_t), PRISM_ALIGNOF(pm_comment_t));
9425+
pm_comment_t *comment = (pm_comment_t *) pm_arena_alloc(&parser->metadata_arena, sizeof(pm_comment_t), PRISM_ALIGNOF(pm_comment_t));
94259426

94269427
*comment = (pm_comment_t) {
94279428
.type = type,

src/util/pm_line_offset_list.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
void
77
pm_line_offset_list_init(pm_arena_t *arena, pm_line_offset_list_t *list, size_t capacity) {
8-
list->offsets = (uint32_t *) pm_arena_zalloc(arena, capacity * sizeof(uint32_t), PRISM_ALIGNOF(uint32_t));
8+
list->offsets = (uint32_t *) pm_arena_alloc(arena, capacity * sizeof(uint32_t), PRISM_ALIGNOF(uint32_t));
99

10-
// This is 1 instead of 0 because we want to include the first line of the
11-
// file as having offset 0, which is set because of the zero-initialization.
10+
// The first line always has offset 0.
11+
list->offsets[0] = 0;
1212
list->size = 1;
1313
list->capacity = capacity;
1414
}

0 commit comments

Comments
 (0)