aboutsummaryrefslogtreecommitdiff
path: root/tccpe.c
diff options
context:
space:
mode:
authorgrischka <grischka>2014-04-13 20:30:46 +0200
committergrischka <grischka>2014-04-13 20:30:46 +0200
commit112148172b50c20acde6adf4f86fa0a32d3d5a6c (patch)
tree4dc4708124ebfe311fd5b3caca58844f543db706 /tccpe.c
parentaa255f37f24abc320b1101fb85f7e9f4d9e21cff (diff)
downloadtinycc-112148172b50c20acde6adf4f86fa0a32d3d5a6c.tar.gz
tinycc-112148172b50c20acde6adf4f86fa0a32d3d5a6c.tar.bz2
tccpe: speed up .def file loading
The fgets replacement meant to work with "int fd" was just too slow.
Diffstat (limited to 'tccpe.c')
-rw-r--r--tccpe.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/tccpe.c b/tccpe.c
index f4a58f7..6ee3865 100644
--- a/tccpe.c
+++ b/tccpe.c
@@ -1583,31 +1583,20 @@ static char *trimback(char *a, char *e)
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)
{
int state = 0, ret = -1, dllindex = 0, ord;
char line[400], dllname[80], *p, *x;
+ FILE *fp;
- for (;;) {
-
- p = get_line(line, sizeof line, fd);
- if (NULL == p)
- break;
+ fp = fdopen(dup(fd), "rb");
+ while (fgets(line, sizeof line, fp))
+ {
+ p = trimfront(trimback(line, strchr(line, 0)));
if (0 == *p || ';' == *p)
continue;
+
switch (state) {
case 0:
if (0 != strnicmp(p, "LIBRARY", 7))
@@ -1645,6 +1634,7 @@ static int pe_load_def(TCCState *s1, int fd)
}
ret = 0;
quit:
+ fclose(fp);
return ret;
}