From e57d9c7e0655a9a55d15767d39713e85d67927b5 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Thu, 15 Oct 2026 21:05:28 +0000 Subject: [PATCH] PROPOSALS: Map.done, met in rwalk --- diff --git a/PROPOSALS.md b/PROPOSALS.md index 95adb95..2474bdd 100644 --- a/PROPOSALS.md +++ b/PROPOSALS.md @@ -513,3 +513,26 @@ Met in rless, whose `make rless-c` builds over the C `Sys` without `-Werror` for this alone. + +## `Map.done` + +`Map` takes memory from its allocator as it grows and frees the old +slots, but never gives the last ones back: a map made over `Heap` for +a while, as a table kept for one directory of a walk, can't be +emptied of its memory, only dropped, and the memory is lost. `Buf` +and `Vec` each have a `done`; `Map` has none, and is the odd one out. + +``` +proc done*(m: ^Map); (* its memory given back, leaving it empty *) +``` + +As `Vec.done`: free the slots if there are any, then `cap` and `len` +0, so the map can be used again and grows anew. `init` already leaves +it so, with no memory taken until the first `put`. + +Met in rwalk's `Rwignore`, which keeps a table of the rules that are a +plain name (`node_modules`, `target`) for each ignore file, made as the +walk enters a directory and dropped as it leaves. Without `done` it +used a `Vec` of rule numbers instead, searched in turn. Library growth +that breaks no program; about ten lines, with a test in `Map`'s +`main`.