perf(findr): Improved performance of join_path* procedures.

This commit is contained in:
2026-06-17 13:22:47 -04:00
parent 3f6eb17aad
commit 1f4d355149

View File

@@ -392,33 +392,30 @@ load_ignore_patterns :: proc(dir_path: string, in_repo: bool) -> ^Gitignore {
} }
join_path :: proc(parent, child: string) -> string { join_path :: proc(parent, child: string) -> string {
b: strings.Builder need_sep := len(parent) == 0 || parent[len(parent) - 1] != '/'
strings.builder_init(&b) total := len(parent) + len(child)
defer strings.builder_destroy(&b) if need_sep do total += 1
buf := make([]u8, total, context.allocator)
fmt.sbprintf(&b, "%s", parent) pos := copy(buf, parent)
if len(parent) == 0 || parent[len(parent) - 1] != '/' { if need_sep {
fmt.sbprintf(&b, "/") buf[pos] = '/'
pos += 1
} }
fmt.sbprintf(&b, "%s", child) copy(buf[pos:], child)
return string(buf)
s := strings.to_string(b)
result, _ := strings.clone(s)
return result
} }
join_path_dir :: proc(parent, child: string) -> string { join_path_dir :: proc(parent, child: string) -> string {
b: strings.Builder need_sep := len(parent) == 0 || parent[len(parent) - 1] != '/'
strings.builder_init(&b) total := len(parent) + len(child) + 1 // +1 for trailing '/'
defer strings.builder_destroy(&b) if need_sep do total += 1
buf := make([]u8, total, context.allocator)
fmt.sbprintf(&b, "%s", parent) pos := copy(buf, parent)
if len(parent) == 0 || parent[len(parent) - 1] != '/' { if need_sep {
fmt.sbprintf(&b, "/") buf[pos] = '/'
pos += 1
} }
fmt.sbprintf(&b, "%s/", child) pos += copy(buf[pos:], child)
buf[pos] = '/'
s := strings.to_string(b) return string(buf)
result, _ := strings.clone(s)
return result
} }