pidgin: c98a0a22: Put all our rateclass members in a singl...

markdoliner at pidgin.im markdoliner at pidgin.im
Tue Feb 2 20:05:41 EST 2010


-----------------------------------------------------------------
Revision: c98a0a224b48d68f530d5fdc5d306ac735c87e0d
Ancestor: 2b7a217b3bbed7bf35801e2c2989dadb8218cee0
Author: markdoliner at pidgin.im
Date: 2010-02-03T01:03:09
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c98a0a224b48d68f530d5fdc5d306ac735c87e0d

Modified files:
        libpurple/protocols/oscar/family_oservice.c
        libpurple/protocols/oscar/flap_connection.c
        libpurple/protocols/oscar/oscar.h

ChangeLog: 

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

-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/family_oservice.c	630c71e7b714f6e728b3300313840fb8577a364d
+++ libpurple/protocols/oscar/family_oservice.c	1ac0a3fc6c73a1a93289c4ce300094ec77d2e4ef
@@ -362,7 +362,6 @@ rateresp(OscarData *od, FlapConnection *
 		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 @@ rateresp(OscarData *od, FlapConnection *
 			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);
 		}
 	}
 
============================================================
--- libpurple/protocols/oscar/flap_connection.c	b8c3ede57e748caa9083f0349cc5481225392e9c
+++ libpurple/protocols/oscar/flap_connection.c	19e7d70825751cca88fab282dd601e81835d4146
@@ -106,20 +106,14 @@ flap_connection_get_rateclass(FlapConnec
 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);
+	rateclass = g_hash_table_lookup(conn->rateclass_members, key);
+	if (rateclass != NULL)
+		return rateclass;
 
-	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;
-	}
-
 	return conn->default_rateclass;
 }
 
@@ -346,6 +340,7 @@ flap_connection_new(OscarData *od, int t
 	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 @@ flap_connection_close(OscarData *od, Fla
 	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 @@ flap_connection_destroy_cb(gpointer data
 	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))
 		{
============================================================
--- libpurple/protocols/oscar/oscar.h	441ccf173523c102846537f8fcdc552e3d96f5f5
+++ libpurple/protocols/oscar/oscar.h	cadfcafae1171988f9e4aca916d6f0abeeeb1b75
@@ -446,6 +446,7 @@ struct _FlapConnection
 	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 @@ struct rateclass {
 	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. */
 };


More information about the Commits mailing list