From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 2/1] st.c: fix up st_foreach* for ccan linked-list
Date: Thu, 2 Oct 2014 18:48:13 +0000 [thread overview]
Message-ID: <st-ccan-ll-fixup-1@80x24.org> (raw)
In-Reply-To: <1411411308-24223-1-git-send-email-e@80x24.org>
This needs tests, but it seems the packed => unpacked transitions are
totally untested in the current Ruby implementation. Fortunately,
it seems hash.c bans such transitions.
---
st.c | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/st.c b/st.c
index f08fcb7..10604db 100644
--- a/st.c
+++ b/st.c
@@ -867,9 +867,9 @@ 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;
struct list_head *head;
+ struct list_node *cur, *n;
enum st_retval retval;
st_index_t i;
@@ -882,16 +882,17 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t
hash = PHASH(table, i);
if (key == never) continue;
retval = (*func)(key, val, arg, 0);
- if (!table->entries_packed) {
+ if (!table->entries_packed) { /* XXX untested, never happens */
FIND_ENTRY(table, ptr, hash, i);
if (retval == ST_CHECK) {
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);
+
+ cur = ptr->olist.next;
+ n = cur->next;
+ head = st_head(table);
+ ptr = container_of(cur, struct st_table_entry, olist);
goto unpacked;
}
switch (retval) {
@@ -918,7 +919,10 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t
}
head = st_head(table);
- list_for_each_safe(head, ptr, next, olist) {
+ for (cur = head->n.next, n = cur->next;
+ cur != &head->n;
+ cur = n, n = cur->next) {
+ ptr = container_of(cur, struct st_table_entry, olist);
if (ptr->key != never) {
i = hash_pos(ptr->hash, table->num_bins);
retval = (*func)(ptr->key, ptr->record, arg, 0);
@@ -951,8 +955,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;
}
@@ -960,10 +962,10 @@ 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;
enum st_retval retval;
- struct list_head resume_head;
struct list_head *head;
+ struct list_node *cur, *n;
st_index_t i;
if (table->entries_packed) {
@@ -977,10 +979,11 @@ 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);
+
+ cur = ptr->olist.next;
+ n = cur->next;
+ head = st_head(table);
+ ptr = container_of(cur, struct st_table_entry, olist);
goto unpacked;
}
switch (retval) {
@@ -999,7 +1002,10 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
}
head = st_head(table);
- list_for_each_safe(head, ptr, next, olist) {
+ for (cur = head->n.next, n = cur->next;
+ cur != &head->n;
+ cur = n, n = cur->next) {
+ ptr = container_of(cur, struct st_table_entry, olist);
i = hash_pos(ptr->hash, table->num_bins);
retval = (*func)(ptr->key, ptr->record, arg, 0);
unpacked:
@@ -1021,8 +1027,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
next prev parent reply other threads:[~2014-10-02 18:48 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 ` Eric Wong [this message]
2014-10-03 22:26 ` [PATCH 2/1] st.c: fix up st_foreach* for ccan linked-list Eric Wong
2014-10-04 1:43 ` [PATCH 2/1] st.c: simplify st_foreach/st_foreach_check Eric Wong
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-ccan-ll-fixup-1@80x24.org \
--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).