From 383c47f538974f57a1a5c7d1b174ce365fdd8698 Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Tue, 8 Aug 2023 16:55:58 -0400 Subject: [PATCH] [ruby/yarp] Separate yp_node_flags_t from yp_node_type_t Prior to this commit, we folded the flags into the type. This created extra overhead when calculating the type and setting the flags. This commit separates them. https://github.com/ruby/yarp/commit/b783a5678c --- yarp/yarp.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/yarp/yarp.c b/yarp/yarp.c index 4cf58cbc3a..71b7e2f895 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -505,7 +505,7 @@ yp_statements_node_body_append(yp_statements_node_t *node, yp_node_t *statement) // implement our own arena allocation. static inline void * yp_alloc_node(YP_ATTRIBUTE_UNUSED yp_parser_t *parser, size_t size) { - void *memory = malloc(size); + void *memory = calloc(1, size); if (memory == NULL) { fprintf(stderr, "Failed to allocate %zu bytes\n", size); abort(); @@ -2289,7 +2289,8 @@ yp_if_node_create(yp_parser_t *parser, *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE, + .flags = YP_NODE_FLAG_NEWLINE, + .type = YP_NODE_IF_NODE, .location = { .start = if_keyword->start, .end = end @@ -2315,7 +2316,8 @@ yp_if_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const yp_t *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE, + .flags = YP_NODE_FLAG_NEWLINE, + .type = YP_NODE_IF_NODE, .location = { .start = statement->location.start, .end = predicate->location.end @@ -2347,7 +2349,8 @@ yp_if_node_ternary_create(yp_parser_t *parser, yp_node_t *predicate, yp_node_t * *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE, + .flags = YP_NODE_FLAG_NEWLINE, + .type = YP_NODE_IF_NODE, .location = { .start = predicate->location.start, .end = false_expression->location.end, @@ -3751,7 +3754,7 @@ yp_statements_node_body_append(yp_statements_node_t *node, yp_node_t *statement) node->base.location.end = statement->location.end; // Every statement gets marked as a place where a newline can occur. - statement->type |= YP_NODE_FLAG_NEWLINE; + statement->flags = YP_NODE_FLAG_NEWLINE; } // Allocate a new StringConcatNode node. @@ -3982,7 +3985,8 @@ yp_unless_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_node_t *node = (yp_unless_node_t) { { - .type = YP_NODE_UNLESS_NODE | YP_NODE_FLAG_NEWLINE, + .flags = YP_NODE_FLAG_NEWLINE, + .type = YP_NODE_UNLESS_NODE, .location = { .start = keyword->start, .end = end @@ -4008,7 +4012,8 @@ yp_unless_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const *node = (yp_unless_node_t) { { - .type = YP_NODE_UNLESS_NODE | YP_NODE_FLAG_NEWLINE, + .flags = YP_NODE_FLAG_NEWLINE, + .type = YP_NODE_UNLESS_NODE, .location = { .start = statement->location.start, .end = predicate->location.end