]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: samples: fix unnecessary memcopy converting binary to string.
authorEmeric Brun <ebrun@haproxy.com>
Mon, 3 Nov 2014 17:17:10 +0000 (18:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 24 Nov 2014 16:44:02 +0000 (17:44 +0100)
src/sample.c

index 70f47bbd2255628f76a55ce40f8266806ca7647c..7db506d0a85892684d13fa59ce3691258b2a8b5f 100644 (file)
@@ -499,27 +499,20 @@ static int c_str2ipv6(struct sample *smp)
        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;
 }