OPTIM: http: improve branching in chunk size parser

By tweaking a bit some conditions in http_parse_chunk_size(), we could
improve the overall performance in the worst case by 15%.
This commit is contained in:
Willy Tarreau 2013-04-02 01:26:55 +02:00
parent bf43927cd7
commit 0161d62d23
2 changed files with 9 additions and 9 deletions

View File

@ -187,9 +187,9 @@ extern int ishex(char s);
*/ */
static inline int hex2i(int c) static inline int hex2i(int c)
{ {
if ((unsigned char)(c -= '0') > 9) { if (unlikely((unsigned char)(c -= '0') > 9)) {
if ((unsigned char)(c -= 'A' - '0') > 5 && if (likely((unsigned char)(c -= 'A' - '0') > 5 &&
(unsigned char)(c -= 'a' - 'A') > 5) (unsigned char)(c -= 'a' - 'A') > 5))
c = -11; c = -11;
c += 10; c += 10;
} }

View File

@ -1776,7 +1776,7 @@ static inline int http_parse_chunk_size(struct http_msg *msg)
c = hex2i(*ptr); c = hex2i(*ptr);
if (c < 0) /* not a hex digit anymore */ if (c < 0) /* not a hex digit anymore */
break; break;
if (++ptr >= end) if (unlikely(++ptr >= end))
ptr = buf->data; ptr = buf->data;
if (chunk & 0xF8000000) /* integer overflow will occur if result >= 2GB */ if (chunk & 0xF8000000) /* integer overflow will occur if result >= 2GB */
goto error; goto error;
@ -1784,13 +1784,13 @@ static inline int http_parse_chunk_size(struct http_msg *msg)
} }
/* empty size not allowed */ /* empty size not allowed */
if (ptr == ptr_old) if (unlikely(ptr == ptr_old))
goto error; goto error;
while (http_is_spht[(unsigned char)*ptr]) { while (http_is_spht[(unsigned char)*ptr]) {
if (++ptr >= end) if (++ptr >= end)
ptr = buf->data; ptr = buf->data;
if (ptr == stop) if (unlikely(ptr == stop))
return 0; return 0;
} }
@ -1838,7 +1838,7 @@ static inline int http_parse_chunk_size(struct http_msg *msg)
* which may or may not be present. We save that into ->next and * which may or may not be present. We save that into ->next and
* ->sov. * ->sov.
*/ */
if (ptr < ptr_old) if (unlikely(ptr < ptr_old))
msg->sov += buf->size; msg->sov += buf->size;
msg->sov += ptr - ptr_old; msg->sov += ptr - ptr_old;
msg->next = buffer_count(buf, buf->p, ptr); msg->next = buffer_count(buf, buf->p, ptr);
@ -1968,7 +1968,7 @@ static inline int http_skip_chunk_crlf(struct http_msg *msg)
} }
ptr++; ptr++;
if (ptr >= buf->data + buf->size) if (unlikely(ptr >= buf->data + buf->size))
ptr = buf->data; ptr = buf->data;
/* prepare the CRLF to be forwarded (between ->sol and ->sov) */ /* prepare the CRLF to be forwarded (between ->sol and ->sov) */
msg->sol = 0; msg->sol = 0;