authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 01:25:03 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 01:25:03 -07:00
log2f797a159a997d3ed19b6587a47240e366efc321
tree5e46bcb0e8c1afe3d5352302f480bf04c7ae7985
parentbec269e6983fa0b5689013a9daac8eff19ce494e

move away from comptimestringmap for self/files to reduce reference counts


1 files changed, 3 insertions(+), 8 deletions(-)

src/common.zig+3-8
......@@ -310,22 +310,17 @@ pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const strin
310310 \\
311311 );
312312 try w.print("const srcpath = \"../../../{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])});
313 try w.writeAll(
314 \\const files = std.ComptimeStringMap(string, .{
315 \\
316 );
317313 var iter = map.iterator();
318314 while (iter.next()) |item| {
319 try w.print(" .{{ .@\"0\" = \"/{}\", .@\"1\" = @embedFile(srcpath ++ \"/{}\") }},\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) });
315 try w.print("pub const @\"/{}\" = @embedFile(srcpath ++ \"/{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) });
320316 }
321317 try w.writeAll("\n");
322318 try w.writeAll(
323 \\});
324 \\
325319 \\pub fn open(comptime path: string) ?string {
326320 \\ if (path.len == 0) return null;
327321 \\ if (path[0] != '/') return null;
328 \\ return files.get(path);
322 \\ if (!@hasDecl(@This(), path)) return null;
323 \\ return @field(@This(), path);
329324 \\}
330325 \\
331326 );