This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cluster: STABLE3 - qdisk: optimize list append operations


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=1bd2905ffd9b6d414b88c2d0200067292f83ca33
Commit:        1bd2905ffd9b6d414b88c2d0200067292f83ca33
Parent:        eadf95f2a6e0ee01af107921ab7c3b306df32fb9
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:37:55 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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]