From 2f797a159a997d3ed19b6587a47240e366efc321 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 28 Oct 2021 01:25:03 -0700 Subject: [PATCH] move away from comptimestringmap for self/files to reduce reference counts --- src/common.zig | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/common.zig b/src/common.zig index 2e8659670fe5b16b5479616f7cf34bbe28a2f7fd..eb02eb53d7a50e05e6c260dee6078b5f06ed7a8b 100644 --- a/src/common.zig +++ b/src/common.zig @@ -310,22 +310,17 @@ pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const strin \\ ); try w.print("const srcpath = \"../../../{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])}); - try w.writeAll( - \\const files = std.ComptimeStringMap(string, .{ - \\ - ); var iter = map.iterator(); while (iter.next()) |item| { - try w.print(" .{{ .@\"0\" = \"/{}\", .@\"1\" = @embedFile(srcpath ++ \"/{}\") }},\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); + try w.print("pub const @\"/{}\" = @embedFile(srcpath ++ \"/{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); } try w.writeAll("\n"); try w.writeAll( - \\}); - \\ \\pub fn open(comptime path: string) ?string { \\ if (path.len == 0) return null; \\ if (path[0] != '/') return null; - \\ return files.get(path); + \\ if (!@hasDecl(@This(), path)) return null; + \\ return @field(@This(), path); \\} \\ ); -- 2.54.0