summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 20:32:22 -0500
committerWormHeamer2026-01-02 20:32:22 -0500
commitb3e19e51d09d0d2cd85f62f6ec2b62b1b03fb7ee (patch)
tree838904ed6eabc921a1c49f83bc6161c94b18d2ea
parentf304d7c3c42daeee5884d07ad4c72c1b68bd4500 (diff)
try to preallocate file option lists
-rw-r--r--main.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/main.c b/main.c
index 2a3f666..6ea99cd 100644
--- a/main.c
+++ b/main.c
@@ -652,6 +652,12 @@ void draw(void *ctx) {
} else {
draw_buf(&e.buf[e.bufi]);
}
+ size_t max = e.scratch.end - e.scratch.start;
+ size_t used = e.scratch.beg - e.scratch.start;
+ vui_printf(-1, -1, "%.02f/%.02fk (%u%%)", used/1024.0, max / 1024.0, (100 * used) / max);
+ //FILE *f = fopen("scratch.dat", "wb");
+ //fwrite(e.scratch.start, 1, used, f);
+ //fclose(f);
}
TxtLoc logical_line_start(TxtLoc l) {
@@ -1334,13 +1340,18 @@ done:
Str select_file_in(const char *path) {
DIR *d = opendir(path);
if (!d) return (Str) { 0, 0 };
- DYNARR(Str) opt = { 0 };
- struct dirent *de;
+ Arena perm = e.perm;
+ Arena scratch = e.scratch;
-again:
- opt.n = 0;
+again:;
+ struct dirent *de;
+ DYNARR(Str) opt = { 0 };
+ u32 dirs = 0;
+ while (readdir(d)) dirs++;
+ DA_AFIT(&opt, &e.scratch, dirs);
if (strcmp(path, "/"))
DA_APUSH(&opt, &e.scratch, S(".."));
+ seekdir(d, 0);
while ((de = readdir(d))) {
if (de->d_name[0] == '.') continue;
Str dn = str_from_cstr(de->d_name);
@@ -1362,9 +1373,15 @@ again:
str_cat(&s, opt.v[o], &e.scratch);
s = normalize_path(s);
+ e.perm = perm;
path = str_to_cstr(s, &e.scratch);
d = opendir(path);
- if (d) goto again;
+ if (d) {
+ path = cstr_dup(path, &e.perm);
+ e.scratch = scratch;
+ goto again;
+ }
+
return s;
}