mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 22:33:08 +00:00
update a couple more callsites to @memset
This commit is contained in:
parent
cb9e8b0d01
commit
0794e48b91
@ -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.
|
// Uses Knuth's Algorithm D, 4.3.1, p. 272.
|
||||||
fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
|
fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
|
||||||
if (q) |q_| std.mem.set(u32, q_[0..], 0);
|
if (q) |q_| @memset(q_[0..], 0);
|
||||||
if (r) |r_| std.mem.set(u32, r_[0..], 0);
|
if (r) |r_| @memset(r_[0..], 0);
|
||||||
|
|
||||||
if (u.len == 0 or v.len == 0) return error.DivisionByZero;
|
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 (n > m) {
|
||||||
if (r) |r_| std.mem.copy(u32, r_[0..], u[0..]);
|
if (r) |r_| @memcpy(r_[0..u.len], u);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
pub const copy = copyForwards;
|
||||||
|
|
||||||
/// Copy all of source into dest at position 0.
|
/// 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 const set = @compileError("deprecated; use @memset instead");
|
||||||
pub fn set(comptime T: type, dest: []T, value: T) void {
|
|
||||||
for (dest) |*d|
|
|
||||||
d.* = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
|
/// 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
|
/// 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 (@sizeOf(T) == 0) return undefined;
|
||||||
if (struct_info.layout == .Extern) {
|
if (struct_info.layout == .Extern) {
|
||||||
var item: T = undefined;
|
var item: T = undefined;
|
||||||
set(u8, asBytes(&item), 0);
|
@memset(asBytes(&item), 0);
|
||||||
return item;
|
return item;
|
||||||
} else {
|
} else {
|
||||||
var structure: T = undefined;
|
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));
|
assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
|
||||||
|
|
||||||
if (@typeInfo(T).Int.bits == 0) {
|
if (@typeInfo(T).Int.bits == 0) {
|
||||||
return set(u8, buffer, 0);
|
return @memset(buffer, 0);
|
||||||
} else if (@typeInfo(T).Int.bits == 8) {
|
} else if (@typeInfo(T).Int.bits == 8) {
|
||||||
set(u8, buffer, 0);
|
@memset(buffer, 0);
|
||||||
buffer[0] = @bitCast(u8, value);
|
buffer[0] = @bitCast(u8, value);
|
||||||
return;
|
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));
|
assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
|
||||||
|
|
||||||
if (@typeInfo(T).Int.bits == 0) {
|
if (@typeInfo(T).Int.bits == 0) {
|
||||||
return set(u8, buffer, 0);
|
return @memset(buffer, 0);
|
||||||
} else if (@typeInfo(T).Int.bits == 8) {
|
} else if (@typeInfo(T).Int.bits == 8) {
|
||||||
set(u8, buffer, 0);
|
@memset(buffer, 0);
|
||||||
buffer[buffer.len - 1] = @bitCast(u8, value);
|
buffer[buffer.len - 1] = @bitCast(u8, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2708,7 +2705,7 @@ fn testReadIntImpl() !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "writeIntSlice" {
|
test writeIntSlice {
|
||||||
try testWriteIntImpl();
|
try testWriteIntImpl();
|
||||||
comptime try testWriteIntImpl();
|
comptime try testWriteIntImpl();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user