| ... | @@ -3951,6 +3951,15 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -3951,6 +3951,15 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3951 | else => unreachable, | 3951 | else => unreachable, |
| 3952 | }, | 3952 | }, |
| 3953 | } | 3953 | } |
| | 3954 | // We can't dedup '0' bytes in the pool or it could add garbage to string_bytes. So |
| | 3955 | // if there are any 0 bytes, we have to skip the bytes case. Note that it's okay for |
| | 3956 | // our sentinel to be 0 since getOrPutTrailingString would add a 0 sentinel anyway. |
| | 3957 | for (ip.string_bytes.items[string_bytes_index..]) |x| { |
| | 3958 | if (x == 0) { |
| | 3959 | ip.string_bytes.shrinkRetainingCapacity(string_bytes_index); |
| | 3960 | break :bytes; |
| | 3961 | } |
| | 3962 | } |
| 3954 | if (sentinel != .none) ip.string_bytes.appendAssumeCapacity( | 3963 | if (sentinel != .none) ip.string_bytes.appendAssumeCapacity( |
| 3955 | @intCast(u8, ip.indexToKey(sentinel).int.storage.u64), | 3964 | @intCast(u8, ip.indexToKey(sentinel).int.storage.u64), |
| 3956 | ); | 3965 | ); |
| ... | @@ -3975,7 +3984,17 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -3975,7 +3984,17 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3975 | .ty = aggregate.ty, | 3984 | .ty = aggregate.ty, |
| 3976 | }), | 3985 | }), |
| 3977 | }); | 3986 | }); |
| 3978 | ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, aggregate.storage.elems)); | 3987 | switch (aggregate.storage) { |
| | 3988 | .bytes => |bytes| for (bytes) |b| { |
| | 3989 | const elem = try ip.get(gpa, .{ .int = .{ |
| | 3990 | .ty = .u8_type, |
| | 3991 | .storage = .{ .u64 = b }, |
| | 3992 | } }); |
| | 3993 | ip.extra.appendAssumeCapacity(@enumToInt(elem)); |
| | 3994 | }, |
| | 3995 | .elems => |elems| ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, elems)), |
| | 3996 | .repeated_elem => |elem| ip.extra.appendNTimesAssumeCapacity(@enumToInt(elem), len), |
| | 3997 | } |
| 3979 | if (sentinel != .none) ip.extra.appendAssumeCapacity(@enumToInt(sentinel)); | 3998 | if (sentinel != .none) ip.extra.appendAssumeCapacity(@enumToInt(sentinel)); |
| 3980 | }, | 3999 | }, |
| 3981 | | 4000 | |
| ... | @@ -5203,7 +5222,7 @@ pub fn destroyFunc(ip: *InternPool, gpa: Allocator, index: Module.Fn.Index) void | ... | @@ -5203,7 +5222,7 @@ pub fn destroyFunc(ip: *InternPool, gpa: Allocator, index: Module.Fn.Index) void |
| 5203 | ip.funcPtr(index).* = undefined; | 5222 | ip.funcPtr(index).* = undefined; |
| 5204 | ip.funcs_free_list.append(gpa, index) catch { | 5223 | ip.funcs_free_list.append(gpa, index) catch { |
| 5205 | // In order to keep `destroyFunc` a non-fallible function, we ignore memory | 5224 | // In order to keep `destroyFunc` a non-fallible function, we ignore memory |
| 5206 | // allocation failures here, instead leaking the Union until garbage collection. | 5225 | // allocation failures here, instead leaking the Fn until garbage collection. |
| 5207 | }; | 5226 | }; |
| 5208 | } | 5227 | } |
| 5209 | | 5228 | |