]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: http: improve branching in chunk size parser
authorWilly Tarreau <w@1wt.eu>
Mon, 1 Apr 2013 23:26:55 +0000 (01:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Apr 2013 00:00:57 +0000 (02:00 +0200)
By tweaking a bit some conditions in http_parse_chunk_size(), we could
improve the overall performance in the worst case by 15%.

include/common/standard.h
src/proto_http.c

index 8e88ee547406841cdcfbe8b9a1b606ce2948cb2d..4de4f73433c2277bc67cf8a7581a474e648dd70b 100644 (file)
@@ -187,9 +187,9 @@ extern int ishex(char s);
  */
 static inline int hex2i(int c)
 {
-       if ((unsigned char)(c -= '0') > 9) {
-               if ((unsigned char)(c -= 'A' - '0') > 5 &&
-                   (unsigned char)(c -= 'a' - 'A') > 5)
+       if (unlikely((unsigned char)(c -= '0') > 9)) {
+               if (likely((unsigned char)(c -= 'A' - '0') > 5 &&
+                             (unsigned char)(c -= 'a' - 'A') > 5))
                        c = -11;
                c += 10;
        }
index b85c6aa7f758b807af45512b476690577bf3dc4a..7abfe31d35ada134dfab64e455e5cfc7008e7657 100644 (file)
@@ -1776,7 +1776,7 @@ static inline int http_parse_chunk_size(struct http_msg *msg)
                c = hex2i(*ptr);
                if (c < 0) /* not a hex digit anymore */
                        break;
-               if (++ptr >= end)
+               if (unlikely(++ptr >= end))
                        ptr = buf->data;
                if (chunk & 0xF8000000) /* integer overflow will occur if result >= 2GB */
                        goto error;
@@ -1784,13 +1784,13 @@ static inline int http_parse_chunk_size(struct http_msg *msg)
        }
 
        /* empty size not allowed */
-       if (ptr == ptr_old)
+       if (unlikely(ptr == ptr_old))
                goto error;
 
        while (http_is_spht[(unsigned char)*ptr]) {
                if (++ptr >= end)
                        ptr = buf->data;
-               if (ptr == stop)
+               if (unlikely(ptr == stop))
                        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
         * ->sov.
         */
-       if (ptr < ptr_old)
+       if (unlikely(ptr < ptr_old))
                msg->sov += buf->size;
        msg->sov += ptr - ptr_old;
        msg->next = buffer_count(buf, buf->p, ptr);
@@ -1968,7 +1968,7 @@ static inline int http_skip_chunk_crlf(struct http_msg *msg)
        }
 
        ptr++;
-       if (ptr >= buf->data + buf->size)
+       if (unlikely(ptr >= buf->data + buf->size))
                ptr = buf->data;
        /* prepare the CRLF to be forwarded (between ->sol and ->sov) */
        msg->sol = 0;
@@ -5895,7 +5895,7 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi
                                        }
                                }
                        }
-               /* otherwise we're in HTTP_MSG_DATA or HTTP_MSG_TRAILERS state */
+                       /* otherwise we're in HTTP_MSG_DATA or HTTP_MSG_TRAILERS state */
                }
                else if (msg->msg_state == HTTP_MSG_CHUNK_CRLF) {
                        /* we want the CRLF after the data */