scan: Don't allocate directory iterator on the stack

I had planned to checkout out async functions here so I could avoid
recursing onto the stack alltogether, but it's still unclear to me how
to safely call into libc from async functions so let's wait for all that
to get fleshed out a bit more.
This commit is contained in:
Yorhel 2021-07-18 16:43:00 +02:00
parent 6f07a36923
commit b96587c25f

View file

@ -449,8 +449,9 @@ var active_context: *Context = undefined;
// Read and index entries of the given dir.
fn scanDir(ctx: *Context, dir: std.fs.Dir, dir_dev: u64) void {
// XXX: The iterator allocates 8k+ bytes on the stack, may want to do heap allocation here?
var it = dir.iterate();
var it = main.allocator.create(std.fs.Dir.Iterator) catch unreachable;
defer main.allocator.destroy(it);
it.* = dir.iterate();
while(true) {
const entry = it.next() catch {
ctx.setDirlistError();