update a couple more callsites to @memset

This commit is contained in:
Andrew Kelley 2023-04-27 17:26:16 -07:00
parent cb9e8b0d01
commit 0794e48b91
2 changed files with 12 additions and 15 deletions

View file

@ -29,8 +29,8 @@ inline fn limb_set(x: []u32, i: usize, v: u32) void {
// Uses Knuth's Algorithm D, 4.3.1, p. 272.
fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
if (q) |q_| std.mem.set(u32, q_[0..], 0);
if (r) |r_| std.mem.set(u32, r_[0..], 0);
if (q) |q_| @memset(q_[0..], 0);
if (r) |r_| @memset(r_[0..], 0);
if (u.len == 0 or v.len == 0) return error.DivisionByZero;
@ -44,7 +44,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
}
if (n > m) {
if (r) |r_| std.mem.copy(u32, r_[0..], u[0..]);
if (r) |r_| @memcpy(r_[0..u.len], u);
return;
}

View file

@ -192,7 +192,8 @@ test "Allocator.resize" {
}
}
/// Deprecated: use `copyForwards`
/// Deprecated: use `@memcpy` if the arguments do not overlap, or
/// `copyForwards` if they do.
pub const copy = copyForwards;
/// 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 {
}
}
/// Sets all elements of `dest` to `value`.
pub fn set(comptime T: type, dest: []T, value: T) void {
for (dest) |*d|
d.* = value;
}
pub const set = @compileError("deprecated; use @memset instead");
/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
/// 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 {
if (@sizeOf(T) == 0) return undefined;
if (struct_info.layout == .Extern) {
var item: T = undefined;
set(u8, asBytes(&item), 0);
@memset(asBytes(&item), 0);
return item;
} else {
var structure: T = undefined;
@ -1669,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
if (@typeInfo(T).Int.bits == 0) {
return set(u8, buffer, 0);
return @memset(buffer, 0);
} else if (@typeInfo(T).Int.bits == 8) {
set(u8, buffer, 0);
@memset(buffer, 0);
buffer[0] = @bitCast(u8, value);
return;
}
@ -1693,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
if (@typeInfo(T).Int.bits == 0) {
return set(u8, buffer, 0);
return @memset(buffer, 0);
} else if (@typeInfo(T).Int.bits == 8) {
set(u8, buffer, 0);
@memset(buffer, 0);
buffer[buffer.len - 1] = @bitCast(u8, value);
return;
}
@ -2708,7 +2705,7 @@ fn testReadIntImpl() !void {
}
}
test "writeIntSlice" {
test writeIntSlice {
try testWriteIntImpl();
comptime try testWriteIntImpl();
}