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;...@@ -10,8 +10,8 @@ const log = std.log;
10arena: Allocator,10arena: Allocator,
11wc: *Configuration.Wip,11wc: *Configuration.Wip,
12module_map: std.array_hash_map.Auto(*std.Build.Module, Configuration.Module.Index) = .empty,12module_map: std.array_hash_map.Auto(*std.Build.Module, Configuration.Module.Index) = .empty,
13/// Keyed by package hash.13/// Keyed by package hash. Index + 1 corresponds to `Configuration.packages` index.
14package_map: std.array_hash_map.String(Configuration.Package.Index) = .empty,14package_map: std.array_hash_map.String(void) = .empty,
15/// Index corresponds to `Configuration.steps` index.15/// Index corresponds to `Configuration.steps` index.
16step_map: std.array_hash_map.Auto(*Step, void) = .empty,16step_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...@@ -750,9 +750,9 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8
750 const arena = s.arena;750 const arena = s.arena;
751 const wc = s.wc;751 const wc = s.wc;
752752
753 if (s.package_map.get(hash)) |index| return .{753 if (s.package_map.getIndex(hash)) |index| return .{
754 .name = try wc.addString(name),754 .name = try wc.addString(name),
755 .package = index,755 .package = @fromBackingInt(@intCast(index + 1)),
756 };756 };
757757
758 const entry = std.Build.package_map.get(hash) orelse unreachable;758 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...@@ -760,7 +760,7 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8
760 const dep_prefix = try arena.print("{s}{s}.", .{ parent_dep_prefix, name });760 const dep_prefix = try arena.print("{s}{s}.", .{ parent_dep_prefix, name });
761761
762 const index: Configuration.Package.Index = @fromBackingInt(@intCast(wc.packages.items.len));762 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
765 try wc.packages.append(wc.gpa, .{765 try wc.packages.append(wc.gpa, .{
766 .dep_prefix = try wc.addString(dep_prefix),766 .dep_prefix = try wc.addString(dep_prefix),
...@@ -784,7 +784,7 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8...@@ -784,7 +784,7 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8
784784
785fn packageFromHash(s: *Serialize, pkg_hash: []const u8) Configuration.Package.Index {785fn packageFromHash(s: *Serialize, pkg_hash: []const u8) Configuration.Package.Index {
786 if (pkg_hash.len == 0) return .root;786 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));
788}788}
789789
790fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath.OptionalIndex {790fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath.OptionalIndex {