optimize performance

Reduce memory allocation times

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-11-14 22:17:06 +08:00
parent f9184839ff
commit 3112b9477e
2 changed files with 2 additions and 2 deletions

View File

@ -49,7 +49,7 @@ size_t uh_buf_append(struct uh_buf *buf, const void *data, size_t len)
return 0; return 0;
if (buf->len + len > buf->size) { if (buf->len + len > buf->size) {
if (uh_buf_grow(buf, len * UH_BUF_SIZE_MULTIPLIER) == -1) if (uh_buf_grow(buf, len << UH_BUF_SIZE_MULTIPLIER) == -1)
len = buf->size - buf->len; len = buf->size - buf->len;
} }

View File

@ -5,7 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#define UH_BUF_SIZE_MULTIPLIER 1.5 #define UH_BUF_SIZE_MULTIPLIER 3
struct uh_buf { struct uh_buf {
char *base; /* Buffer pointer */ char *base; /* Buffer pointer */