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 {
2929
3030// Uses Knuth's Algorithm D, 4.3.1, p. 272.
3131fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
32 if (q) |q_| std.mem.set(u32, q_[0..], 0);
33 if (r) |r_| std.mem.set(u32, r_[0..], 0);
32 if (q) |q_| @memset(q_[0..], 0);
33 if (r) |r_| @memset(r_[0..], 0);
3434
3535 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 {
4444 }
4545
4646 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);
4848 return;
4949 }
5050
lib/std/mem.zig+9-12
......@@ -192,7 +192,8 @@ test "Allocator.resize" {
192192 }
193193}
194194
195/// Deprecated: use `copyForwards`
195/// Deprecated: use `@memcpy` if the arguments do not overlap, or
196/// `copyForwards` if they do.
196197pub const copy = copyForwards;
197198
198199/// 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 {
218219 }
219220}
220221
221/// Sets all elements of `dest` to `value`.
222pub fn set(comptime T: type, dest: []T, value: T) void {
223 for (dest) |*d|
224 d.* = value;
225}
222pub const set = @compileError("deprecated; use @memset instead");
226223
227224/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
228225/// 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 {
251248 if (@sizeOf(T) == 0) return undefined;
252249 if (struct_info.layout == .Extern) {
253250 var item: T = undefined;
254 set(u8, asBytes(&item), 0);
251 @memset(asBytes(&item), 0);
255252 return item;
256253 } else {
257254 var structure: T = undefined;
......@@ -1669,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
16691666 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16701667
16711668 if (@typeInfo(T).Int.bits == 0) {
1672 return set(u8, buffer, 0);
1669 return @memset(buffer, 0);
16731670 } else if (@typeInfo(T).Int.bits == 8) {
1674 set(u8, buffer, 0);
1671 @memset(buffer, 0);
16751672 buffer[0] = @bitCast(u8, value);
16761673 return;
16771674 }
......@@ -1693,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
16931690 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
16941691
16951692 if (@typeInfo(T).Int.bits == 0) {
1696 return set(u8, buffer, 0);
1693 return @memset(buffer, 0);
16971694 } else if (@typeInfo(T).Int.bits == 8) {
1698 set(u8, buffer, 0);
1695 @memset(buffer, 0);
16991696 buffer[buffer.len - 1] = @bitCast(u8, value);
17001697 return;
17011698 }
......@@ -2708,7 +2705,7 @@ fn testReadIntImpl() !void {
27082705 }
27092706}
27102707
2711test "writeIntSlice" {
2708test writeIntSlice {
27122709 try testWriteIntImpl();
27132710 comptime try testWriteIntImpl();
27142711}