summaryrefslogtreecommitdiffstats
path: root/lib/buffer.c
diff options
context:
space:
mode:
authorGergely Nagy <algernon@balabit.hu>2012-04-16 00:25:46 +0200
committerGergely Nagy <algernon@balabit.hu>2012-04-16 00:25:46 +0200
commit142f411b1305d4c9857532f66e61a895604160a9 (patch)
tree5533070acacfa7e06ab9dc361f896bd5cc8e8976 /lib/buffer.c
parent0f62005ae51954abd2c1e3eeb30c11c3877bbe07 (diff)
downloadlibumberlog-142f411b1305d4c9857532f66e61a895604160a9.tar.gz
libumberlog-142f411b1305d4c9857532f66e61a895604160a9.tar.xz
libumberlog-142f411b1305d4c9857532f66e61a895604160a9.zip
Improve string escape performance a little
Instead of escaping a string, returning a new one and running strlen() on that, use an output variable to store the length, since we can easily calculate that during the escape process anyway. This should shave off a tiny bit of CPU time. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Diffstat (limited to 'lib/buffer.c')
-rw-r--r--lib/buffer.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/buffer.c b/lib/buffer.c
index 8bdb3ef..3d92224 100644
--- a/lib/buffer.c
+++ b/lib/buffer.c
@@ -55,7 +55,7 @@ static const unsigned char json_exceptions[] =
};
static inline char *
-_ul_str_escape (const char *str)
+_ul_str_escape (const char *str, size_t *length)
{
const unsigned char *p;
char *dest;
@@ -139,6 +139,8 @@ _ul_str_escape (const char *str)
}
*q = 0;
+ if (length)
+ *length = q - dest;
return dest;
}
@@ -170,19 +172,16 @@ ul_buffer_append (ul_buffer_t *buffer, const char *key, const char *value)
char *k, *v;
size_t lk, lv;
- k = _ul_str_escape (key);
+ k = _ul_str_escape (key, &lk);
if (!k)
return NULL;
- v = _ul_str_escape (value);
+ v = _ul_str_escape (value, &lv);
if (!v)
{
free (k);
return NULL;
}
- lk = strlen (k);
- lv = strlen (v);
-
buffer = _ul_buffer_ensure_size (buffer, buffer->len + lk + lv + 6);
if (!buffer)
{