Merge branch 'ks/perf-build-with-autoconf' into maint
[gitweb.git] / pkt-line.c
index 62fdb37079fa31698846044448b5cfb398e45528..30489c60b1d3f8acc002fad31aa68b528757c8da 100644 (file)
@@ -172,27 +172,8 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
 
 static int packet_length(const char *linelen)
 {
-       int n;
-       int len = 0;
-
-       for (n = 0; n < 4; n++) {
-               unsigned char c = linelen[n];
-               len <<= 4;
-               if (c >= '0' && c <= '9') {
-                       len += c - '0';
-                       continue;
-               }
-               if (c >= 'a' && c <= 'f') {
-                       len += c - 'a' + 10;
-                       continue;
-               }
-               if (c >= 'A' && c <= 'F') {
-                       len += c - 'A' + 10;
-                       continue;
-               }
-               return -1;
-       }
-       return len;
+       int val = hex2chr(linelen);
+       return (val < 0) ? val : (val << 8) | hex2chr(linelen + 2);
 }
 
 int packet_read(int fd, char **src_buf, size_t *src_len,