]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: sample: use iststop instead of a for loop
authorJerome Magnin <jmagnin@haproxy.com>
Fri, 21 Feb 2020 09:49:12 +0000 (10:49 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Feb 2020 10:53:18 +0000 (11:53 +0100)
In sample_fetch_path we can use iststop() instead of a for loop
to find the '?' and return the correct length. This requires commit
"MINOR: ist: add an iststop() function".

src/http_fetch.c

index bf4c00680920e1fa48bb915c9ba8880d88f9c617..29a5d17d82ef7ba1d1b04349ad31f95bdcb4a721 100644 (file)
@@ -982,23 +982,19 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char
        struct htx *htx = smp_prefetch_htx(smp, chn, 1);
        struct htx_sl *sl;
        struct ist path;
-       size_t len;
 
        if (!htx)
                return 0;
 
        sl = http_get_stline(htx);
-       path = http_get_path(htx_sl_req_uri(sl));
+       path = iststop(http_get_path(htx_sl_req_uri(sl)), '?');
        if (!path.ptr)
                return 0;
 
-       for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
-               ;
-
        /* OK, we got the '/' ! */
        smp->data.type = SMP_T_STR;
        smp->data.u.str.area = path.ptr;
-       smp->data.u.str.data = len;
+       smp->data.u.str.data = path.len;
        smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
        return 1;
 }