authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-01 14:47:18-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-01 14:47:18-04:00
log109c0b9d96ba0b1d421190d38fa67a97d4184d6b
tree68af6ca926b52a367576c2b8b7504f71e1b06729
parentc0e5eca6f2e1a688a6703ed36aef300d9393183d

rename std.mem.defaultInit to std.mem.zeroInit


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

lib/std/mem.zig+5-5
......@@ -519,7 +519,7 @@ test "mem.secureZero" {
519519/// Initializes all fields of the struct with their default value, or zero values if no default value is present.
520520/// If the field is present in the provided initial values, it will have that value instead.
521521/// Structs are initialized recursively.
522pub fn defaultInit(comptime T: type, init: var) T {
522pub fn zeroInit(comptime T: type, init: var) T {
523523 comptime const Init = @TypeOf(init);
524524
525525 switch (@typeInfo(T)) {
......@@ -538,7 +538,7 @@ pub fn defaultInit(comptime T: type, init: var) T {
538538 if (@hasField(Init, field.name)) {
539539 switch (@typeInfo(field.field_type)) {
540540 .Struct => {
541 @field(value, field.name) = defaultInit(field.field_type, @field(init, field.name));
541 @field(value, field.name) = zeroInit(field.field_type, @field(init, field.name));
542542 },
543543 else => {
544544 @field(value, field.name) = @field(init, field.name);
......@@ -562,7 +562,7 @@ pub fn defaultInit(comptime T: type, init: var) T {
562562 }
563563}
564564
565test "mem.defaultInit" {
565test "zeroInit" {
566566 const I = struct {
567567 d: f64,
568568 };
......@@ -575,7 +575,7 @@ test "mem.defaultInit" {
575575 f: i64,
576576 };
577577
578 const s = defaultInit(S, .{
578 const s = zeroInit(S, .{
579579 .a = 42,
580580 });
581581
......@@ -585,7 +585,7 @@ test "mem.defaultInit" {
585585 .c = .{
586586 .d = 0,
587587 },
588 .e = [3]u8{0, 0, 0},
588 .e = [3]u8{ 0, 0, 0 },
589589 .f = 0,
590590 });
591591}