From: kwc@citi.umich.edu Date: Mon, 3 Jul 2006 22:34:33 +0000 (-0400) Subject: Change default buffer size increment for readline() X-Git-Tag: nfs-utils-1-0-9~20 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=commitdiff_plain;h=ee664fd246d77010af13fb557407c612752a5ea8 Change default buffer size increment for readline() Signed-off-by: Kevin Coffman The readline routine expects much smaller messages than we are passing. Change the default initial allocation and increment value from 128 to 2048. This saves many calls to realloc(). --- diff --git a/utils/gssd/cacheio.c b/utils/gssd/cacheio.c index ac76c06..07658e9 100644 --- a/utils/gssd/cacheio.c +++ b/utils/gssd/cacheio.c @@ -244,6 +244,8 @@ int qword_get_int(char **bpp, int *anint) return 0; } +#define READLINE_BUFFER_INCREMENT 2048 + int readline(int fd, char **buf, int *lenp) { /* read a line into *buf, which is malloced *len long @@ -254,11 +256,11 @@ int readline(int fd, char **buf, int *lenp) int len; if (*lenp == 0) { - char *b = malloc(128); + char *b = malloc(READLINE_BUFFER_INCREMENT); if (b == NULL) return 0; *buf = b; - *lenp = 128; + *lenp = READLINE_BUFFER_INCREMENT; } len = read(fd, *buf, *lenp); if (len <= 0) { @@ -271,7 +273,7 @@ int readline(int fd, char **buf, int *lenp) */ char *new; int nl; - *lenp += 128; + *lenp += READLINE_BUFFER_INCREMENT; new = realloc(*buf, *lenp); if (new == NULL) return 0;