| ... | ... | @@ -20,7 +20,8 @@ pub fn MultiArrayList(comptime S: type) type { |
| 20 | 20 | pub const Field = meta.FieldEnum(S); |
| 21 | 21 | |
| 22 | 22 | pub const Slice = struct { |
| 23 | | /// The index corresponds to sizes.bytes, not in field order. |
| 23 | /// This array is indexed by the field index which can be obtained |
| 24 | /// by using @enumToInt() on the Field enum |
| 24 | 25 | ptrs: [fields.len][*]u8, |
| 25 | 26 | len: usize, |
| 26 | 27 | capacity: usize, |
| ... | ... | @@ -57,8 +58,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 57 | 58 | |
| 58 | 59 | const fields = meta.fields(S); |
| 59 | 60 | /// `sizes.bytes` is an array of @sizeOf each S field. Sorted by alignment, descending. |
| 60 | | /// `sizes.indexes` is an array mapping from field to its index in the `sizes.bytes` array. |
| 61 | | /// `sizes.fields` is an array with the field indexes of the `sizes.bytes` array. |
| 61 | /// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index. |
| 62 | 62 | const sizes = blk: { |
| 63 | 63 | const Data = struct { |
| 64 | 64 | size: usize, |
| ... | ... | @@ -81,16 +81,13 @@ pub fn MultiArrayList(comptime S: type) type { |
| 81 | 81 | var trash: i32 = undefined; // workaround for stage1 compiler bug |
| 82 | 82 | std.sort.sort(Data, &data, &trash, Sort.lessThan); |
| 83 | 83 | var sizes_bytes: [fields.len]usize = undefined; |
| 84 | | var sizes_indexes: [fields.len]usize = undefined; |
| 85 | 84 | var field_indexes: [fields.len]usize = undefined; |
| 86 | 85 | for (data) |elem, i| { |
| 87 | 86 | sizes_bytes[i] = elem.size; |
| 88 | | sizes_indexes[elem.size_index] = i; |
| 89 | 87 | field_indexes[i] = elem.size_index; |
| 90 | 88 | } |
| 91 | 89 | break :blk .{ |
| 92 | 90 | .bytes = sizes_bytes, |
| 93 | | .indexes = sizes_indexes, |
| 94 | 91 | .fields = field_indexes, |
| 95 | 92 | }; |
| 96 | 93 | }; |
| ... | ... | @@ -183,8 +180,11 @@ pub fn MultiArrayList(comptime S: type) type { |
| 183 | 180 | capacityInBytes(new_len), |
| 184 | 181 | .exact, |
| 185 | 182 | ) catch { |
| 183 | inline for (fields) |field_info, i| { |
| 184 | const field = @intToEnum(Field, i); |
| 185 | mem.set(field_info.field_type, self.slice().items(field)[new_len..], undefined); |
| 186 | } |
| 186 | 187 | self.len = new_len; |
| 187 | | // TODO memset the invalidated items to undefined |
| 188 | 188 | return; |
| 189 | 189 | }; |
| 190 | 190 | var other = Self{ |