refactor(findr): Now accepts an allocator parameter.

This commit is contained in:
2026-06-30 12:53:27 -04:00
parent ae42d53f02
commit ca992f05f4
6 changed files with 37 additions and 10 deletions
+2 -4
View File
@@ -18,11 +18,9 @@
9. Update `read_wire_string` to use a slice. 9. Update `read_wire_string` to use a slice.
10. Pass allocator to findr? 10. Consider getting rid of color global.
11. Consider getting rid of color global. 11. `write_flags_table` should never return false.
12. `write_flags_table` should never return false.
## Double-check AI output ## Double-check AI output
+4 -3
View File
@@ -201,8 +201,7 @@ find_git_roots :: proc(
ok: bool, ok: bool,
) { ) {
paths := search_paths(cfg, allocator) paths := search_paths(cfg, allocator)
// TODO: Pass allocator to findr findr.find_repos(paths[:], &roots, os.get_processor_core_count(), allocator)
findr.find_repos(paths[:], &roots, os.get_processor_core_count())
ok = true ok = true
return return
} }
@@ -214,6 +213,7 @@ search_paths :: proc(cfg: Config, allocator := context.allocator) -> [dynamic]st
} }
paths := new_clone(cfg.scan_config.include, allocator) paths := new_clone(cfg.scan_config.include, allocator)
defer free(paths, allocator)
for &include in paths { for &include in paths {
expanded, _ := strings.replace(include, "~", home, 1, allocator) expanded, _ := strings.replace(include, "~", home, 1, allocator)
@@ -227,7 +227,8 @@ search_paths :: proc(cfg: Config, allocator := context.allocator) -> [dynamic]st
} }
} }
} }
return paths^ result := paths^
return result
} }
envr_dir :: proc(config_path: string) -> string { envr_dir :: proc(config_path: string) -> string {
+12
View File
@@ -2,6 +2,7 @@
package main package main
import "core:fmt" import "core:fmt"
import "core:mem"
import "core:os" import "core:os"
import "core:path/filepath" import "core:path/filepath"
import "core:strings" import "core:strings"
@@ -194,3 +195,14 @@ test_search_paths_expands_tilde :: proc(t: ^testing.T) {
} }
} }
@(test)
test_search_paths_no_leak :: proc(t: ^testing.T) {
cfg := Config {
scan_config = ScanConfig{include = make([dynamic]string, 0, 1)},
}
defer delete(cfg.scan_config.include)
append(&cfg.scan_config.include, "/tmp")
_ = search_paths(cfg, context.allocator)
}
+1 -1
View File
@@ -491,7 +491,7 @@ db_persist :: proc(db: ^Db, f: ^EnvFile, old_path: string) -> bool {
} }
try_move_dir :: proc(db: ^Db, f: ^EnvFile, allocator: mem.Allocator) -> (bool, SyncError) { try_move_dir :: proc(db: ^Db, f: ^EnvFile, allocator: mem.Allocator) -> (bool, SyncError) {
roots, ok := find_git_roots(db.cfg) roots, ok := find_git_roots(db.cfg, context.allocator)
if !ok { if !ok {
return false, .GitRootFailed return false, .GitRootFailed
} }
+9 -1
View File
@@ -16,7 +16,14 @@ RepoPool :: struct {
threads: []^thread.Thread, threads: []^thread.Thread,
} }
find_repos :: proc(roots: []string, results: ^[dynamic]string, thread_count: int) { find_repos :: proc(
roots: []string,
results: ^[dynamic]string,
thread_count: int,
allocator := context.allocator,
) {
// TODO: This may be a code smell
context.allocator = allocator
if len(roots) == 0 do return if len(roots) == 0 do return
pool := new(RepoPool) pool := new(RepoPool)
@@ -126,3 +133,4 @@ process_repo_dir :: proc(pool: ^RepoPool, dir_path: string) {
} }
} }
} }
+9 -1
View File
@@ -78,7 +78,15 @@ collect_worker :: proc(t: ^thread.Thread) {
} }
} }
walk :: proc(roots: []string, results: ^[dynamic]string, opts: WalkOptions, thread_count: int) { walk :: proc(
roots: []string,
results: ^[dynamic]string,
opts: WalkOptions,
thread_count: int,
allocator := context.allocator,
) {
// TODO: This may be a code smell
context.allocator = allocator
if len(roots) == 0 do return if len(roots) == 0 do return
ch, _ := chan.create(chan.Chan([]u8), max(2 * thread_count, 2), context.allocator) ch, _ := chan.create(chan.Chan([]u8), max(2 * thread_count, 2), context.allocator)