authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-10 16:57:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-11 10:33:54-07:00
logec67d6e03a05a2d87880d7a97654ae55f4c733a2
tree8a33f76030fea045e29cf50e9f30b29cd516cedc
parent41dbd0d0da0989495a97e99fb9269a49ac302768

std.MultiArrayList: add empty initalizer value


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

lib/std/multi_array_list.zig+7-1
...@@ -23,6 +23,12 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -23,6 +23,12 @@ pub fn MultiArrayList(comptime T: type) type {
23 len: usize = 0,23 len: usize = 0,
24 capacity: usize = 0,24 capacity: usize = 0,
2525
26 pub const empty: Self = .{
27 .bytes = undefined,
28 .len = 0,
29 .capacity = 0,
30 };
31
26 const Elem = switch (@typeInfo(T)) {32 const Elem = switch (@typeInfo(T)) {
27 .@"struct" => T,33 .@"struct" => T,
28 .@"union" => |u| struct {34 .@"union" => |u| struct {
...@@ -474,7 +480,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -474,7 +480,7 @@ pub fn MultiArrayList(comptime T: type) type {
474 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {480 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
475 inline for (fields, 0..) |field_info, i| {481 inline for (fields, 0..) |field_info, i| {
476 if (@sizeOf(field_info.type) != 0) {482 if (@sizeOf(field_info.type) != 0) {
477 const field = @as(Field, @enumFromInt(i));483 const field: Field = @enumFromInt(i);
478 const ptr = sc.slice.items(field);484 const ptr = sc.slice.items(field);
479 mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);485 mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
480 }486 }