changeset 22269:0e68dab2a362

Patch from oliver: In message.c in the escape & unescape functions the loops are not optimal, doing a strlen() for each character in the message string. valgrind/callgrind identified especially msim_unescape() as a expensive because of that (guess there is more unescaping going on than escaping). The attached patch moves the strlen() out of the loop header for both functions. Closes #4790.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 09 Feb 2008 02:22:30 +0000
parents 1f3481447197
children c2115e5e613d
files libpurple/protocols/myspace/message.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Wed Feb 06 05:37:32 2008 +0000
+++ b/libpurple/protocols/myspace/message.c	Sat Feb 09 02:22:30 2008 +0000
@@ -50,11 +50,12 @@
 {
 	GString *gs;
 	guint i, j;
+	guint msg_len;
 
 	gs = g_string_new("");
-
+	msg_len = strlen(msg);	
 
-	for (i = 0; i < strlen(msg); ++i) {
+	for (i = 0; i < msg_len; ++i) {
 		struct MSIM_ESCAPE_REPLACEMENT *replacement;
 		gchar *replace;
 
@@ -93,10 +94,12 @@
 {
 	GString *gs;
 	guint i, j;
+	guint msg_len;
 
 	gs = g_string_new("");
+	msg_len = strlen(msg);	
 
-	for (i = 0; i < strlen(msg); ++i) {
+	for (i = 0; i < msg_len; ++i) {
 		struct MSIM_ESCAPE_REPLACEMENT *replacement;
 		gchar replace;
 
@@ -105,7 +108,7 @@
 		for (j = 0; (replacement = &msim_escape_replacements[j]) &&
 				replacement->code != NULL; ++j) {
 			if (msg[i] == replacement->code[0] &&
-			    i + 1 < strlen(msg) &&
+			    i + 1 < msg_len &&
 			    msg[i + 1] == replacement->code[1]) {
 				replace = replacement->text;
 				++i;