tccpe: speed up .def file loading

The fgets replacement meant to work with "int fd"
was just too slow.
This commit is contained in:
grischka 2014-04-13 20:30:46 +02:00
parent aa255f37f2
commit 112148172b

24
tccpe.c
View file

@ -1583,31 +1583,20 @@ static char *trimback(char *a, char *e)
return a; return a;
} }
static char *get_line(char *line, int size, int fd)
{
int n;
for (n = 0; n < size - 1; )
if (read(fd, line + n, 1) < 1 || line[n++] == '\n')
break;
if (0 == n)
return NULL;
trimback(line, line + n);
return trimfront(line);
}
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static int pe_load_def(TCCState *s1, int fd) static int pe_load_def(TCCState *s1, int fd)
{ {
int state = 0, ret = -1, dllindex = 0, ord; int state = 0, ret = -1, dllindex = 0, ord;
char line[400], dllname[80], *p, *x; char line[400], dllname[80], *p, *x;
FILE *fp;
for (;;) { fp = fdopen(dup(fd), "rb");
while (fgets(line, sizeof line, fp))
p = get_line(line, sizeof line, fd); {
if (NULL == p) p = trimfront(trimback(line, strchr(line, 0)));
break;
if (0 == *p || ';' == *p) if (0 == *p || ';' == *p)
continue; continue;
switch (state) { switch (state) {
case 0: case 0:
if (0 != strnicmp(p, "LIBRARY", 7)) if (0 != strnicmp(p, "LIBRARY", 7))
@ -1645,6 +1634,7 @@ static int pe_load_def(TCCState *s1, int fd)
} }
ret = 0; ret = 0;
quit: quit:
fclose(fp);
return ret; return ret;
} }