summaryrefslogtreecommitdiff
path: root/src/frames.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-03-19 10:39:24 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2009-03-19 10:39:36 +0000
commitbc46ac8aaf8378b6399f1e81ec19516cabf020d1 (patch)
tree0dd56d2b74598534a1cfbb111bf44bbb026bd9b6 /src/frames.c
parent8d4f996c86a9b1d0dbbb063be20c322927d2509c (diff)
Avoid temporary string allocation.
Diffstat (limited to 'src/frames.c')
-rw-r--r--src/frames.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/frames.c b/src/frames.c
index bddc49f..3be149e 100644
--- a/src/frames.c
+++ b/src/frames.c
@@ -70,7 +70,8 @@ frames_add (Frames *frames,
gint line)
{
Frame *f, *node;
- gchar *tmp;
+ gchar buf[4096];
+ int buf_len;
guint index;
f = frames_get (frames, ip);
@@ -80,13 +81,11 @@ frames_add (Frames *frames,
f = client_perm_alloc (frames->client, sizeof (Frame));
f->ip = ip;
- tmp = NULL;
if (function == NULL && object != NULL)
- tmp = g_strdup_printf ("(within %s)", object);
+ sprintf (buf, "(within %s)", object);
f->function = function ? client_add_string (frames->client, function) :
- object ? client_add_string (frames->client, tmp) :
+ object ? client_add_string (frames->client, buf) :
client_add_string (frames->client, "???");
- g_free (tmp);
f->has_function = function != NULL;
f->object = object ? client_add_string (frames->client, object) : NULL;
@@ -99,24 +98,29 @@ frames_add (Frames *frames,
while (node != NULL && ! srcloc_equal (node, f))
node = node->ht_srcloc_next;
if (node == NULL) {
- GString *string = g_string_new ("");
+ buf_len = 0;
if (function) {
- g_string_append (string, function);
+ buf_len = strlen (function);
+ memcpy (buf, function, buf_len);
if (file == NULL && object != NULL) {
- g_string_append_printf (string, " (in %s)", object);
+ buf_len += snprintf (buf + buf_len,
+ sizeof (buf) - buf_len - 1,
+ " (in %s)", object);
}
} else if (file == NULL && object != NULL) {
- g_string_append_printf (string, "(within %s)", object);
+ buf_len = sprintf (buf, "(within %s)", object);
} else {
- g_string_append (string, "???");
+ memcpy (buf, "???", 3);
+ buf_len = 3;
}
- if (file != NULL)
- g_string_append_printf (string, " (%s:%d)", file, line);
- tmp = g_string_free (string, FALSE);
- f->function_srcloc = client_add_string (frames->client, tmp);
- g_free (tmp);
-
+ if (file != NULL) {
+ buf_len += snprintf (buf + buf_len,
+ sizeof (buf) - buf_len - 1,
+ " (%s:%d)", file, line);
+ }
+ buf[buf_len] = '\0';
+ f->function_srcloc = client_add_string (frames->client, buf);
if (++frames->srcloc.nnodes > 3 * frames->srcloc.size) {
Frame **new_nodes;