Mercurial > pidgin
changeset 17531:21773944db4b
Don't create the temp GString unless it's actually needed, and avoid
doing an strlen() there unless that's really needed.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 07 Jun 2007 05:28:05 +0000 |
parents | a6594c34635b |
children | efb5d0fe4895 |
files | libpurple/plugins/log_reader.c |
diffstat | 1 files changed, 18 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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 <a> 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)