summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: acc226d)
raw | patch | inline | side by side (parent: acc226d)
author | Florian Forster <octo@collectd.org> | |
Thu, 11 Jul 2013 08:12:54 +0000 (10:12 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 11 Jul 2013 08:12:54 +0000 (10:12 +0200) |
snprintf() is very expensive and the alternative is simple. This shaves
off about 7% of the time spent handling events.
off about 7% of the time spent handling events.
src/statsd.c | patch | blob | history |
diff --git a/src/statsd.c b/src/statsd.c
index 2ba42bfdd121f029eeb18c1af10e073d3006d11f..b8fee175574334521120642c78714e80d2db6e84 100644 (file)
--- a/src/statsd.c
+++ b/src/statsd.c
static statsd_metric_t *statsd_metric_lookup_unsafe (char const *name,
metric_type_t type)
{
- char const *prefix;
char key[DATA_MAX_NAME_LEN + 2];
char *key_copy;
statsd_metric_t *metric;
switch (type)
{
- case STATSD_COUNTER: prefix = "c"; break;
- case STATSD_TIMER: prefix = "t"; break;
- case STATSD_GAUGE: prefix = "g"; break;
- case STATSD_SET: prefix = "s"; break;
+ case STATSD_COUNTER: key[0] = 'c'; break;
+ case STATSD_TIMER: key[0] = 't'; break;
+ case STATSD_GAUGE: key[0] = 'g'; break;
+ case STATSD_SET: key[0] = 's'; break;
default: return (NULL);
}
- ssnprintf (key, sizeof (key), "%s:%s", prefix, name);
+ key[1] = ':';
+ sstrncpy (&key[2], name, sizeof (key) - 2);
status = c_avl_get (metrics_tree, key, (void *) &metric);
if (status == 0)