public inbox for cluster-cvs@sourceware.org help / color / mirror / Atom feed
From: "Fabio M. Di Nitto" <fabbione@fedoraproject.org> To: cluster-cvs-relay@redhat.com Subject: cluster: master - qdisk: optimize list append operations Date: Wed, 11 Feb 2009 10:45:00 -0000 [thread overview] Message-ID: <20090211104524.36BC1120198@lists.fedorahosted.org> (raw) Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=0ff4bc837d6fadeae95061efd64a3e361c68503f Commit: 0ff4bc837d6fadeae95061efd64a3e361c68503f Parent: e4ccc8b70c1c1d518b6a15d1cef9dd63d91db28c Author: Fabio M. Di Nitto <fdinitto@redhat.com> AuthorDate: Wed Feb 11 11:37:55 2009 +0100 Committer: Fabio M. Di Nitto <fdinitto@redhat.com> CommitterDate: Wed Feb 11 11:44:37 2009 +0100 qdisk: optimize list append operations makes list insertion O(1) instead of O(n) - add 'tail' to the structure Signed-off-by: Lon Hohberger <lhh@redhat.com> Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com> --- cman/qdisk/scandisk.c | 23 +++++++++-------------- cman/qdisk/scandisk.h | 3 ++- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cman/qdisk/scandisk.c b/cman/qdisk/scandisk.c index 8851fe3..39acb31 100644 --- a/cman/qdisk/scandisk.c +++ b/cman/qdisk/scandisk.c @@ -97,7 +97,7 @@ static void flush_dev_cache(struct devlisthead *devlisthead) static struct devnode *alloc_list_obj(struct devlisthead *devlisthead, int maj, int min) { - struct devnode *nextnode, *startnode; + struct devnode *nextnode; nextnode = malloc(sizeof(struct devnode)); if (!nextnode) @@ -105,22 +105,17 @@ static struct devnode *alloc_list_obj(struct devlisthead *devlisthead, int maj, memset(nextnode, 0, sizeof(struct devnode)); - if (!devlisthead->devnode) { - devlisthead->devnode = startnode = nextnode; - } else { - startnode = devlisthead->devnode; - while (startnode->next) - startnode = startnode->next; + if (!devlisthead->devnode) + devlisthead->devnode = nextnode; + else + devlisthead->tail->next = nextnode; - /* always append what we find */ - startnode->next = nextnode; - startnode = nextnode; - } + devlisthead->tail = nextnode; - startnode->maj = maj; - startnode->min = min; + nextnode->maj = maj; + nextnode->min = min; - return startnode; + return nextnode; } /* really annoying but we have no way to know upfront how diff --git a/cman/qdisk/scandisk.h b/cman/qdisk/scandisk.h index 6a8aa32..394d153 100644 --- a/cman/qdisk/scandisk.h +++ b/cman/qdisk/scandisk.h @@ -63,6 +63,8 @@ struct devnode { /* each entry can be 0 if we can't scan or < 0 if there are errors */ struct devlisthead { + struct devnode *devnode; /* points to the first entry */ + struct devnode *tail; /* last entry (for fast append) */ time_t cache_timestamp; /* this cache timestamp */ int cache_timeout; /* for how long this cache is valid */ int sysfs; /* set to 1 if we were able to scan @@ -74,7 +76,6 @@ struct devlisthead { * /proc/mdstat */ int mapper; /* set to 1 if we were able to run * something against mapper */ - struct devnode *devnode; /* points to the first entry */ }; typedef void (*devfilter) (struct devnode * cur, void *arg);
reply other threads:[~2009-02-11 10:45 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20090211104524.36BC1120198@lists.fedorahosted.org \ --to=fabbione@fedoraproject.org \ --cc=cluster-cvs-relay@redhat.com \ /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: linkBe 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).