pidgin: e33dac1f: optimization to the oscar prpl to use le...

markdoliner at pidgin.im markdoliner at pidgin.im
Tue Feb 2 19:10:42 EST 2010


-----------------------------------------------------------------
Revision: e33dac1f291b0e2ad9f4093e375baff5a16a2005
Ancestor: 8e3f88b957056f7fa511fcff0d4fd2af7269d36e
Author: markdoliner at pidgin.im
Date: 2010-02-03T00:05:22
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/e33dac1f291b0e2ad9f4093e375baff5a16a2005

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

ChangeLog: 

optimization to the oscar prpl to use less memory, care of Shaun Lindsay
at Meebo.  I suspect this will save a few kilobytes per AIM or ICQ account.

-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/family_oservice.c	133785f91cdb61381e36e6d5cd3b7b0229bf0e09
+++ libpurple/protocols/oscar/family_oservice.c	630c71e7b714f6e728b3300313840fb8577a364d
@@ -27,6 +27,24 @@
 
 #include "cipher.h"
 
+/*
+ * Each time we make a FLAP connection to an oscar server the server gives
+ * us a list of rate classes.  Each rate class has different properties for
+ * how frequently we can send SNACs in that rate class before we become
+ * throttled or disconnected.
+ *
+ * The server also gives us a list of every available SNAC and tells us which
+ * rate class it's in.  There are a lot of different SNACs, so this list can be
+ * fairly large.  One important characteristic of these rate classes is that
+ * currently (and since at least 2004) most SNACs are in the same rate class.
+ *
+ * One optimization we can do to save memory is to only keep track of SNACs
+ * that are in classes other than this default rate class.  So if we try to
+ * look up a SNAC and it's not in our hash table then we can assume that it's
+ * in the default rate class.
+ */
+#define OSCAR_DEFAULT_RATECLASS 1
+
 /* Subtype 0x0002 - Client Online */
 void
 aim_srv_clientready(OscarData *od, FlapConnection *conn)
@@ -346,6 +364,9 @@ rateresp(OscarData *od, FlapConnection *
 
 		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)
+			conn->default_rateclass = rateclass;
 	}
 	conn->rateclasses = g_slist_reverse(conn->rateclasses);
 
@@ -361,6 +382,15 @@ rateresp(OscarData *od, FlapConnection *
 		classid = byte_stream_get16(bs);
 		count = byte_stream_get16(bs);
 
+		if (classid == OSCAR_DEFAULT_RATECLASS) {
+			/*
+			 * Don't bother adding these SNACs to the hash table.  See the
+			 * comment for OSCAR_DEFAULT_RATECLASS at the top of this file.
+			 */
+			byte_stream_advance(bs, 4 * count);
+			continue;
+		}
+
 		rateclass = rateclass_find(conn->rateclasses, classid);
 
 		for (j = 0; j < count; j++)
============================================================
--- libpurple/protocols/oscar/flap_connection.c	cb6ba63007912e939e538e26c123a1b3eef77397
+++ libpurple/protocols/oscar/flap_connection.c	07819f2d2d29b9ebb23c052fead289767b4fce34
@@ -120,7 +120,7 @@ flap_connection_get_rateclass(FlapConnec
 			return rateclass;
 	}
 
-	return NULL;
+	return conn->default_rateclass;
 }
 
 /*
============================================================
--- libpurple/protocols/oscar/oscar.h	64005c277e3ac960bb0f1d15a1d8946ce5fadd16
+++ libpurple/protocols/oscar/oscar.h	441ccf173523c102846537f8fcdc552e3d96f5f5
@@ -445,6 +445,7 @@ struct _FlapConnection
 	guint16 seqnum_in; /**< The sequence number of most recently received packet. */
 	GSList *groups;
 	GSList *rateclasses; /* Contains nodes of struct rateclass. */
+	struct rateclass *default_rateclass;
 
 	GQueue *queued_snacs; /**< Contains QueuedSnacs. */
 	GQueue *queued_lowpriority_snacs; /**< Contains QueuedSnacs to send only once queued_snacs is empty */


More information about the Commits mailing list