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" {...@@ -519,7 +519,7 @@ test "mem.secureZero" {
519/// Initializes all fields of the struct with their default value, or zero values if no default value is present.519/// Initializes all fields of the struct with their default value, or zero values if no default value is present.
520/// If the field is present in the provided initial values, it will have that value instead.520/// If the field is present in the provided initial values, it will have that value instead.
521/// Structs are initialized recursively.521/// Structs are initialized recursively.
522pub fn defaultInit(comptime T: type, init: var) T {522pub fn zeroInit(comptime T: type, init: var) T {
523 comptime const Init = @TypeOf(init);523 comptime const Init = @TypeOf(init);
524524
525 switch (@typeInfo(T)) {525 switch (@typeInfo(T)) {
...@@ -538,7 +538,7 @@ pub fn defaultInit(comptime T: type, init: var) T {...@@ -538,7 +538,7 @@ pub fn defaultInit(comptime T: type, init: var) T {
538 if (@hasField(Init, field.name)) {538 if (@hasField(Init, field.name)) {
539 switch (@typeInfo(field.field_type)) {539 switch (@typeInfo(field.field_type)) {
540 .Struct => {540 .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));
542 },542 },
543 else => {543 else => {
544 @field(value, field.name) = @field(init, field.name);544 @field(value, field.name) = @field(init, field.name);
...@@ -562,7 +562,7 @@ pub fn defaultInit(comptime T: type, init: var) T {...@@ -562,7 +562,7 @@ pub fn defaultInit(comptime T: type, init: var) T {
562 }562 }
563}563}
564564
565test "mem.defaultInit" {565test "zeroInit" {
566 const I = struct {566 const I = struct {
567 d: f64,567 d: f64,
568 };568 };
...@@ -575,7 +575,7 @@ test "mem.defaultInit" {...@@ -575,7 +575,7 @@ test "mem.defaultInit" {
575 f: i64,575 f: i64,
576 };576 };
577577
578 const s = defaultInit(S, .{578 const s = zeroInit(S, .{
579 .a = 42,579 .a = 42,
580 });580 });
581581
...@@ -585,7 +585,7 @@ test "mem.defaultInit" {...@@ -585,7 +585,7 @@ test "mem.defaultInit" {
585 .c = .{585 .c = .{
586 .d = 0,586 .d = 0,
587 },587 },
588 .e = [3]u8{0, 0, 0},588 .e = [3]u8{ 0, 0, 0 },
589 .f = 0,589 .f = 0,
590 });590 });
591}591}