[Users] [PATCH 1/3] Avoid strlen() on big buffers, use precomputed length instead
Igor Mammedov
imammedo at redhat.com
Wed Oct 24 23:40:52 CEST 2012
it reduces cost of textview_write_line() from 32% to 3% for big messages
Signed-off-by: Igor Mammedov <imammedo at redhat.com>
---
src/textview.c | 4 +++-
src/textview.h | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/textview.c b/src/textview.c
index d91b3ff..8c4b6e7 100644
--- a/src/textview.c
+++ b/src/textview.c
@@ -1637,6 +1637,7 @@ do_quote:
uri = g_new0(ClickableText, 1);
uri->uri = g_strdup("");
uri->data = g_strdup(buf);
+ uri->data_len = strlen(uri->data);
uri->start = gtk_text_iter_get_offset(&iter);
uri->is_quote = TRUE;
uri->quote_level = real_quotelevel;
@@ -1669,11 +1670,12 @@ do_quote:
textview->prev_quote_level = -1;
goto do_quote;
}
- e_len = lasturi->data ? strlen(lasturi->data):0;
+ e_len = lasturi->data ? lasturi->data_len:0;
n_len = strlen(buf);
lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
strcpy((gchar *)lasturi->data + e_len, buf);
*((gchar *)lasturi->data + e_len + n_len) = '\0';
+ lasturi->data_len += n_len;
}
}
} else {
diff --git a/src/textview.h b/src/textview.h
index a128726..ed36b0b 100644
--- a/src/textview.h
+++ b/src/textview.h
@@ -35,6 +35,7 @@ struct _ClickableText
gchar *filename;
gpointer data;
+ gint data_len;
guint start;
guint end;
--
1.7.11.7
More information about the Users
mailing list