dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 2/1] st.c: simplify st_foreach/st_foreach_check
Date: Sat, 4 Oct 2014 01:43:22 +0000	[thread overview]
Message-ID: <st-ll-foreach-simple@whir> (raw)
In-Reply-To: <20141003222601.GA19354@dcvr.yhbt.net>

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

  reply	other threads:[~2014-10-04  1:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-22 18:41 [PATCH] st.c: use ccan linked-list Eric Wong
2014-09-22 18:46 ` benchmarks on Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz Eric Wong
2014-09-22 23:18 ` bench results on AMD Phenom II X4 945 Eric Wong
2014-10-02 18:48 ` [PATCH 2/1] st.c: fix up st_foreach* for ccan linked-list Eric Wong
2014-10-03 22:26   ` Eric Wong
2014-10-04  1:43     ` Eric Wong [this message]
2014-10-04  6:21       ` st-ll v2 bench results on AMD FX-8320 Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=st-ll-foreach-simple@whir \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).