im.pidgin.pidgin: 72a2b71dfe259097d115f67e0442fb44934ce686
jeff2 at soc.pidgin.im
jeff2 at soc.pidgin.im
Fri Feb 8 21:25:40 EST 2008
-----------------------------------------------------------------
Revision: 72a2b71dfe259097d115f67e0442fb44934ce686
Ancestor: c68bf74889268c55c15cf101e1d593966b55c2a9
Author: jeff2 at soc.pidgin.im
Date: 2008-02-09T02:22:30
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/72a2b71dfe259097d115f67e0442fb44934ce686
Modified files:
libpurple/protocols/myspace/message.c
ChangeLog:
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.
-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/message.c ba8b2b07ae68f22d15e6f95f3ebb95cade25ddaa
+++ libpurple/protocols/myspace/message.c 885db9035efc4525e67fd63b01268e05704dfee0
@@ -50,11 +50,12 @@ msim_escape(const gchar *msg)
{
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 @@ msim_unescape(const gchar *msg)
{
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 @@ msim_unescape(const gchar *msg)
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;
More information about the Commits
mailing list