authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-27 17:26:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 13:24:43-07:00
log0794e48b9148ebf4ea62c2da19790985f6f6f875
treecdb0cd1fd982b31f1451139b5f29d95d55e092cf
parentcb9e8b0d01dcfb67c0f60af843aa85df31a13c8c

update a couple more callsites to `@memset`


2 files changed, 12 insertions(+), 15 deletions(-)

lib/compiler_rt/udivmodei4.zig+3-3
...@@ -29,8 +29,8 @@ inline fn limb_set(x: []u32, i: usize, v: u32) void {...@@ -29,8 +29,8 @@ inline fn limb_set(x: []u32, i: usize, v: u32) void {
2929
30// Uses Knuth's Algorithm D, 4.3.1, p. 272.30// Uses Knuth's Algorithm D, 4.3.1, p. 272.
31fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {31fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
32 if (q) |q_| std.mem.set(u32, q_[0..], 0);32 if (q) |q_| @memset(q_[0..], 0);
33 if (r) |r_| std.mem.set(u32, r_[0..], 0);33 if (r) |r_| @memset(r_[0..], 0);
3434
35 if (u.len == 0 or v.len == 0) return error.DivisionByZero;35 if (u.len == 0 or v.len == 0) return error.DivisionByZero;
3636
...@@ -44,7 +44,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {...@@ -44,7 +44,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
44 }44 }
4545
46 if (n > m) {46 if (n > m) {
47 if (r) |r_| std.mem.copy(u32, r_[0..], u[0..]);47 if (r) |r_| @memcpy(r_[0..u.len], u);
48 return;48 return;
49 }49 }
5050
lib/std/mem.zig+9-12
...@@ -192,7 +192,8 @@ test "Allocator.resize" {...@@ -192,7 +192,8 @@ test "Allocator.resize" {
192 }192 }
193}193}
194194
195/// Deprecated: use `copyForwards`195/// Deprecated: use `@memcpy` if the arguments do not overlap, or
196/// `copyForwards` if they do.
196pub const copy = copyForwards;197pub const copy = copyForwards;
197198
198/// Copy all of source into dest at position 0.199/// Copy all of source into dest at position 0.
...@@ -218,11 +219,7 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {...@@ -218,11 +219,7 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {
218 }219 }
219}220}
220221
221/// Sets all elements of `dest` to `value`.222pub const set = @compileError("deprecated; use @memset instead");
222pub fn set(comptime T: type, dest: []T, value: T) void {
223 for (dest) |*d|
224 d.* = value;
225}
226223
227/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.224/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
228/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when225/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when
...@@ -251,7 +248,7 @@ pub fn zeroes(comptime T: type) T {...@@ -251,7 +248,7 @@ pub fn zeroes(comptime T: type) T {
251 if (@sizeOf(T) == 0) return undefined;248 if (@sizeOf(T) == 0) return undefined;
252 if (struct_info.layout == .Extern) {249 if (struct_info.layout == .Extern) {
253 var item: T = undefined;250 var item: T = undefined;
254 set(u8, asBytes(&item), 0);251 @memset(asBytes(&item), 0);
255 return item;252 return item;
256 } else {253 } else {
257 var structure: T = undefined;254 var structure: T = undefined;
...@@ -1669,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {...@@ -1669,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
1669 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));1666 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16701667
1671 if (@typeInfo(T).Int.bits == 0) {1668 if (@typeInfo(T).Int.bits == 0) {
1672 return set(u8, buffer, 0);1669 return @memset(buffer, 0);
1673 } else if (@typeInfo(T).Int.bits == 8) {1670 } else if (@typeInfo(T).Int.bits == 8) {
1674 set(u8, buffer, 0);1671 @memset(buffer, 0);
1675 buffer[0] = @bitCast(u8, value);1672 buffer[0] = @bitCast(u8, value);
1676 return;1673 return;
1677 }1674 }
...@@ -1693,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {...@@ -1693,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
1693 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));1690 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16941691
1695 if (@typeInfo(T).Int.bits == 0) {1692 if (@typeInfo(T).Int.bits == 0) {
1696 return set(u8, buffer, 0);1693 return @memset(buffer, 0);
1697 } else if (@typeInfo(T).Int.bits == 8) {1694 } else if (@typeInfo(T).Int.bits == 8) {
1698 set(u8, buffer, 0);1695 @memset(buffer, 0);
1699 buffer[buffer.len - 1] = @bitCast(u8, value);1696 buffer[buffer.len - 1] = @bitCast(u8, value);
1700 return;1697 return;
1701 }1698 }
...@@ -2708,7 +2705,7 @@ fn testReadIntImpl() !void {...@@ -2708,7 +2705,7 @@ fn testReadIntImpl() !void {
2708 }2705 }
2709}2706}
27102707
2711test "writeIntSlice" {2708test writeIntSlice {
2712 try testWriteIntImpl();2709 try testWriteIntImpl();
2713 comptime try testWriteIntImpl();2710 comptime try testWriteIntImpl();
2714}2711}