BUG/MINOR: samples: fix unnecessary memcopy converting binary to string.
(cherry picked from commit 4b9e80268ec15f6f3db85e53a5ab9c6dbf920264)
diff --git a/src/sample.c b/src/sample.c
index 8e62640..7b70f4d 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -497,27 +497,20 @@
return 1;
}
-/* The sample is always copied into a new one so that smp->size is always
- * valid. The NULL char always enforces the end of string if it is met.
+/*
+ * The NULL char always enforces the end of string if it is met.
+ * Data is never changed, so we can ignore the CONST case
*/
static int c_bin2str(struct sample *smp)
{
- struct chunk *trash = get_trash_chunk();
- unsigned char c;
- int ptr = 0;
+ int i;
- while (ptr < smp->data.str.len) {
- c = smp->data.str.str[ptr];
- if (!c)
+ for (i = 0; i < smp->data.str.len; i++) {
+ if (!smp->data.str.str[i]) {
+ smp->data.str.len = i;
break;
- trash->str[ptr] = c;
- ptr++;
+ }
}
- trash->len = ptr;
- trash->str[ptr] = 0;
- smp->data.str = *trash;
- smp->type = SMP_T_STR;
- smp->flags &= ~SMP_F_CONST;
return 1;
}