# HG changeset patch # User Richard Laager # Date 1181194085 0 # Node ID 21773944db4b90f1ff152c5b9c012ddd7efac9f3 # Parent a6594c34635b466c69e20f80b6cc6b33ee9b243e Don't create the temp GString unless it's actually needed, and avoid doing an strlen() there unless that's really needed. diff -r a6594c34635b -r 21773944db4b libpurple/plugins/log_reader.c --- a/libpurple/plugins/log_reader.c Thu Jun 07 05:27:08 2007 +0000 +++ b/libpurple/plugins/log_reader.c Thu Jun 07 05:28:05 2007 +0000 @@ -1467,13 +1467,12 @@ { const char *link; const char *footer = NULL; - GString *temp; - - c = strstr(c, "\n"); + GString *temp = NULL; - if (c) { + if ((c = strstr(c, "\n"))) + { *c = '\0'; - ++c; + c++; } /* Convert links. @@ -1488,7 +1487,6 @@ * * As implemented, this isn't perfect, but it should cover common cases. */ - temp = g_string_sized_new(strlen(line)); while (line && (link = strstr(line, "(Link: "))) { const char *tmp = link; @@ -1505,6 +1503,9 @@ break; } + if (!temp) + temp = g_string_sized_new(c ? (c - 1 - line) : strlen(line)); + g_string_append_len(temp, line, (tmp - line)); /* Start an tag. */ @@ -1543,10 +1544,12 @@ } } - if (line) { - g_string_append(temp, line); + if (temp) + { + if (line) + g_string_append(temp, line); + line = temp->str; } - line = temp->str; if (*line == '[') { const char *timestamp; @@ -1672,21 +1675,19 @@ g_string_append(formatted, line); + line = c; + if (temp) + g_string_free(temp, TRUE); + if (footer) g_string_append(formatted, footer); g_string_append_c(formatted, '\n'); - - g_string_free(temp, TRUE); - - line = c; } g_free(read); - read = formatted->str; - g_string_free(formatted, FALSE); - - return read; + /* XXX: TODO: Avoid this g_strchomp() */ + return g_strchomp(g_string_free(formatted, FALSE)); } static int trillian_logger_size (PurpleLog *log)