changeset 29329:4d50162d809e

Put all our rateclass members in a single hash table instead of in one hash table per rateclass. Should reduce memory usage by using 1 hash table instead of 5ish for each flap connection
author Mark Doliner <mark@kingant.net>
date Wed, 03 Feb 2010 01:03:09 +0000
parents 0616027add19
children e3031e5785a3 9cdf9bc6c1ed
files libpurple/protocols/oscar/family_oservice.c libpurple/protocols/oscar/flap_connection.c libpurple/protocols/oscar/oscar.h
diffstat 3 files changed, 11 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/family_oservice.c	Wed Feb 03 00:07:45 2010 +0000
+++ b/libpurple/protocols/oscar/family_oservice.c	Wed Feb 03 01:03:09 2010 +0000
@@ -362,7 +362,6 @@
 		rateclass->last.tv_sec = now.tv_sec - delta / 1000;
 		rateclass->last.tv_usec = now.tv_usec - (delta % 1000) * 1000;
 
-		rateclass->members = g_hash_table_new(g_direct_hash, g_direct_equal);
 		conn->rateclasses = g_slist_prepend(conn->rateclasses, rateclass);
 
 		if (rateclass->classid == OSCAR_DEFAULT_RATECLASS)
@@ -401,9 +400,9 @@
 			subtype = byte_stream_get16(bs);
 
 			if (rateclass != NULL)
-				g_hash_table_insert(rateclass->members,
+				g_hash_table_insert(conn->rateclass_members,
 						GUINT_TO_POINTER((group << 16) + subtype),
-						GUINT_TO_POINTER(TRUE));
+						rateclass);
 		}
 	}
 
--- a/libpurple/protocols/oscar/flap_connection.c	Wed Feb 03 00:07:45 2010 +0000
+++ b/libpurple/protocols/oscar/flap_connection.c	Wed Feb 03 01:03:09 2010 +0000
@@ -106,19 +106,13 @@
 static struct rateclass *
 flap_connection_get_rateclass(FlapConnection *conn, guint16 family, guint16 subtype)
 {
-	GSList *tmp1;
 	gconstpointer key;
+	gpointer rateclass;
 
 	key = GUINT_TO_POINTER((family << 16) + subtype);
-
-	for (tmp1 = conn->rateclasses; tmp1 != NULL; tmp1 = tmp1->next)
-	{
-		struct rateclass *rateclass;
-		rateclass = tmp1->data;
-
-		if (g_hash_table_lookup(rateclass->members, key))
-			return rateclass;
-	}
+	rateclass = g_hash_table_lookup(conn->rateclass_members, key);
+	if (rateclass != NULL)
+		return rateclass;
 
 	return conn->default_rateclass;
 }
@@ -346,6 +340,7 @@
 	conn->fd = -1;
 	conn->subtype = -1;
 	conn->type = type;
+	conn->rateclass_members = g_hash_table_new(g_direct_hash, g_direct_equal);
 
 	od->oscar_connections = g_slist_prepend(od->oscar_connections, conn);
 
@@ -413,13 +408,6 @@
 	conn->buffer_outgoing = NULL;
 }
 
-static void
-flap_connection_destroy_rateclass(struct rateclass *rateclass)
-{
-	g_hash_table_destroy(rateclass->members);
-	g_free(rateclass);
-}
-
 /**
  * Free a FlapFrame
  *
@@ -507,10 +495,12 @@
 	g_slist_free(conn->groups);
 	while (conn->rateclasses != NULL)
 	{
-		flap_connection_destroy_rateclass(conn->rateclasses->data);
+		g_free(conn->rateclasses->data);
 		conn->rateclasses = g_slist_delete_link(conn->rateclasses, conn->rateclasses);
 	}
 
+	g_hash_table_destroy(conn->rateclass_members);
+
 	if (conn->queued_snacs) {
 		while (!g_queue_is_empty(conn->queued_snacs))
 		{
--- a/libpurple/protocols/oscar/oscar.h	Wed Feb 03 00:07:45 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.h	Wed Feb 03 01:03:09 2010 +0000
@@ -446,6 +446,7 @@
 	GSList *groups;
 	GSList *rateclasses; /* Contains nodes of struct rateclass. */
 	struct rateclass *default_rateclass;
+	GHashTable *rateclass_members; /* Key is family and subtype, value is pointer to the rateclass struct to use. */
 
 	GQueue *queued_snacs; /**< Contains QueuedSnacs. */
 	GQueue *queued_lowpriority_snacs; /**< Contains QueuedSnacs to send only once queued_snacs is empty */
@@ -1687,7 +1688,6 @@
 	guint32 current;
 	guint32 max;
 	guint8 dropping_snacs;
-	GHashTable *members; /* Key is family and subtype, value is TRUE. */
 
 	struct timeval last; /**< The time when we last sent a SNAC of this rate class. */
 };