summaryrefslogtreecommitdiff
path: root/stun/debug.c
diff options
context:
space:
mode:
authorFabrice Bellet <fabrice@bellet.info>2016-02-08 20:20:06 +0100
committerOlivier CrĂȘte <olivier.crete@collabora.com>2016-06-20 18:22:15 -0400
commit7ea00f610185ebb55f49fe2b32677a0d279f2530 (patch)
tree17af773718d53b1d0258e761c4f2ed87bfb07471 /stun/debug.c
parent8f74fa48670a927531fa362366c7ee66406e40d1 (diff)
downloadlibnice-7ea00f610185ebb55f49fe2b32677a0d279f2530.tar.gz
stun: avoid expensive call to sprintf in debug-related code
Diffstat (limited to 'stun/debug.c')
-rw-r--r--stun/debug.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/stun/debug.c b/stun/debug.c
index 8efb576..9d3d59b 100644
--- a/stun/debug.c
+++ b/stun/debug.c
@@ -89,6 +89,9 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
size_t i;
size_t prefix_len = strlen (prefix);
char *bytes;
+ char *j;
+ unsigned char k;
+ const char *hex = "0123456789abcdef";
if (!debug_enabled)
return;
@@ -98,9 +101,14 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
strcpy (bytes, prefix);
strcpy (bytes + prefix_len, "0x");
- for (i = 0; i < len; i++)
- sprintf (bytes + prefix_len + 2 + (i * 2), "%02x", ((const unsigned char *)data)[i]);
-
+ j = bytes + prefix_len + 2;
+ for (i = 0; i < len; i++) {
+ k = ((const unsigned char *)data)[i];
+ j[0] = hex[(k & 0xf0) >> 4];
+ j[1] = hex[k & 0xf];
+ j = j + 2;
+ }
+ j[0] = 0;
stun_debug ("%s", bytes);
free (bytes);
}