From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id F05101F7D5; Sat, 4 Oct 2014 01:43:22 +0000 (UTC) Date: Sat, 4 Oct 2014 01:43:22 +0000 From: Eric Wong To: spew@80x24.org Subject: [PATCH 2/1] st.c: simplify st_foreach/st_foreach_check Message-ID: References: <1411411308-24223-1-git-send-email-e@80x24.org> <20141003222601.GA19354@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141003222601.GA19354@dcvr.yhbt.net> List-Id: The packed-to-unpacked table transition may be simplified. (To be squashed...) --- st.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/st.c b/st.c index 6c697b9..69fa0c1 100644 --- a/st.c +++ b/st.c @@ -884,8 +884,7 @@ st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data int st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t never) { - st_table_entry *ptr, **last, *tmp, *next, *resume_tail = 0; - struct list_head resume_head; + st_table_entry *ptr, **last, *tmp, *next; struct list_head *head; enum st_retval retval; st_index_t i; @@ -905,10 +904,8 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t if (!ptr) goto deleted; } if (table->num_entries == 0) return 0; - resume_head.n = ptr->olist; - head = &resume_head; - next = list_next(st_head(table), ptr, olist); - resume_tail = list_tail(st_head(table), st_table_entry, olist); + head = st_head(table); + next = list_entry(ptr->olist.next, st_table_entry, olist); goto unpacked; } switch (retval) { @@ -968,8 +965,6 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t if (table->num_entries == 0) return 0; } } - - if (resume_tail == ptr) break; } return 0; } @@ -977,9 +972,8 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t int st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) { - st_table_entry *ptr, **last, *tmp, *next, *resume_tail = 0; + st_table_entry *ptr, **last, *tmp, *next; enum st_retval retval; - struct list_head resume_head; struct list_head *head; st_index_t i; @@ -994,10 +988,8 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) if (!table->entries_packed) { FIND_ENTRY(table, ptr, hash, i); if (!ptr) return 0; - resume_head.n = ptr->olist; - head = &resume_head; - next = list_next(st_head(table), ptr, olist); - resume_tail = list_tail(st_head(table), st_table_entry, olist); + head = st_head(table); + next = list_entry(ptr->olist.next, st_table_entry, olist); goto unpacked; } switch (retval) { @@ -1038,8 +1030,6 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) } if (table->num_entries == 0) return 0; } - - if (resume_tail == ptr) break; } return 0; } -- EW