Revision 3ebbd00cf3c5a7c6f90e2fed8adaf0c5145fb4ac authored by Jim Hill on 31 May 2015, 18:16:45 UTC, committed by Junio C Hamano on 10 August 2015, 19:51:13 UTC
The loop in strbuf_read() uses xread() repeatedly while extending
the strbuf until the call returns zero.  If the buffer is
sufficiently large to begin with, this results in xread()
returning the remainder of the file to the end (returning
non-zero), the loop extending the strbuf, and then making another
call to xread() to have it return zero.

By using read_in_full(), we can tell when the read reached the end
of file: when it returns less than was requested, it's eof.  This
way we can avoid an extra iteration that allocates an extra 8kB
that is never used.

Signed-off-by: Jim Hill <gjthill@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 282616c
Raw File
test-ctype.c
#include "cache.h"

static int rc;

static void report_error(const char *class, int ch)
{
	printf("%s classifies char %d (0x%02x) wrongly\n", class, ch, ch);
	rc = 1;
}

static int is_in(const char *s, int ch)
{
	/* We can't find NUL using strchr.  It's classless anyway. */
	if (ch == '\0')
		return 0;
	return !!strchr(s, ch);
}

#define TEST_CLASS(t,s) {			\
	int i;					\
	for (i = 0; i < 256; i++) {		\
		if (is_in(s, i) != t(i))	\
			report_error(#t, i);	\
	}					\
}

#define DIGIT "0123456789"
#define LOWER "abcdefghijklmnopqrstuvwxyz"
#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

int main(int argc, char **argv)
{
	TEST_CLASS(isdigit, DIGIT);
	TEST_CLASS(isspace, " \n\r\t");
	TEST_CLASS(isalpha, LOWER UPPER);
	TEST_CLASS(isalnum, LOWER UPPER DIGIT);
	TEST_CLASS(is_glob_special, "*?[\\");
	TEST_CLASS(is_regex_special, "$()*+.?[\\^{|");
	TEST_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~");

	return rc;
}
back to top