Commit 7ea00f61 authored by Fabrice Bellet's avatar Fabrice Bellet Committed by Olivier Crête

stun: avoid expensive call to sprintf in debug-related code

parent 8f74fa48
...@@ -89,6 +89,9 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len) ...@@ -89,6 +89,9 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
size_t i; size_t i;
size_t prefix_len = strlen (prefix); size_t prefix_len = strlen (prefix);
char *bytes; char *bytes;
char *j;
unsigned char k;
const char *hex = "0123456789abcdef";
if (!debug_enabled) if (!debug_enabled)
return; return;
...@@ -98,9 +101,14 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len) ...@@ -98,9 +101,14 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
strcpy (bytes, prefix); strcpy (bytes, prefix);
strcpy (bytes + prefix_len, "0x"); strcpy (bytes + prefix_len, "0x");
for (i = 0; i < len; i++) j = bytes + prefix_len + 2;
sprintf (bytes + prefix_len + 2 + (i * 2), "%02x", ((const unsigned char *)data)[i]); 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); stun_debug ("%s", bytes);
free (bytes); free (bytes);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment