From 3cf95b2bc806da03d5512b1cf32a373a57bdf879 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Fri, 1 Dec 2017 14:17:58 +0800 Subject: [PATCH] Optimizing performance by less memory allocation times Signed-off-by: Jianhui Zhao --- src/uhttp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uhttp.c b/src/uhttp.c index 49fe99d..199a16c 100755 --- a/src/uhttp.c +++ b/src/uhttp.c @@ -244,7 +244,7 @@ static void connection_read_cb(struct ev_loop *loop, ev_io *w, int revents) handshake_done: #endif - if (uh_buf_available(buf) < UH_BUFFER_SIZE) { + if (unlikely(uh_buf_available(buf) < 1)) { int off = con->parser.mark - buf->base; uh_buf_grow(buf, UH_BUFFER_SIZE); con->parser.mark = buf->base + off; @@ -252,7 +252,7 @@ handshake_done: base = buf->base + buf->len; - len = uh_ssl_read(con, base, UH_BUFFER_SIZE); + len = uh_ssl_read(con, base, uh_buf_available(buf)); if (unlikely(len <= 0)) { if (con->flags & UH_CON_CLOSE) uh_connection_destroy(con);