| ... | ... | @@ -3951,24 +3951,20 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3951 | 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 | const has_internal_null = |
| 3955 | std.mem.indexOfScalar(u8, ip.string_bytes.items[string_bytes_index..], 0) != null; |
| 3963 | 3956 | if (sentinel != .none) ip.string_bytes.appendAssumeCapacity( |
| 3964 | 3957 | @intCast(u8, ip.indexToKey(sentinel).int.storage.u64), |
| 3965 | 3958 | ); |
| 3966 | | const bytes = try ip.getOrPutTrailingString(gpa, len_including_sentinel); |
| 3959 | const string = if (has_internal_null) |
| 3960 | @intToEnum(String, string_bytes_index) |
| 3961 | else |
| 3962 | (try ip.getOrPutTrailingString(gpa, len_including_sentinel)).toString(); |
| 3967 | 3963 | ip.items.appendAssumeCapacity(.{ |
| 3968 | 3964 | .tag = .bytes, |
| 3969 | 3965 | .data = ip.addExtraAssumeCapacity(Bytes{ |
| 3970 | 3966 | .ty = aggregate.ty, |
| 3971 | | .bytes = bytes.toString(), |
| 3967 | .bytes = string, |
| 3972 | 3968 | }), |
| 3973 | 3969 | }); |
| 3974 | 3970 | return @intToEnum(Index, ip.items.len - 1); |
| ... | ... | @@ -3984,17 +3980,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3984 | 3980 | .ty = aggregate.ty, |
| 3985 | 3981 | }), |
| 3986 | 3982 | }); |
| 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 | | } |
| 3983 | ip.extra.appendSliceAssumeCapacity(@ptrCast([]const u32, aggregate.storage.elems)); |
| 3998 | 3984 | if (sentinel != .none) ip.extra.appendAssumeCapacity(@enumToInt(sentinel)); |
| 3999 | 3985 | }, |
| 4000 | 3986 | |