optimize performance
Reduce memory allocation times Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>main
parent
f9184839ff
commit
3112b9477e
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
||||||
|
|
Loading…
Reference in New Issue