authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-02-05 11:40:22+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-05 10:51:45-08:00
log0b4bb9b84fddd8fe03fe15e25bd82babb455f2a6
tree062003511f4a45fb34f972a531a5ee2de3011920
parent7069459a76ad507bb1ce56b2d8de923b93385def

std.MultiArrayList: implement review comments


1 files changed, 7 insertions(+), 7 deletions(-)

lib/std/multi_array_list.zig+7-7
......@@ -20,7 +20,8 @@ pub fn MultiArrayList(comptime S: type) type {
2020 pub const Field = meta.FieldEnum(S);
2121
2222 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
2425 ptrs: [fields.len][*]u8,
2526 len: usize,
2627 capacity: usize,
......@@ -57,8 +58,7 @@ pub fn MultiArrayList(comptime S: type) type {
5758
5859 const fields = meta.fields(S);
5960 /// `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.
6262 const sizes = blk: {
6363 const Data = struct {
6464 size: usize,
......@@ -81,16 +81,13 @@ pub fn MultiArrayList(comptime S: type) type {
8181 var trash: i32 = undefined; // workaround for stage1 compiler bug
8282 std.sort.sort(Data, &data, &trash, Sort.lessThan);
8383 var sizes_bytes: [fields.len]usize = undefined;
84 var sizes_indexes: [fields.len]usize = undefined;
8584 var field_indexes: [fields.len]usize = undefined;
8685 for (data) |elem, i| {
8786 sizes_bytes[i] = elem.size;
88 sizes_indexes[elem.size_index] = i;
8987 field_indexes[i] = elem.size_index;
9088 }
9189 break :blk .{
9290 .bytes = sizes_bytes,
93 .indexes = sizes_indexes,
9491 .fields = field_indexes,
9592 };
9693 };
......@@ -183,8 +180,11 @@ pub fn MultiArrayList(comptime S: type) type {
183180 capacityInBytes(new_len),
184181 .exact,
185182 ) 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 }
186187 self.len = new_len;
187 // TODO memset the invalidated items to undefined
188188 return;
189189 };
190190 var other = Self{