Skip to content
Snippets Groups Projects
Commit a21b9e39 authored by Taco Hoekwater's avatar Taco Hoekwater
Browse files

restore file read speedup

parent 58131e6f
No related branches found
No related tags found
No related merge requests found
......@@ -233,8 +233,16 @@ static int read_line(lua_State * L, FILE * f, int chop)
static void read_all (lua_State *L, FILE *f) {
size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
size_t old, nrlen = 0; /* for testing file size */
luaL_Buffer b;
luaL_buffinit(L, &b);
/* speed up loading of not too large files: */
old = ftell(f);
if ((fseek(f, 0, SEEK_END) >= 0) &&
((nrlen = ftell(f)) > 0) && nrlen < 1000 * 1000 * 100) {
rlen = nrlen;
}
fseek(f, old, SEEK_SET);
for (;;) {
char *p = luaL_prepbuffsize(&b, rlen);
size_t nr = fread(p, sizeof(char), rlen, f);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment