changeset 5257:e131ab86ead7

[gaim-migrate @ 5629] our 0(1)-ness is changeloged committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 29 Apr 2003 00:15:21 +0000
parents 1d1c45d9b7fc
children 4ac135a2f422
files ChangeLog src/blist.c src/blist.h
diffstat 3 files changed, 45 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 28 22:53:53 2003 +0000
+++ b/ChangeLog	Tue Apr 29 00:15:21 2003 +0000
@@ -8,6 +8,7 @@
 	  debug levels and categories.
 	* Support for adding chats to your buddy list.
 	* Thanks to all the various people who submitted translation updates
+	* Speed enhancements (Thanks Ethan Blanton).
 
 version 0.62 (04/23/2003):
 	* Keyboard shortcuts in the buddy list work again (Thanks Joe 
--- a/src/blist.c	Mon Apr 28 22:53:53 2003 +0000
+++ b/src/blist.c	Tue Apr 29 00:15:21 2003 +0000
@@ -172,10 +172,12 @@
 		buddy->present = GAIM_BUDDY_SIGNING_ON;
 		gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name);
 		do_timer = TRUE;
+		((struct group *)((GaimBlistNode *)buddy)->parent)->online++;
 	} else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) {
 		buddy->present = GAIM_BUDDY_SIGNING_OFF;
 		gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name);
 		do_timer = TRUE;
+		((struct group *)((GaimBlistNode *)buddy)->parent)->online--;
 	}
 
 	if(do_timer) {
@@ -330,6 +332,9 @@
 		/* This chat was already in the list and is
 		 * being moved.
 		 */
+		((struct group *)cnode->parent)->totalsize--;
+		if (chat->account->gc)
+			((struct group *)cnode->parent)->currentsize--;
 		if(cnode->next)
 			cnode->next->prev = cnode->prev;
 		if(cnode->prev)
@@ -349,10 +354,16 @@
 		cnode->prev = n;
 		cnode->parent = n->parent;
 		n->next = cnode;
+		((struct group *)n->parent)->totalsize++;
+		if (chat->account->gc)
+			((struct group *)n->parent)->currentsize++;
 	} else {
 		((GaimBlistNode*)g)->child = cnode;
 		cnode->next = cnode->prev = NULL;
 		cnode->parent = (GaimBlistNode*)g;
+		g->totalsize++;
+		if (chat->account->gc)
+			g->currentsize++;
 	}
 
 	if (ops)
@@ -387,6 +398,10 @@
 		/* This buddy was already in the list and is
 		 * being moved.
 		 */
+		((struct group *)bnode->parent)->totalsize--;
+		if (buddy->account->gc)
+			((struct group *)bnode->parent)->currentsize--;
+
 		if(bnode->next)
 			bnode->next->prev = bnode->prev;
 		if(bnode->prev)
@@ -396,8 +411,9 @@
 
 		ops->remove(gaimbuddylist, bnode);
 
-		if (bnode->parent != ((GaimBlistNode*)g))
+		if (bnode->parent != ((GaimBlistNode*)g)) {
 			serv_move_buddy(buddy, (struct group*)bnode->parent, g);
+		}
 		save = TRUE;
 	}
 
@@ -408,11 +424,17 @@
 		((GaimBlistNode*)buddy)->prev = n;
 		((GaimBlistNode*)buddy)->parent = n->parent;
 		n->next = (GaimBlistNode*)buddy;
+		((struct group *)n->parent)->totalsize++;
+		if (buddy->account->gc)
+			((struct group *)n->parent)->currentsize++;
 	} else {
 		((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy;
 		((GaimBlistNode*)buddy)->next = NULL;
 		((GaimBlistNode*)buddy)->prev = NULL;
 		((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g;
+		g->totalsize++;
+		if (buddy->account->gc)
+			g->currentsize++;
 	}
 
 	hb = g_malloc(sizeof(struct _gaim_hbuddy));
@@ -441,6 +463,9 @@
 		struct gaim_blist_ui_ops *ops;
 		g= g_new0(struct group, 1);
 		g->name = g_strdup(name);
+		g->totalsize = 0;
+		g->currentsize = 0;
+		g->online = 0;
 		g->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
 				g_free, g_free);
 		((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE;
@@ -524,6 +549,9 @@
 		node->prev->next = node->next;
 	if (node->next)
 		node->next->prev = node->prev;
+	group->totalsize--;
+	if (buddy->account->gc)
+		group->currentsize--;
 
 	hb.name = normalize(buddy->name);
 	hb.account = buddy->account;
@@ -556,6 +584,9 @@
 		node->prev->next = node->next;
 	if (node->next)
 		node->next->prev = node->prev;
+	group->totalsize--;
+	if (chat->account->gc)
+		group->currentsize--;
 
 	ops->remove(gaimbuddylist, node);
 	g_hash_table_destroy(chat->components);
@@ -680,11 +711,13 @@
 		for(buddy = group->child; buddy; buddy = buddy->next) {
 			if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) {
 				if (account == ((struct buddy*)buddy)->account) {
+					((struct group *)group)->currentsize++;
 					if(ops)
 						ops->update(gaimbuddylist, buddy);
 				}
 			} else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) {
 				if (account == ((struct chat*)buddy)->account) {
+					((struct group *)group)->currentsize++;
 					if(ops)
 						ops->update(gaimbuddylist, buddy);
 				}
@@ -707,12 +740,17 @@
 		for(buddy = group->child; buddy; buddy = buddy->next) {
 			if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) {
 				if (account == ((struct buddy*)buddy)->account) {
+					if (((struct buddy *)buddy)->present)
+						((struct group *)group)->online--;
 					((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE;
+					((struct group *)group)->currentsize--;
 					if(ops)
 						ops->remove(gaimbuddylist, buddy);
 				}
 			} else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) {
 				if (account == ((struct chat*)buddy)->account) {
+					((struct group *)group)->online--;
+					((struct group *)group)->currentsize--;
 					if(ops)
 						ops->remove(gaimbuddylist, buddy);
 				}
@@ -1787,45 +1825,17 @@
 }
 
 int gaim_blist_get_group_size(struct group *group, gboolean offline) {
-	GaimBlistNode *node;
-	int count = 0;
-
 	if(!group)
 		return 0;
 
-	for(node = group->node.child; node; node = node->next) {
-		if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
-			struct buddy *b = (struct buddy *)node;
-			if(b->account->gc || offline)
-				count++;
-		} else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
-			struct chat *chat = (struct chat *)node;
-			if(chat->account->gc || offline)
-				count++;
-		}
-	}
-
-	return count;
+	return offline ? group->totalsize : group->currentsize;
 }
 
 int gaim_blist_get_group_online_count(struct group *group) {
-	GaimBlistNode *node;
-	int count = 0;
-
 	if(!group)
 		return 0;
 
-	for(node = group->node.child; node; node = node->next) {
-		if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
-			struct buddy *b = (struct buddy *)node;
-			if(GAIM_BUDDY_IS_ONLINE(b))
-				count++;
-		} else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
-			count++;
-		}
-	}
-
-	return count;
+	return group->online;
 }
 
 
--- a/src/blist.h	Mon Apr 28 22:53:53 2003 +0000
+++ b/src/blist.h	Tue Apr 29 00:15:21 2003 +0000
@@ -96,6 +96,9 @@
 struct group {
 	GaimBlistNode node;                    /**< The node that this group inherits from */
 	char *name;                            /**< The name of this group. */
+	int totalsize;			       /**< The number of buddies in this group */
+	int currentsize;		       /**< The number of buddies in this group corresponding to online accounts */
+	int online;			       /**< The number of buddies in this group who are currently online */
 	GHashTable *settings;                  /**< per-group settings from the XML buddy list, set by plugins and the likes. */
 };