From 0a0df482ce40db64e6d6f0e7c84d5217eeae8191 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Wed, 17 Dec 2008 13:46:03 +0000 Subject: [PATCH 1/1] Slightly simplify traversing declaration lists. [r24750] --- ast2firm.c | 33 ++++++++++++++++----------------- walk_statements.c | 6 ++---- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/ast2firm.c b/ast2firm.c index 020a3d2..e558b9b 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -4456,20 +4456,21 @@ static void initialize_local_declaration(entity_t *entity) static void declaration_statement_to_firm(declaration_statement_t *statement) { - entity_t * entity = statement->declarations_begin; - entity_t *const last = statement->declarations_end; - if (entity != NULL) { - for ( ;; entity = entity->base.next) { - if (is_declaration(entity)) { - initialize_local_declaration(entity); - } else if (entity->kind == ENTITY_TYPEDEF) { - type_t *const type = skip_typeref(entity->typedefe.type); - if (is_type_array(type) && type->array.is_vla) - get_vla_size(&type->array); - } - if (entity == last) - break; + entity_t *entity = statement->declarations_begin; + if (entity == NULL) + return; + + entity_t *const last = statement->declarations_end; + for ( ;; entity = entity->base.next) { + if (is_declaration(entity)) { + initialize_local_declaration(entity); + } else if (entity->kind == ENTITY_TYPEDEF) { + type_t *const type = skip_typeref(entity->typedefe.type); + if (is_type_array(type) && type->array.is_vla) + get_vla_size(&type->array); } + if (entity == last) + break; } } @@ -5272,7 +5273,8 @@ static int count_local_variables(const entity_t *entity, const entity_t *const last) { int count = 0; - for (; entity != NULL; entity = entity->base.next) { + entity_t const *const end = last != NULL ? last->base.next : NULL; + for (; entity != end; entity = entity->base.next) { type_t *type; bool address_taken; @@ -5288,9 +5290,6 @@ static int count_local_variables(const entity_t *entity, if (!address_taken && is_type_scalar(type)) ++count; - - if (entity == last) - break; } return count; } diff --git a/walk_statements.c b/walk_statements.c index ef3c549..8edc790 100644 --- a/walk_statements.c +++ b/walk_statements.c @@ -125,7 +125,8 @@ static void walk_declarations(const entity_t* entity, statement_callback const callback, void *const env) { - for (; entity != NULL; entity = entity->base.next) { + entity_t const *const end = last != NULL ? last->base.next : NULL; + for (; entity != end; entity = entity->base.next) { /* we only look at variables */ if (entity->kind != ENTITY_VARIABLE) continue; @@ -135,9 +136,6 @@ static void walk_declarations(const entity_t* entity, if (initializer != NULL) { walk_initializer(initializer, callback, env); } - - if (entity == last) - break; } } -- 2.20.1