authorgravatar for hemisputnik@proton.mehemisputnik <hemisputnik@proton.me> 2026-08-09 06:54:33+03:00
committergravatar for hemisputnik@proton.mehemisputnik <hemisputnik@proton.me> 2026-08-09 15:25:12+03:00
log92b04c5b6cbca78e3bd2339b13813271732b9259
tree74d574948a105d4881c3951e903838738e6d769d
parentc9dc9b798cdf03e792c214268b1b46fbee1d6c54
signaturebadge-check Signed by SSH key SHA256:iUK/EffQPyeXTXChJNV0UrxsscinNLxnk+0pu4OGU7Q

std.Build.Serialize: use array hash map index trick for package_map


1 files changed, 6 insertions(+), 6 deletions(-)

lib/std/Build/Serialize.zig+6-6
......@@ -10,8 +10,8 @@ const log = std.log;
1010arena: Allocator,
1111wc: *Configuration.Wip,
1212module_map: std.array_hash_map.Auto(*std.Build.Module, Configuration.Module.Index) = .empty,
13/// Keyed by package hash.
14package_map: std.array_hash_map.String(Configuration.Package.Index) = .empty,
13/// Keyed by package hash. Index + 1 corresponds to `Configuration.packages` index.
14package_map: std.array_hash_map.String(void) = .empty,
1515/// Index corresponds to `Configuration.steps` index.
1616step_map: std.array_hash_map.Auto(*Step, void) = .empty,
1717
......@@ -750,9 +750,9 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8
750750 const arena = s.arena;
751751 const wc = s.wc;
752752
753 if (s.package_map.get(hash)) |index| return .{
753 if (s.package_map.getIndex(hash)) |index| return .{
754754 .name = try wc.addString(name),
755 .package = index,
755 .package = @fromBackingInt(@intCast(index + 1)),
756756 };
757757
758758 const entry = std.Build.package_map.get(hash) orelse unreachable;
......@@ -760,7 +760,7 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8
760760 const dep_prefix = try arena.print("{s}{s}.", .{ parent_dep_prefix, name });
761761
762762 const index: Configuration.Package.Index = @fromBackingInt(@intCast(wc.packages.items.len));
763 try s.package_map.put(arena, hash, index);
763 try s.package_map.put(arena, hash, {});
764764
765765 try wc.packages.append(wc.gpa, .{
766766 .dep_prefix = try wc.addString(dep_prefix),
......@@ -784,7 +784,7 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8
784784
785785fn packageFromHash(s: *Serialize, pkg_hash: []const u8) Configuration.Package.Index {
786786 if (pkg_hash.len == 0) return .root;
787 return s.package_map.get(pkg_hash) orelse std.debug.panic("unrecognized package hash: {q}", .{pkg_hash});
787 return @fromBackingInt(@intCast(s.package_map.getIndex(pkg_hash).? + 1));
788788}
789789
790790fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath.OptionalIndex {