urlmatch: use hex2chr() in append_normalized_escapes()

Simplify the code by using hex2chr() to convert and check for invalid characters at the same time instead of doing that sequentially with one table lookup for each. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 8, 2017 at 10:59 UTC 50533135622a80b0326c7e93067e136072bef5eb
1 file changed +5 -5
urlmatch.c
+5 -5
@@ -42,12 +42,12 @@ static int append_normalized_escapes(struct strbuf *buf,
42
43 from_len--;
44 if (ch == '%') {
45 - if (from_len < 2 ||
46 - !isxdigit(from[0]) ||
47 - !isxdigit(from[1]))
45 + if (from_len < 2)
46 return 0;
49 - ch = hexval(*from++) << 4;
50 - ch |= hexval(*from++);
47 + ch = hex2chr(from);
48 + if (ch < 0)
49 + return 0;
50 + from += 2;
51 from_len -= 2;
52 was_esc = 1;
53 }