| ... | ... | @@ -122,22 +122,16 @@ pub const Graph = struct { |
| 122 | 122 | return @enumFromInt(graph.generated_files.items.len - 1); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | | pub fn dupeString(graph: *Graph, bytes: []const u8) [:0]const u8 { |
| 126 | | // This code assumes the `Configuration.Wip` uses arena allocation such |
| 127 | | // that references to string_bytes never die even when the ArrayList is |
| 128 | | // reallocated. |
| 129 | | const wc = &graph.wip_configuration; |
| 130 | | const i = wc.addString(bytes) catch @panic("OOM"); |
| 131 | | return wc.string_bytes.items[@intFromEnum(i)..][0..bytes.len :0]; |
| 125 | pub fn dupeString(graph: *Graph, bytes: []const u8) []const u8 { |
| 126 | return graph.arena.dupe(u8, bytes) catch @panic("OOM"); |
| 132 | 127 | } |
| 133 | 128 | |
| 134 | | pub fn dupePath(graph: *Graph, bytes: []const u8) [:0]const u8 { |
| 135 | | if (builtin.os.tag != .windows) return dupeString(graph, bytes); |
| 129 | pub fn dupePath(graph: *Graph, bytes: []const u8) []const u8 { |
| 136 | 130 | const arena = graph.arena; |
| 131 | if (builtin.os.tag != .windows) return graph.arena.dupe(u8, bytes) catch @panic("OOM"); |
| 137 | 132 | const the_copy = arena.dupe(u8, bytes) catch @panic("OOM"); |
| 138 | | defer arena.free(the_copy); |
| 139 | 133 | mem.replaceScalar(u8, the_copy, '/', '\\'); |
| 140 | | return dupeString(graph, the_copy); |
| 134 | return the_copy; |
| 141 | 135 | } |
| 142 | 136 | |
| 143 | 137 | pub fn dupeStrings(graph: *Graph, strings: []const []const u8) []const []const u8 { |
| ... | ... | @@ -895,7 +889,7 @@ pub fn addConfigHeader( |
| 895 | 889 | return config_header_step; |
| 896 | 890 | } |
| 897 | 891 | |
| 898 | | pub fn dupe(b: *Build, bytes: []const u8) [:0]const u8 { |
| 892 | pub fn dupe(b: *Build, bytes: []const u8) []const u8 { |
| 899 | 893 | return b.graph.dupeString(bytes); |
| 900 | 894 | } |
| 901 | 895 | |
| ... | ... | @@ -905,7 +899,7 @@ pub fn dupeStrings(b: *Build, strings: []const []const u8) []const []const u8 { |
| 905 | 899 | } |
| 906 | 900 | |
| 907 | 901 | /// Duplicates a path, canonicalizing path separators. |
| 908 | | pub fn dupePath(b: *Build, bytes: []const u8) [:0]const u8 { |
| 902 | pub fn dupePath(b: *Build, bytes: []const u8) []const u8 { |
| 909 | 903 | return b.graph.dupePath(bytes); |
| 910 | 904 | } |
| 911 | 905 | |