# HG changeset patch # User Jeffrey Connelly # Date 1202523750 0 # Node ID 0e68dab2a362d2d6f4efb1bccdaab718a8717026 # Parent 1f3481447197a5acab423f5f728d4c1f7d280ebc 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. diff -r 1f3481447197 -r 0e68dab2a362 libpurple/protocols/myspace/message.c --- 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;