Commit 6261c13731
Changed files (121)
lib
std
compress
lzma
decode
zstandard
decode
crypto
pcurves
tls
fmt
fs
json
math
big
os
testing
src
arch
aarch64
arm
riscv64
sparc64
codegen
lib/std/Build/Cache.zig
@@ -388,7 +388,7 @@ pub const Manifest = struct {
self.hash.hasher = hasher_init;
self.hash.hasher.update(&bin_digest);
- mem.copy(u8, &manifest_file_path, &self.hex_digest);
+ @memcpy(manifest_file_path[0..self.hex_digest.len], &self.hex_digest);
manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;
if (self.files.items.len == 0) {
lib/std/Build/CompileStep.zig
@@ -1139,7 +1139,7 @@ fn appendModuleArgs(
// We'll use this buffer to store the name we decide on
var buf = try b.allocator.alloc(u8, dep.name.len + 32);
// First, try just the exposed dependency name
- std.mem.copy(u8, buf, dep.name);
+ @memcpy(buf[0..dep.name.len], dep.name);
var name = buf[0..dep.name.len];
var n: usize = 0;
while (names.contains(name)) {
lib/std/compress/deflate/compressor.zig
@@ -543,7 +543,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
self.hash_offset = 1;
self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);
self.tokens_count = 0;
- mem.set(token.Token, self.tokens, 0);
+ @memset(self.tokens, 0);
self.length = min_match_length - 1;
self.offset = 0;
self.byte_available = false;
@@ -841,9 +841,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
s.hash_head = try allocator.alloc(u32, hash_size);
s.hash_prev = try allocator.alloc(u32, window_size);
s.hash_match = try allocator.alloc(u32, max_match_length - 1);
- mem.set(u32, s.hash_head, 0);
- mem.set(u32, s.hash_prev, 0);
- mem.set(u32, s.hash_match, 0);
+ @memset(s.hash_head, 0);
+ @memset(s.hash_prev, 0);
+ @memset(s.hash_match, 0);
switch (options.level) {
.no_compression => {
@@ -936,8 +936,8 @@ pub fn Compressor(comptime WriterType: anytype) type {
.best_compression,
=> {
self.chain_head = 0;
- mem.set(u32, self.hash_head, 0);
- mem.set(u32, self.hash_prev, 0);
+ @memset(self.hash_head, 0);
+ @memset(self.hash_prev, 0);
self.hash_offset = 1;
self.index = 0;
self.window_end = 0;
lib/std/compress/deflate/decompressor.zig
@@ -159,7 +159,7 @@ const HuffmanDecoder = struct {
if (sanity) {
// initialize to a known invalid chunk code (0) to see if we overwrite
// this value later on
- mem.set(u16, self.links[off], 0);
+ @memset(self.links[off], 0);
}
try self.sub_chunks.append(off);
}
lib/std/compress/deflate/deflate_fast.zig
@@ -566,11 +566,11 @@ test "best speed match 2/2" {
for (cases) |c| {
var previous = try testing.allocator.alloc(u8, c.previous);
defer testing.allocator.free(previous);
- mem.set(u8, previous, 0);
+ @memset(previous, 0);
var current = try testing.allocator.alloc(u8, c.current);
defer testing.allocator.free(current);
- mem.set(u8, current, 0);
+ @memset(current, 0);
var e = DeflateFast{
.prev = previous,
lib/std/compress/lzma/decode/rangecoder.zig
@@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {
}
pub fn reset(self: *Self) void {
- mem.set(u16, &self.probs, 0x400);
+ @memset(&self.probs, 0x400);
}
};
}
lib/std/compress/lzma/vec2d.zig
@@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {
pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {
const len = try math.mul(usize, size[0], size[1]);
const data = try allocator.alloc(T, len);
- mem.set(T, data, value);
+ @memset(data, value);
return Self{
.data = data,
.cols = size[1],
@@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {
}
pub fn fill(self: *Self, value: T) void {
- mem.set(T, self.data, value);
+ @memset(self.data, value);
}
inline fn _get(self: Self, row: usize) ![]T {
lib/std/compress/zstandard/decode/block.zig
@@ -293,10 +293,10 @@ pub const DecodeState = struct {
try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);
const copy_start = write_pos + sequence.literal_length - sequence.offset;
- const copy_end = copy_start + sequence.match_length;
- // NOTE: we ignore the usage message for std.mem.copy and copy with dest.ptr >= src.ptr
- // to allow repeats
- std.mem.copy(u8, dest[write_pos + sequence.literal_length ..], dest[copy_start..copy_end]);
+ for (
+ dest[write_pos + sequence.literal_length ..][0..sequence.match_length],
+ dest[copy_start..][0..sequence.match_length],
+ ) |*d, s| d.* = s;
self.written_count += sequence.match_length;
}
@@ -311,7 +311,6 @@ pub const DecodeState = struct {
try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);
const copy_start = dest.write_index + dest.data.len - sequence.offset;
const copy_slice = dest.sliceAt(copy_start, sequence.match_length);
- // TODO: would std.mem.copy and figuring out dest slice be better/faster?
for (copy_slice.first) |b| dest.writeAssumeCapacity(b);
for (copy_slice.second) |b| dest.writeAssumeCapacity(b);
self.written_count += sequence.match_length;
@@ -444,9 +443,8 @@ pub const DecodeState = struct {
switch (self.literal_header.block_type) {
.raw => {
- const literals_end = self.literal_written_count + len;
- const literal_data = self.literal_streams.one[self.literal_written_count..literals_end];
- std.mem.copy(u8, dest, literal_data);
+ const literal_data = self.literal_streams.one[self.literal_written_count..][0..len];
+ @memcpy(dest[0..len], literal_data);
self.literal_written_count += len;
self.written_count += len;
},
@@ -615,8 +613,7 @@ pub fn decodeBlock(
.raw => {
if (src.len < block_size) return error.MalformedBlockSize;
if (dest[written_count..].len < block_size) return error.DestTooSmall;
- const data = src[0..block_size];
- std.mem.copy(u8, dest[written_count..], data);
+ @memcpy(dest[written_count..][0..block_size], src[0..block_size]);
consumed_count.* += block_size;
decode_state.written_count += block_size;
return block_size;
lib/std/compress/lzma.zig
@@ -75,9 +75,9 @@ pub fn Decompress(comptime ReaderType: type) type {
}
}
const input = self.to_read.items;
- const n = math.min(input.len, output.len);
- mem.copy(u8, output[0..n], input[0..n]);
- mem.copy(u8, input, input[n..]);
+ const n = @min(input.len, output.len);
+ @memcpy(output[0..n], input[0..n]);
+ @memcpy(input[0 .. input.len - n], input[n..]);
self.to_read.shrinkRetainingCapacity(input.len - n);
return n;
}
lib/std/crypto/25519/ed25519.zig
@@ -79,8 +79,8 @@ pub const Ed25519 = struct {
const r_bytes = r.toBytes();
var t: [64]u8 = undefined;
- mem.copy(u8, t[0..32], &r_bytes);
- mem.copy(u8, t[32..], &public_key.bytes);
+ t[0..32].* = r_bytes;
+ t[32..].* = public_key.bytes;
var h = Sha512.init(.{});
h.update(&t);
@@ -200,8 +200,8 @@ pub const Ed25519 = struct {
/// Return the raw signature (r, s) in little-endian format.
pub fn toBytes(self: Signature) [encoded_length]u8 {
var bytes: [encoded_length]u8 = undefined;
- mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
- mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
+ bytes[0 .. encoded_length / 2].* = self.r;
+ bytes[encoded_length / 2 ..].* = self.s;
return bytes;
}
@@ -260,8 +260,8 @@ pub const Ed25519 = struct {
const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;
const pk_bytes = pk_p.toBytes();
var sk_bytes: [SecretKey.encoded_length]u8 = undefined;
- mem.copy(u8, &sk_bytes, &ss);
- mem.copy(u8, sk_bytes[seed_length..], &pk_bytes);
+ sk_bytes[0..ss.len].* = ss;
+ sk_bytes[seed_length..].* = pk_bytes;
return KeyPair{
.public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,
.secret_key = try SecretKey.fromBytes(sk_bytes),
@@ -373,7 +373,7 @@ pub const Ed25519 = struct {
var z_batch: [count]Curve.scalar.CompressedScalar = undefined;
for (&z_batch) |*z| {
crypto.random.bytes(z[0..16]);
- mem.set(u8, z[16..], 0);
+ @memset(z[16..], 0);
}
var zs_sum = Curve.scalar.zero;
@@ -444,8 +444,8 @@ pub const Ed25519 = struct {
};
var prefix: [64]u8 = undefined;
- mem.copy(u8, prefix[0..32], h[32..64]);
- mem.copy(u8, prefix[32..64], blind_h[32..64]);
+ prefix[0..32].* = h[32..64].*;
+ prefix[32..64].* = blind_h[32..64].*;
const blind_secret_key = BlindSecretKey{
.prefix = prefix,
lib/std/crypto/25519/edwards25519.zig
@@ -306,7 +306,7 @@ pub const Edwards25519 = struct {
var pcs: [count][9]Edwards25519 = undefined;
var bpc: [9]Edwards25519 = undefined;
- mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]);
+ @memcpy(&bpc, basePointPc[0..bpc.len]);
for (ps, 0..) |p, i| {
if (p.is_base) {
@@ -439,7 +439,7 @@ pub const Edwards25519 = struct {
var u: [n * H.digest_length]u8 = undefined;
var i: usize = 0;
while (i < n * H.digest_length) : (i += H.digest_length) {
- mem.copy(u8, u[i..][0..H.digest_length], u_0[0..]);
+ u[i..][0..H.digest_length].* = u_0;
var j: usize = 0;
while (i > 0 and j < H.digest_length) : (j += 1) {
u[i + j] ^= u[i + j - H.digest_length];
@@ -455,8 +455,8 @@ pub const Edwards25519 = struct {
var px: [n]Edwards25519 = undefined;
i = 0;
while (i < n) : (i += 1) {
- mem.set(u8, u_0[0 .. H.digest_length - h_l], 0);
- mem.copy(u8, u_0[H.digest_length - h_l ..][0..h_l], u[i * h_l ..][0..h_l]);
+ @memset(u_0[0 .. H.digest_length - h_l], 0);
+ u_0[H.digest_length - h_l ..][0..h_l].* = u[i * h_l ..][0..h_l].*;
px[i] = fromHash(u_0);
}
return px;
lib/std/crypto/25519/scalar.zig
@@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {
pub fn neg(s: CompressedScalar) CompressedScalar {
const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;
var sx: [64]u8 = undefined;
- mem.copy(u8, sx[0..32], s[0..]);
- mem.set(u8, sx[32..], 0);
+ sx[0..32].* = s;
+ @memset(sx[32..], 0);
var carry: u32 = 0;
var i: usize = 0;
while (i < 64) : (i += 1) {
@@ -593,7 +593,7 @@ const ScalarDouble = struct {
limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
}
limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));
- mem.set(u64, limbs[5..], 0);
+ @memset(limbs[5..], 0);
return ScalarDouble{ .limbs = limbs };
}
lib/std/crypto/25519/x25519.zig
@@ -37,7 +37,7 @@ pub const X25519 = struct {
break :sk random_seed;
};
var kp: KeyPair = undefined;
- mem.copy(u8, &kp.secret_key, sk[0..]);
+ kp.secret_key = sk;
kp.public_key = try X25519.recoverPublicKey(sk);
return kp;
}
@@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {
var i: usize = 0;
while (i < 1) : (i += 1) {
const output = try X25519.scalarmult(k, u);
- mem.copy(u8, u[0..], k[0..]);
- mem.copy(u8, k[0..], output[0..]);
+ u = k;
+ k = output;
}
try std.testing.expectEqual(k, expected_output);
@@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {
var i: usize = 0;
while (i < 1000) : (i += 1) {
const output = try X25519.scalarmult(&k, &u);
- mem.copy(u8, u[0..], k[0..]);
- mem.copy(u8, k[0..], output[0..]);
+ u = k;
+ k = output;
}
try std.testing.expectEqual(k, expected_output);
@@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
var i: usize = 0;
while (i < 1000000) : (i += 1) {
const output = try X25519.scalarmult(&k, &u);
- mem.copy(u8, u[0..], k[0..]);
- mem.copy(u8, k[0..], output[0..]);
+ u = k;
+ k = output;
}
try std.testing.expectEqual(k[0..], expected_output);
lib/std/crypto/pcurves/p256/scalar.zig
@@ -192,20 +192,20 @@ const ScalarDouble = struct {
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
{
var b = [_]u8{0} ** encoded_length;
- const len = math.min(s.len, 24);
- mem.copy(u8, b[0..len], s[0..len]);
+ const len = @min(s.len, 24);
+ b[0..len].* = s[0..len].*;
t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 24) {
var b = [_]u8{0} ** encoded_length;
- const len = math.min(s.len - 24, 24);
- mem.copy(u8, b[0..len], s[24..][0..len]);
+ const len = @min(s.len - 24, 24);
+ b[0..len].* = s[24..][0..len].*;
t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 48) {
var b = [_]u8{0} ** encoded_length;
const len = s.len - 48;
- mem.copy(u8, b[0..len], s[48..][0..len]);
+ b[0..len].* = s[48..][0..len].*;
t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
}
return t;
lib/std/crypto/pcurves/p384/scalar.zig
@@ -180,14 +180,14 @@ const ScalarDouble = struct {
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
{
var b = [_]u8{0} ** encoded_length;
- const len = math.min(s.len, 32);
- mem.copy(u8, b[0..len], s[0..len]);
+ const len = @min(s.len, 32);
+ b[0..len].* = s[0..len].*;
t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 32) {
var b = [_]u8{0} ** encoded_length;
- const len = math.min(s.len - 32, 32);
- mem.copy(u8, b[0..len], s[32..][0..len]);
+ const len = @min(s.len - 32, 32);
+ b[0..len].* = s[32..][0..len].*;
t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
}
return t;
lib/std/crypto/pcurves/secp256k1/scalar.zig
@@ -192,20 +192,20 @@ const ScalarDouble = struct {
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
{
var b = [_]u8{0} ** encoded_length;
- const len = math.min(s.len, 24);
- mem.copy(u8, b[0..len], s[0..len]);
+ const len = @min(s.len, 24);
+ b[0..len].* = s[0..len].*;
t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 24) {
var b = [_]u8{0} ** encoded_length;
- const len = math.min(s.len - 24, 24);
- mem.copy(u8, b[0..len], s[24..][0..len]);
+ const len = @min(s.len - 24, 24);
+ b[0..len].* = s[24..][0..len].*;
t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 48) {
var b = [_]u8{0} ** encoded_length;
const len = s.len - 48;
- mem.copy(u8, b[0..len], s[48..][0..len]);
+ b[0..len].* = s[48..][0..len].*;
t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
}
return t;
lib/std/crypto/pcurves/common.zig
@@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {
}
if (iterations % 2 != 0) {
fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);
- mem.copy(Word, &v, &out4);
- mem.copy(Word, &f, &out2);
+ v = out4;
+ f = out2;
}
var v_opp: Limbs = undefined;
fiat.opp(&v_opp, v);
lib/std/crypto/pcurves/p256.zig
@@ -105,7 +105,7 @@ pub const P256 = struct {
var out: [33]u8 = undefined;
const xy = p.affineCoordinates();
out[0] = if (xy.y.isOdd()) 3 else 2;
- mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
+ out[1..].* = xy.x.toBytes(.Big);
return out;
}
@@ -114,8 +114,8 @@ pub const P256 = struct {
var out: [65]u8 = undefined;
out[0] = 4;
const xy = p.affineCoordinates();
- mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
- mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
+ out[1..33].* = xy.x.toBytes(.Big);
+ out[33..65].* = xy.y.toBytes(.Big);
return out;
}
lib/std/crypto/pcurves/p384.zig
@@ -105,7 +105,7 @@ pub const P384 = struct {
var out: [49]u8 = undefined;
const xy = p.affineCoordinates();
out[0] = if (xy.y.isOdd()) 3 else 2;
- mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
+ out[1..].* = xy.x.toBytes(.Big);
return out;
}
@@ -114,8 +114,8 @@ pub const P384 = struct {
var out: [97]u8 = undefined;
out[0] = 4;
const xy = p.affineCoordinates();
- mem.copy(u8, out[1..49], &xy.x.toBytes(.Big));
- mem.copy(u8, out[49..97], &xy.y.toBytes(.Big));
+ out[1..49].* = xy.x.toBytes(.Big);
+ out[49..97].* = xy.y.toBytes(.Big);
return out;
}
lib/std/crypto/pcurves/secp256k1.zig
@@ -158,7 +158,7 @@ pub const Secp256k1 = struct {
var out: [33]u8 = undefined;
const xy = p.affineCoordinates();
out[0] = if (xy.y.isOdd()) 3 else 2;
- mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
+ out[1..].* = xy.x.toBytes(.Big);
return out;
}
@@ -167,8 +167,8 @@ pub const Secp256k1 = struct {
var out: [65]u8 = undefined;
out[0] = 4;
const xy = p.affineCoordinates();
- mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
- mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
+ out[1..33].* = xy.x.toBytes(.Big);
+ out[33..65].* = xy.y.toBytes(.Big);
return out;
}
lib/std/crypto/tls/Client.zig
@@ -685,7 +685,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
.application_cipher = app_cipher,
.partially_read_buffer = undefined,
};
- mem.copy(u8, &client.partially_read_buffer, leftover);
+ @memcpy(client.partially_read_buffer[0..leftover.len], leftover);
return client;
},
else => {
@@ -809,7 +809,7 @@ fn prepareCiphertextRecord(
.overhead_len = overhead_len,
};
- mem.copy(u8, &cleartext_buf, bytes[bytes_i..][0..encrypted_content_len]);
+ @memcpy(cleartext_buf[0..encrypted_content_len], bytes[bytes_i..][0..encrypted_content_len]);
cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);
bytes_i += encrypted_content_len;
const ciphertext_len = encrypted_content_len + 1;
@@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
if (frag1.len < second_len)
return finishRead2(c, first, frag1, vp.total);
- mem.copy(u8, frag[0..in], first);
- mem.copy(u8, frag[first.len..], frag1[0..second_len]);
+ @memcpy(frag[0..in], first);
+ @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
frag = frag[0..full_record_len];
frag1 = frag1[second_len..];
in = 0;
@@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
if (frag1.len < second_len)
return finishRead2(c, first, frag1, vp.total);
- mem.copy(u8, frag[0..in], first);
- mem.copy(u8, frag[first.len..], frag1[0..second_len]);
+ @memcpy(frag[0..in], first);
+ @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
frag = frag[0..full_record_len];
frag1 = frag1[second_len..];
in = 0;
@@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
// We have already run out of room in iovecs. Continue
// appending to `partially_read_buffer`.
const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];
- mem.copy(u8, dest, msg);
+ @memcpy(dest[0..msg.len], msg);
c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);
} else {
const amt = vp.put(msg);
@@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
const rest = msg[amt..];
c.partial_cleartext_idx = 0;
c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), rest.len);
- mem.copy(u8, &c.partially_read_buffer, rest);
+ @memcpy(c.partially_read_buffer[0..rest.len], rest);
}
}
} else {
@@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
// There is cleartext at the beginning already which we need to preserve.
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + saved_buf.len);
- mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], saved_buf);
+ @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..saved_buf.len], saved_buf);
} else {
c.partial_cleartext_idx = 0;
c.partial_ciphertext_idx = 0;
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), saved_buf.len);
- mem.copy(u8, &c.partially_read_buffer, saved_buf);
+ @memcpy(c.partially_read_buffer[0..saved_buf.len], saved_buf);
}
return out;
}
@@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi
if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
// There is cleartext at the beginning already which we need to preserve.
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + first.len + frag1.len);
- mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], first);
- mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..], frag1);
+ @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
+ @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
} else {
c.partial_cleartext_idx = 0;
c.partial_ciphertext_idx = 0;
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);
- mem.copy(u8, &c.partially_read_buffer, first);
- mem.copy(u8, c.partially_read_buffer[first.len..], frag1);
+ @memcpy(c.partially_read_buffer[0..first.len], first);
+ @memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);
}
return out;
}
@@ -1282,7 +1282,7 @@ const VecPut = struct {
const v = vp.iovecs[vp.idx];
const dest = v.iov_base[vp.off..v.iov_len];
const src = bytes[bytes_i..][0..@min(dest.len, bytes.len - bytes_i)];
- mem.copy(u8, dest, src);
+ @memcpy(dest[0..src.len], src);
bytes_i += src.len;
vp.off += src.len;
if (vp.off >= v.iov_len) {
lib/std/crypto/aegis.zig
@@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.absorb(ad[i..][0..32]);
}
if (ad.len % 32 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
state.absorb(&src);
}
i = 0;
@@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.enc(c[i..][0..32], m[i..][0..32]);
}
if (m.len % 32 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. m.len % 32], m[i .. i + m.len % 32]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. m.len % 32], m[i..][0 .. m.len % 32]);
state.enc(&dst, &src);
- mem.copy(u8, c[i .. i + m.len % 32], dst[0 .. m.len % 32]);
+ @memcpy(c[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
}
tag.* = state.mac(tag_bits, ad.len, m.len);
}
@@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.absorb(ad[i..][0..32]);
}
if (ad.len % 32 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
state.absorb(&src);
}
i = 0;
@@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.dec(m[i..][0..32], c[i..][0..32]);
}
if (m.len % 32 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. m.len % 32], c[i .. i + m.len % 32]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. m.len % 32], c[i..][0 .. m.len % 32]);
state.dec(&dst, &src);
- mem.copy(u8, m[i .. i + m.len % 32], dst[0 .. m.len % 32]);
- mem.set(u8, dst[0 .. m.len % 32], 0);
+ @memcpy(m[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
+ @memset(dst[0 .. m.len % 32], 0);
const blocks = &state.blocks;
blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));
blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));
@@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.enc(&dst, ad[i..][0..16]);
}
if (ad.len % 16 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
state.enc(&dst, &src);
}
i = 0;
@@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.enc(c[i..][0..16], m[i..][0..16]);
}
if (m.len % 16 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. m.len % 16], m[i .. i + m.len % 16]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. m.len % 16], m[i..][0 .. m.len % 16]);
state.enc(&dst, &src);
- mem.copy(u8, c[i .. i + m.len % 16], dst[0 .. m.len % 16]);
+ @memcpy(c[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
}
tag.* = state.mac(tag_bits, ad.len, m.len);
}
@@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.enc(&dst, ad[i..][0..16]);
}
if (ad.len % 16 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
state.enc(&dst, &src);
}
i = 0;
@@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.dec(m[i..][0..16], c[i..][0..16]);
}
if (m.len % 16 != 0) {
- mem.set(u8, src[0..], 0);
- mem.copy(u8, src[0 .. m.len % 16], c[i .. i + m.len % 16]);
+ @memset(src[0..], 0);
+ @memcpy(src[0 .. m.len % 16], c[i..][0 .. m.len % 16]);
state.dec(&dst, &src);
- mem.copy(u8, m[i .. i + m.len % 16], dst[0 .. m.len % 16]);
- mem.set(u8, dst[0 .. m.len % 16], 0);
+ @memcpy(m[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
+ @memset(dst[0 .. m.len % 16], 0);
const blocks = &state.blocks;
blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));
}
@@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {
self.msg_len += b.len;
const len_partial = @min(b.len, block_length - self.off);
- mem.copy(u8, self.buf[self.off..][0..len_partial], b[0..len_partial]);
+ @memcpy(self.buf[self.off..][0..len_partial], b[0..len_partial]);
self.off += len_partial;
if (self.off < block_length) {
return;
@@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {
self.state.absorb(b[i..][0..block_length]);
}
if (i != b.len) {
- mem.copy(u8, self.buf[0..], b[i..]);
+ @memcpy(self.buf[0..], b[i..]);
self.off = b.len - i;
}
}
@@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {
pub fn final(self: *Self, out: *[mac_length]u8) void {
if (self.off > 0) {
var pad = [_]u8{0} ** block_length;
- mem.copy(u8, pad[0..], self.buf[0..self.off]);
+ @memcpy(pad[0..self.off], self.buf[0..self.off]);
self.state.absorb(&pad);
}
out.* = self.state.mac(T.tag_length * 8, self.msg_len, 0);
lib/std/crypto/aes_gcm.zig
@@ -31,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {
var t: [16]u8 = undefined;
var j: [16]u8 = undefined;
- mem.copy(u8, j[0..nonce_length], npub[0..]);
+ j[0..nonce_length].* = npub;
mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
aes.encrypt(&t, &j);
@@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {
var t: [16]u8 = undefined;
var j: [16]u8 = undefined;
- mem.copy(u8, j[0..nonce_length], npub[0..]);
+ j[0..nonce_length].* = npub;
mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
aes.encrypt(&t, &j);
lib/std/crypto/aes_ocb.zig
@@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {
if (leftover > 0) {
xorWith(&offset, lx.star);
var padded = [_]u8{0} ** 16;
- mem.copy(u8, padded[0..leftover], a[i * 16 ..][0..leftover]);
+ @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]);
padded[leftover] = 1;
var e = xorBlocks(offset, padded);
aes_enc_ctx.encrypt(&e, &e);
@@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {
var nx = [_]u8{0} ** 16;
nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);
nx[16 - nonce_length - 1] = 1;
- mem.copy(u8, nx[16 - nonce_length ..], &npub);
+ nx[nx.len - nonce_length ..].* = npub;
const bottom = @truncate(u6, nx[15]);
nx[15] &= 0xc0;
@@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {
xorWith(&offset, lt[@ctz(i + 1 + j)]);
offsets[j] = offset;
const p = m[(i + j) * 16 ..][0..16].*;
- mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(p, offsets[j]));
+ es[j * 16 ..][0..16].* = xorBlocks(p, offsets[j]);
xorWith(&sum, p);
}
aes_enc_ctx.encryptWide(wb, &es, &es);
j = 0;
while (j < wb) : (j += 1) {
const e = es[j * 16 ..][0..16].*;
- mem.copy(u8, c[(i + j) * 16 ..][0..16], &xorBlocks(e, offsets[j]));
+ c[(i + j) * 16 ..][0..16].* = xorBlocks(e, offsets[j]);
}
}
while (i < full_blocks) : (i += 1) {
@@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {
const p = m[i * 16 ..][0..16].*;
var e = xorBlocks(p, offset);
aes_enc_ctx.encrypt(&e, &e);
- mem.copy(u8, c[i * 16 ..][0..16], &xorBlocks(e, offset));
+ c[i * 16 ..][0..16].* = xorBlocks(e, offset);
xorWith(&sum, p);
}
const leftover = m.len % 16;
@@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {
c[i * 16 + j] = pad[j] ^ x;
}
var e = [_]u8{0} ** 16;
- mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);
+ @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
e[leftover] = 0x80;
xorWith(&sum, e);
}
@@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {
xorWith(&offset, lt[@ctz(i + 1 + j)]);
offsets[j] = offset;
const q = c[(i + j) * 16 ..][0..16].*;
- mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(q, offsets[j]));
+ es[j * 16 ..][0..16].* = xorBlocks(q, offsets[j]);
}
aes_dec_ctx.decryptWide(wb, &es, &es);
j = 0;
while (j < wb) : (j += 1) {
const p = xorBlocks(es[j * 16 ..][0..16].*, offsets[j]);
- mem.copy(u8, m[(i + j) * 16 ..][0..16], &p);
+ m[(i + j) * 16 ..][0..16].* = p;
xorWith(&sum, p);
}
}
@@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {
var e = xorBlocks(q, offset);
aes_dec_ctx.decrypt(&e, &e);
const p = xorBlocks(e, offset);
- mem.copy(u8, m[i * 16 ..][0..16], &p);
+ m[i * 16 ..][0..16].* = p;
xorWith(&sum, p);
}
const leftover = m.len % 16;
@@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {
m[i * 16 + j] = pad[j] ^ x;
}
var e = [_]u8{0} ** 16;
- mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);
+ @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
e[leftover] = 0x80;
xorWith(&sum, e);
}
lib/std/crypto/argon2.zig
@@ -494,7 +494,7 @@ pub fn kdf(
if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;
var h0 = initHash(password, salt, params, derived_key.len, mode);
- const memory = math.max(
+ const memory = @max(
params.m / (sync_points * params.p) * (sync_points * params.p),
2 * sync_points * params.p,
);
@@ -877,7 +877,7 @@ test "kdf" {
.hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",
},
};
- inline for (test_vectors) |v| {
+ for (test_vectors) |v| {
var want: [24]u8 = undefined;
_ = try std.fmt.hexToBytes(&want, v.hash);
lib/std/crypto/ascon.zig
@@ -34,7 +34,7 @@ pub fn State(comptime endian: builtin.Endian) type {
/// Initialize the state from a slice of bytes.
pub fn init(initial_state: [block_bytes]u8) Self {
var state = Self{ .st = undefined };
- mem.copy(u8, state.asBytes(), &initial_state);
+ @memcpy(state.asBytes(), &initial_state);
state.endianSwap();
return state;
}
@@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** 8;
- mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
+ @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / 8] = mem.readInt(u64, padded[0..], endian);
}
}
@@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** 8;
- mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
+ @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);
}
}
@@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {
if (i < out.len) {
var padded = [_]u8{0} ** 8;
mem.writeInt(u64, padded[0..], self.st[i / 8], endian);
- mem.copy(u8, out[i..], padded[0 .. out.len - i]);
+ @memcpy(out[i..], padded[0 .. out.len - i]);
}
}
@@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {
}
if (i < in.len) {
var padded = [_]u8{0} ** 8;
- mem.copy(u8, padded[0 .. in.len - i], in[i..]);
+ @memcpy(padded[0 .. in.len - i], in[i..]);
const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);
mem.writeIntNative(u64, &padded, x);
- mem.copy(u8, out[i..], padded[0 .. in.len - i]);
+ @memcpy(out[i..], padded[0 .. in.len - i]);
}
}
/// Set the words storing the bytes of a given range to zero.
pub fn clear(self: *Self, from: usize, to: usize) void {
- mem.set(u64, self.st[from / 8 .. (to + 7) / 8], 0);
+ @memset(self.st[from / 8 .. (to + 7) / 8], 0);
}
/// Clear the entire state, disabling compiler optimizations.
lib/std/crypto/bcrypt.zig
@@ -416,8 +416,8 @@ pub fn bcrypt(
) [dk_length]u8 {
var state = State{};
var password_buf: [73]u8 = undefined;
- const trimmed_len = math.min(password.len, password_buf.len - 1);
- mem.copy(u8, password_buf[0..], password[0..trimmed_len]);
+ const trimmed_len = @min(password.len, password_buf.len - 1);
+ @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
password_buf[trimmed_len] = 0;
var passwordZ = password_buf[0 .. trimmed_len + 1];
state.expand(salt[0..], passwordZ);
@@ -626,7 +626,7 @@ const CryptFormatHasher = struct {
crypto.random.bytes(&salt);
const hash = crypt_format.strHashInternal(password, salt, params);
- mem.copy(u8, buf, &hash);
+ @memcpy(buf[0..hash.len], &hash);
return buf[0..pwhash_str_length];
}
lib/std/crypto/benchmark.zig
@@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
var i: usize = 0;
while (i < exchange_count) : (i += 1) {
const out = try DhKeyExchange.scalarmult(secret, public);
- mem.copy(u8, secret[0..16], out[0..16]);
- mem.copy(u8, public[0..16], out[16..32]);
+ secret[0..16].* = out[0..16].*;
+ public[0..16].* = out[16..32].*;
mem.doNotOptimizeAway(&out);
}
}
lib/std/crypto/blake2.zig
@@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
comptime debug.assert(8 <= out_bits and out_bits <= 256);
var d: Self = undefined;
- mem.copy(u32, d.h[0..], iv[0..]);
+ d.h = iv;
const key_len = if (options.key) |key| key.len else 0;
// default parameters
@@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
d.h[7] ^= mem.readIntLittle(u32, context[4..8]);
}
if (key_len > 0) {
- mem.set(u8, d.buf[key_len..], 0);
+ @memset(d.buf[key_len..], 0);
d.update(options.key.?);
d.buf_len = 64;
}
@@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len > 64) {
off += 64 - d.buf_len;
- mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
+ @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.t += 64;
d.round(d.buf[0..], false);
d.buf_len = 0;
@@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {
}
// Copy any remainder for next pass.
- mem.copy(u8, d.buf[d.buf_len..], b[off..]);
- d.buf_len += @intCast(u8, b[off..].len);
+ const b_slice = b[off..];
+ @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
+ d.buf_len += @intCast(u8, b_slice.len);
}
pub fn final(d: *Self, out: *[digest_length]u8) void {
- mem.set(u8, d.buf[d.buf_len..], 0);
+ @memset(d.buf[d.buf_len..], 0);
d.t += d.buf_len;
d.round(d.buf[0..], true);
for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
- mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
+ out.* = @ptrCast(*[digest_length]u8, &d.h).*;
}
fn round(d: *Self, b: *const [64]u8, last: bool) void {
@@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
comptime debug.assert(8 <= out_bits and out_bits <= 512);
var d: Self = undefined;
- mem.copy(u64, d.h[0..], iv[0..]);
+ d.h = iv;
const key_len = if (options.key) |key| key.len else 0;
// default parameters
@@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
d.h[7] ^= mem.readIntLittle(u64, context[8..16]);
}
if (key_len > 0) {
- mem.set(u8, d.buf[key_len..], 0);
+ @memset(d.buf[key_len..], 0);
d.update(options.key.?);
d.buf_len = 128;
}
@@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len > 128) {
off += 128 - d.buf_len;
- mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
+ @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.t += 128;
d.round(d.buf[0..], false);
d.buf_len = 0;
@@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {
}
// Copy any remainder for next pass.
- mem.copy(u8, d.buf[d.buf_len..], b[off..]);
- d.buf_len += @intCast(u8, b[off..].len);
+ const b_slice = b[off..];
+ @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
+ d.buf_len += @intCast(u8, b_slice.len);
}
pub fn final(d: *Self, out: *[digest_length]u8) void {
- mem.set(u8, d.buf[d.buf_len..], 0);
+ @memset(d.buf[d.buf_len..], 0);
d.t += d.buf_len;
d.round(d.buf[0..], true);
for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
- mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
+ out.* = @ptrCast(*[digest_length]u8, &d.h).*;
}
fn round(d: *Self, b: *const [128]u8, last: bool) void {
lib/std/crypto/blake3.zig
@@ -253,7 +253,7 @@ const Output = struct {
while (out_word_it.next()) |out_word| {
var word_bytes: [4]u8 = undefined;
mem.writeIntLittle(u32, &word_bytes, words[word_counter]);
- mem.copy(u8, out_word, word_bytes[0..out_word.len]);
+ @memcpy(out_word, word_bytes[0..out_word.len]);
word_counter += 1;
}
output_block_counter += 1;
@@ -284,7 +284,7 @@ const ChunkState = struct {
fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {
const want = BLOCK_LEN - self.block_len;
const take = math.min(want, input.len);
- mem.copy(u8, self.block[self.block_len..][0..take], input[0..take]);
+ @memcpy(self.block[self.block_len..][0..take], input[0..take]);
self.block_len += @truncate(u8, take);
return input[take..];
}
@@ -336,8 +336,8 @@ fn parentOutput(
flags: u8,
) Output {
var block_words: [16]u32 align(16) = undefined;
- mem.copy(u32, block_words[0..8], left_child_cv[0..]);
- mem.copy(u32, block_words[8..], right_child_cv[0..]);
+ block_words[0..8].* = left_child_cv;
+ block_words[8..].* = right_child_cv;
return Output{
.input_chaining_value = key,
.block_words = block_words,
lib/std/crypto/Certificate.zig
@@ -928,7 +928,7 @@ pub const rsa = struct {
pub const PSSSignature = struct {
pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {
var result = [1]u8{0} ** modulus_len;
- std.mem.copy(u8, &result, msg);
+ std.mem.copyForwards(u8, &result, msg);
return result;
}
@@ -1025,9 +1025,9 @@ pub const rsa = struct {
// initial zero octets.
var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);
defer allocator.free(m_p);
- std.mem.copy(u8, m_p, &([_]u8{0} ** 8));
- std.mem.copy(u8, m_p[8..], &mHash);
- std.mem.copy(u8, m_p[(8 + Hash.digest_length)..], salt);
+ std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8));
+ std.mem.copyForwards(u8, m_p[8..], &mHash);
+ std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt);
// 13. Let H' = Hash(M'), an octet string of length hLen.
var h_p: [Hash.digest_length]u8 = undefined;
@@ -1047,7 +1047,7 @@ pub const rsa = struct {
var hash = try allocator.alloc(u8, seed.len + c.len);
defer allocator.free(hash);
- std.mem.copy(u8, hash, seed);
+ std.mem.copyForwards(u8, hash, seed);
var hashed: [Hash.digest_length]u8 = undefined;
while (idx < len) {
@@ -1056,10 +1056,10 @@ pub const rsa = struct {
c[2] = @intCast(u8, (counter >> 8) & 0xFF);
c[3] = @intCast(u8, counter & 0xFF);
- std.mem.copy(u8, hash[seed.len..], &c);
+ std.mem.copyForwards(u8, hash[seed.len..], &c);
Hash.hash(hash, &hashed, .{});
- std.mem.copy(u8, out[idx..], &hashed);
+ std.mem.copyForwards(u8, out[idx..], &hashed);
idx += hashed.len;
counter += 1;
lib/std/crypto/chacha20.zig
@@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {
var buf: [64]u8 = undefined;
hashToBytes(buf[0..], x);
- mem.copy(u8, out[i..], buf[0 .. out.len - i]);
+ @memcpy(out[i..], buf[0 .. out.len - i]);
}
}
@@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
var buf: [64]u8 = undefined;
hashToBytes(buf[0..], x);
- mem.copy(u8, out[i..], buf[0 .. out.len - i]);
+ @memcpy(out[i..], buf[0 .. out.len - i]);
}
}
@@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {
fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {
var subnonce: [12]u8 = undefined;
- mem.set(u8, subnonce[0..4], 0);
- mem.copy(u8, subnonce[4..], nonce[16..24]);
+ @memset(subnonce[0..4], 0);
+ subnonce[4..].* = nonce[16..24].*;
return .{
.key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),
.nonce = subnonce,
lib/std/crypto/ecdsa.zig
@@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
/// Return the raw signature (r, s) in big-endian format.
pub fn toBytes(self: Signature) [encoded_length]u8 {
var bytes: [encoded_length]u8 = undefined;
- mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
- mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
+ @memcpy(bytes[0 .. encoded_length / 2], &self.r);
+ @memcpy(bytes[encoded_length / 2 ..], &self.s);
return bytes;
}
@@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
if (unreduced_len >= 48) {
var xs = [_]u8{0} ** 64;
- mem.copy(u8, xs[xs.len - s.len ..], s[0..]);
+ @memcpy(xs[xs.len - s.len ..], s[0..]);
return Curve.scalar.Scalar.fromBytes64(xs, .Big);
}
var xs = [_]u8{0} ** 48;
- mem.copy(u8, xs[xs.len - s.len ..], s[0..]);
+ @memcpy(xs[xs.len - s.len ..], s[0..]);
return Curve.scalar.Scalar.fromBytes48(xs, .Big);
}
@@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];
const m_h = m[m.len - h.len ..];
- mem.set(u8, m_v, 0x01);
+ @memset(m_v, 0x01);
m_i.* = 0x00;
- if (noise) |n| mem.copy(u8, m_z, &n);
- mem.copy(u8, m_x, &secret_key);
- mem.copy(u8, m_h, &h);
+ if (noise) |n| @memcpy(m_z, &n);
+ @memcpy(m_x, &secret_key);
+ @memcpy(m_h, &h);
Hmac.create(&k, &m, &k);
Hmac.create(m_v, m_v, &k);
- mem.copy(u8, m_v, m_v);
m_i.* = 0x01;
Hmac.create(&k, &m, &k);
Hmac.create(m_v, m_v, &k);
@@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
while (t_off < t.len) : (t_off += m_v.len) {
const t_end = @min(t_off + m_v.len, t.len);
Hmac.create(m_v, m_v, &k);
- std.mem.copy(u8, t[t_off..t_end], m_v[0 .. t_end - t_off]);
+ @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]);
}
if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}
- mem.copy(u8, m_v, m_v);
m_i.* = 0x00;
Hmac.create(&k, m[0 .. m_v.len + 1], &k);
Hmac.create(m_v, m_v, &k);
lib/std/crypto/hkdf.zig
@@ -63,7 +63,7 @@ pub fn Hkdf(comptime Hmac: type) type {
st.update(&counter);
var tmp: [prk_length]u8 = undefined;
st.final(tmp[0..prk_length]);
- mem.copy(u8, out[i..][0..left], tmp[0..left]);
+ @memcpy(out[i..][0..left], tmp[0..left]);
}
}
};
lib/std/crypto/hmac.zig
@@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {
// Normalize key length to block size of hash
if (key.len > Hash.block_length) {
Hash.hash(key, scratch[0..mac_length], .{});
- mem.set(u8, scratch[mac_length..Hash.block_length], 0);
+ @memset(scratch[mac_length..Hash.block_length], 0);
} else if (key.len < Hash.block_length) {
- mem.copy(u8, scratch[0..key.len], key);
- mem.set(u8, scratch[key.len..Hash.block_length], 0);
+ @memcpy(scratch[0..key.len], key);
+ @memset(scratch[key.len..Hash.block_length], 0);
} else {
- mem.copy(u8, scratch[0..], key);
+ @memcpy(&scratch, key);
}
for (&ctx.o_key_pad, 0..) |*b, i| {
lib/std/crypto/isap.zig
@@ -43,7 +43,7 @@ pub const IsapA128A = struct {
}
} else {
var padded = [_]u8{0} ** 8;
- mem.copy(u8, padded[0..left], m[i..]);
+ @memcpy(padded[0..left], m[i..]);
padded[left] = 0x80;
isap.st.addBytes(&padded);
isap.st.permute();
lib/std/crypto/keccak_p.zig
@@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** @sizeOf(T);
- mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
+ @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);
}
}
@@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** @sizeOf(T);
- mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
+ @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);
}
}
@@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {
if (i < out.len) {
var padded = [_]u8{0} ** @sizeOf(T);
mem.writeIntLittle(T, padded[0..], self.st[i / @sizeOf(T)]);
- mem.copy(u8, out[i..], padded[0 .. out.len - i]);
+ @memcpy(out[i..], padded[0 .. out.len - i]);
}
}
@@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {
}
if (i < in.len) {
var padded = [_]u8{0} ** @sizeOf(T);
- mem.copy(u8, padded[0 .. in.len - i], in[i..]);
+ @memcpy(padded[0 .. in.len - i], in[i..]);
const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
mem.writeIntNative(T, &padded, x);
- mem.copy(u8, out[i..], padded[0 .. in.len - i]);
+ @memcpy(out[i..], padded[0 .. in.len - i]);
}
}
/// Set the words storing the bytes of a given range to zero.
pub fn clear(self: *Self, from: usize, to: usize) void {
- mem.set(T, self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);
+ @memset(self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);
}
/// Clear the entire state, disabling compiler optimizations.
@@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
var bytes = bytes_;
if (self.offset > 0) {
const left = math.min(rate - self.offset, bytes.len);
- mem.copy(u8, self.buf[self.offset..], bytes[0..left]);
+ @memcpy(self.buf[self.offset..][0..left], bytes[0..left]);
self.offset += left;
if (self.offset == rate) {
self.offset = 0;
@@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
bytes = bytes[rate..];
}
if (bytes.len > 0) {
- mem.copy(u8, &self.buf, bytes);
+ @memcpy(self.buf[0..bytes.len], bytes);
self.offset = bytes.len;
}
}
lib/std/crypto/kyber_d00.zig
@@ -1479,7 +1479,7 @@ test "MulHat" {
const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();
var p: Poly = undefined;
- mem.set(i16, &p.cs, 0);
+ @memset(&p.cs, 0);
for (0..N) |i| {
for (0..N) |j| {
lib/std/crypto/md5.zig
@@ -66,7 +66,7 @@ pub const Md5 = struct {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
off += 64 - d.buf_len;
- mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
+ @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(&d.buf);
d.buf_len = 0;
@@ -78,8 +78,9 @@ pub const Md5 = struct {
}
// Copy any remainder for next pass.
- mem.copy(u8, d.buf[d.buf_len..], b[off..]);
- d.buf_len += @intCast(u8, b[off..].len);
+ const b_slice = b[off..];
+ @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
+ d.buf_len += @intCast(u8, b_slice.len);
// Md5 uses the bottom 64-bits for length padding
d.total_len +%= b.len;
@@ -87,7 +88,7 @@ pub const Md5 = struct {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
- mem.set(u8, d.buf[d.buf_len..], 0);
+ @memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@@ -96,7 +97,7 @@ pub const Md5 = struct {
// > 448 mod 512 so need to add an extra round to wrap around.
if (64 - d.buf_len < 8) {
d.round(d.buf[0..]);
- mem.set(u8, d.buf[0..], 0);
+ @memset(d.buf[0..], 0);
}
// Append message length.
lib/std/crypto/modes.zig
@@ -38,8 +38,10 @@ pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8,
if (i < src.len) {
mem.writeInt(u128, &counter, counterInt, endian);
var pad = [_]u8{0} ** block_length;
- mem.copy(u8, &pad, src[i..]);
+ const src_slice = src[i..];
+ @memcpy(pad[0..src_slice.len], src_slice);
block_cipher.xor(&pad, &pad, counter);
- mem.copy(u8, dst[i..], pad[0 .. src.len - i]);
+ const pad_slice = pad[0 .. src.len - i];
+ @memcpy(dst[i..][0..pad_slice.len], pad_slice);
}
}
lib/std/crypto/pbkdf2.zig
@@ -129,13 +129,13 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com
const offset = block * h_len;
const block_len = if (block != blocks_count - 1) h_len else r;
const dk_block: []u8 = dk[offset..][0..block_len];
- mem.copy(u8, dk_block, prev_block[0..dk_block.len]);
+ @memcpy(dk_block, prev_block[0..dk_block.len]);
var i: u32 = 1;
while (i < rounds) : (i += 1) {
// U_c = PRF (P, U_{c-1})
Prf.create(&new_block, prev_block[0..], password);
- mem.copy(u8, prev_block[0..], new_block[0..]);
+ prev_block = new_block;
// F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
for (dk_block, 0..) |_, j| {
lib/std/crypto/phc_encoding.zig
@@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {
pub fn fromSlice(slice: []const u8) Error!Self {
if (slice.len > capacity) return Error.NoSpaceLeft;
var bin_value: Self = undefined;
- mem.copy(u8, &bin_value.buf, slice);
+ @memcpy(bin_value.buf[0..slice.len], slice);
bin_value.len = slice.len;
return bin_value;
}
lib/std/crypto/salsa20.zig
@@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {
debug.assert(c.len == m.len);
const extended = extend(rounds, k, npub);
var block0 = [_]u8{0} ** 64;
- const mlen0 = math.min(32, m.len);
- mem.copy(u8, block0[32..][0..mlen0], m[0..mlen0]);
+ const mlen0 = @min(32, m.len);
+ @memcpy(block0[32..][0..mlen0], m[0..mlen0]);
Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
- mem.copy(u8, c[0..mlen0], block0[32..][0..mlen0]);
+ @memcpy(c[0..mlen0], block0[32..][0..mlen0]);
Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);
var mac = Poly1305.init(block0[0..32]);
mac.update(ad);
@@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {
const extended = extend(rounds, k, npub);
var block0 = [_]u8{0} ** 64;
const mlen0 = math.min(32, c.len);
- mem.copy(u8, block0[32..][0..mlen0], c[0..mlen0]);
+ @memcpy(block0[32..][0..mlen0], c[0..mlen0]);
Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
var mac = Poly1305.init(block0[0..32]);
mac.update(ad);
@@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {
utils.secureZero(u8, &computedTag);
return error.AuthenticationFailed;
}
- mem.copy(u8, m[0..mlen0], block0[32..][0..mlen0]);
+ @memcpy(m[0..mlen0], block0[32..][0..mlen0]);
Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);
}
};
@@ -533,7 +533,7 @@ pub const SealedBox = struct {
debug.assert(c.len == m.len + seal_length);
var ekp = try KeyPair.create(null);
const nonce = createNonce(ekp.public_key, public_key);
- mem.copy(u8, c[0..public_length], ekp.public_key[0..]);
+ c[0..public_length].* = ekp.public_key;
try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);
utils.secureZero(u8, ekp.secret_key[0..]);
}
lib/std/crypto/sha1.zig
@@ -62,7 +62,7 @@ pub const Sha1 = struct {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
off += 64 - d.buf_len;
- mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
+ @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(d.buf[0..]);
d.buf_len = 0;
@@ -74,7 +74,7 @@ pub const Sha1 = struct {
}
// Copy any remainder for next pass.
- mem.copy(u8, d.buf[d.buf_len..], b[off..]);
+ @memcpy(d.buf[d.buf_len..][0 .. b.len - off], b[off..]);
d.buf_len += @intCast(u8, b[off..].len);
d.total_len += b.len;
@@ -82,7 +82,7 @@ pub const Sha1 = struct {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
- mem.set(u8, d.buf[d.buf_len..], 0);
+ @memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@@ -91,7 +91,7 @@ pub const Sha1 = struct {
// > 448 mod 512 so need to add an extra round to wrap around.
if (64 - d.buf_len < 8) {
d.round(d.buf[0..]);
- mem.set(u8, d.buf[0..], 0);
+ @memset(d.buf[0..], 0);
}
// Append message length.
lib/std/crypto/sha2.zig
@@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
off += 64 - d.buf_len;
- mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
+ @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(&d.buf);
d.buf_len = 0;
@@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {
}
// Copy any remainder for next pass.
- mem.copy(u8, d.buf[d.buf_len..], b[off..]);
+ const b_slice = b[off..];
+ @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
d.buf_len += @intCast(u8, b[off..].len);
d.total_len += b.len;
@@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
- mem.set(u8, d.buf[d.buf_len..], 0);
+ @memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
// > 448 mod 512 so need to add an extra round to wrap around.
if (64 - d.buf_len < 8) {
d.round(&d.buf);
- mem.set(u8, d.buf[0..], 0);
+ @memset(d.buf[0..], 0);
}
// Append message length.
@@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 128) {
off += 128 - d.buf_len;
- mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
+ @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(&d.buf);
d.buf_len = 0;
@@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {
}
// Copy any remainder for next pass.
- mem.copy(u8, d.buf[d.buf_len..], b[off..]);
+ const b_slice = b[off..];
+ @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
d.buf_len += @intCast(u8, b[off..].len);
d.total_len += b.len;
@@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
- mem.set(u8, d.buf[d.buf_len..], 0);
+ @memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
// > 896 mod 1024 so need to add an extra round to wrap around.
if (128 - d.buf_len < 16) {
d.round(d.buf[0..]);
- mem.set(u8, d.buf[0..], 0);
+ @memset(d.buf[0..], 0);
}
// Append message length.
lib/std/crypto/sha3.zig
@@ -149,7 +149,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
const left = self.buf.len - self.offset;
if (left > 0) {
const n = math.min(left, out.len);
- mem.copy(u8, out[0..n], self.buf[self.offset..][0..n]);
+ @memcpy(out[0..n], self.buf[self.offset..][0..n]);
out = out[n..];
self.offset += n;
if (out.len == 0) {
@@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
}
if (out.len > 0) {
self.st.squeeze(self.buf[0..]);
- mem.copy(u8, out[0..], self.buf[0..out.len]);
+ @memcpy(out[0..], self.buf[0..out.len]);
self.offset = out.len;
}
}
lib/std/crypto/siphash.zig
@@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
self.msg_len +%= @truncate(u8, b.len);
var buf = [_]u8{0} ** 8;
- mem.copy(u8, buf[0..], b[0..]);
+ @memcpy(buf[0..b.len], b);
buf[7] = self.msg_len;
self.round(buf);
@@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
if (self.buf_len != 0 and self.buf_len + b.len >= 8) {
off += 8 - self.buf_len;
- mem.copy(u8, self.buf[self.buf_len..], b[0..off]);
+ @memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
self.state.update(self.buf[0..]);
self.buf_len = 0;
}
@@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
const aligned_len = remain_len - (remain_len % 8);
self.state.update(b[off .. off + aligned_len]);
- mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);
- self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
+ const b_slice = b[off + aligned_len ..];
+ @memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);
+ self.buf_len += @intCast(u8, b_slice.len);
}
pub fn peek(self: Self) [mac_length]u8 {
lib/std/crypto/utils.zig
@@ -134,12 +134,8 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
/// Sets a slice to zeroes.
/// Prevents the store from being optimized out.
-pub fn secureZero(comptime T: type, s: []T) void {
- // TODO: implement `@memset` for non-byte-sized element type in the llvm backend
- //@memset(@as([]volatile T, s), 0);
- const ptr = @ptrCast([*]volatile u8, s.ptr);
- const length = s.len * @sizeOf(T);
- @memset(ptr[0..length], 0);
+pub inline fn secureZero(comptime T: type, s: []T) void {
+ @memset(@as([]volatile T, s), 0);
}
test "crypto.utils.timingSafeEql" {
@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {
random.bytes(a[0..]);
random.bytes(b[0..]);
try testing.expect(!timingSafeEql([100]u8, a, b));
- mem.copy(u8, a[0..], b[0..]);
+ a = b;
try testing.expect(timingSafeEql([100]u8, a, b));
}
@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {
var a = [_]u8{0xfe} ** 8;
var b = [_]u8{0xfe} ** 8;
- mem.set(u8, a[0..], 0);
+ @memset(a[0..], 0);
secureZero(u8, b[0..]);
try testing.expectEqualSlices(u8, a[0..], b[0..]);
lib/std/fmt/errol.zig
@@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
const i = tableLowerBound(bits);
if (i < enum3.len and enum3[i] == bits) {
const data = enum3_data[i];
- const digits = buffer[1 .. data.str.len + 1];
- mem.copy(u8, digits, data.str);
+ const digits = buffer[1..][0..data.str.len];
+ @memcpy(digits, data.str);
return FloatDecimal{
.digits = digits,
.exp = data.exp,
lib/std/fs/path.zig
@@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
const buf = try allocator.alloc(u8, total_len);
errdefer allocator.free(buf);
- mem.copy(u8, buf, paths[first_path_index]);
+ @memcpy(buf[0..paths[first_path_index].len], paths[first_path_index]);
var buf_index: usize = paths[first_path_index].len;
var prev_path = paths[first_path_index];
assert(prev_path.len > 0);
@@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
buf_index += 1;
}
const adjusted_path = if (prev_sep and this_sep) this_path[1..] else this_path;
- mem.copy(u8, buf[buf_index..], adjusted_path);
+ @memcpy(buf[buf_index..][0..adjusted_path.len], adjusted_path);
buf_index += adjusted_path.len;
prev_path = this_path;
}
@@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
real_result[i..][0..3].* = "..\\".*;
i += 3;
}
- mem.copy(u8, real_result[i..], result.items);
+ @memcpy(real_result[i..][0..result.items.len], result.items);
return real_result;
}
}
@@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
real_result[i..][0..3].* = "../".*;
i += 3;
}
- mem.copy(u8, real_result[i..], result.items);
+ @memcpy(real_result[i..][0..result.items.len], result.items);
return real_result;
}
}
@@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
while (rest_it.next()) |to_component| {
result[result_index] = '\\';
result_index += 1;
- mem.copy(u8, result[result_index..], to_component);
+ @memcpy(result[result_index..][0..to_component.len], to_component);
result_index += to_component.len;
}
@@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
return allocator.realloc(result, result_index - 1);
}
- mem.copy(u8, result[result_index..], to_rest);
+ @memcpy(result[result_index..][0..to_rest.len], to_rest);
return result;
}
lib/std/hash/cityhash.zig
@@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
var key: [256]u8 = undefined;
var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
- std.mem.set(u8, &key, 0);
- std.mem.set(u8, &hashes_bytes, 0);
+ @memset(&key, 0);
+ @memset(&hashes_bytes, 0);
var i: u32 = 0;
while (i < 256) : (i += 1) {
lib/std/hash/wyhash.zig
@@ -147,7 +147,7 @@ pub const Wyhash = struct {
if (self.buf_len != 0 and self.buf_len + b.len >= 32) {
off += 32 - self.buf_len;
- mem.copy(u8, self.buf[self.buf_len..], b[0..off]);
+ @memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
self.state.update(self.buf[0..]);
self.buf_len = 0;
}
@@ -156,7 +156,8 @@ pub const Wyhash = struct {
const aligned_len = remain_len - (remain_len % 32);
self.state.update(b[off .. off + aligned_len]);
- mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);
+ const src = b[off + aligned_len ..];
+ @memcpy(self.buf[self.buf_len..][0..src.len], src);
self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
}
lib/std/hash/xxhash.zig
@@ -36,7 +36,7 @@ pub const XxHash64 = struct {
pub fn update(self: *XxHash64, input: []const u8) void {
if (input.len < 32 - self.buf_len) {
- mem.copy(u8, self.buf[self.buf_len..], input);
+ @memcpy(self.buf[self.buf_len..][0..input.len], input);
self.buf_len += input.len;
return;
}
@@ -45,7 +45,7 @@ pub const XxHash64 = struct {
if (self.buf_len > 0) {
i = 32 - self.buf_len;
- mem.copy(u8, self.buf[self.buf_len..], input[0..i]);
+ @memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
self.processStripe(&self.buf);
self.buf_len = 0;
}
@@ -55,7 +55,7 @@ pub const XxHash64 = struct {
}
const remaining_bytes = input[i..];
- mem.copy(u8, &self.buf, remaining_bytes);
+ @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
self.buf_len = remaining_bytes.len;
}
@@ -165,7 +165,7 @@ pub const XxHash32 = struct {
pub fn update(self: *XxHash32, input: []const u8) void {
if (input.len < 16 - self.buf_len) {
- mem.copy(u8, self.buf[self.buf_len..], input);
+ @memcpy(self.buf[self.buf_len..][0..input.len], input);
self.buf_len += input.len;
return;
}
@@ -174,7 +174,7 @@ pub const XxHash32 = struct {
if (self.buf_len > 0) {
i = 16 - self.buf_len;
- mem.copy(u8, self.buf[self.buf_len..], input[0..i]);
+ @memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
self.processStripe(&self.buf);
self.buf_len = 0;
}
@@ -184,7 +184,7 @@ pub const XxHash32 = struct {
}
const remaining_bytes = input[i..];
- mem.copy(u8, &self.buf, remaining_bytes);
+ @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
self.buf_len = remaining_bytes.len;
}
lib/std/heap/general_purpose_allocator.zig
@@ -448,7 +448,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
if (stack_n == 0) return;
- mem.set(usize, addresses, 0);
+ @memset(addresses, 0);
var stack_trace = StackTrace{
.instruction_addresses = addresses,
.index = 0,
@@ -1113,7 +1113,7 @@ test "shrink" {
var slice = try allocator.alloc(u8, 20);
defer allocator.free(slice);
- mem.set(u8, slice, 0x11);
+ @memset(slice, 0x11);
try std.testing.expect(allocator.resize(slice, 17));
slice = slice[0..17];
lib/std/heap/WasmAllocator.zig
@@ -230,7 +230,7 @@ test "shrink" {
var slice = try test_ally.alloc(u8, 20);
defer test_ally.free(slice);
- mem.set(u8, slice, 0x11);
+ @memset(slice, 0x11);
try std.testing.expect(test_ally.resize(slice, 17));
slice = slice[0..17];
lib/std/heap/WasmPageAllocator.zig
@@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {
extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];
// Since this is the first page being freed and we consume it, assume *nothing* is free.
- mem.set(u128, extended.data, PageStatus.none_free);
+ @memset(extended.data, PageStatus.none_free);
}
const clamped_start = @max(extendedOffset(), start);
extended.recycle(clamped_start - extendedOffset(), new_end - clamped_start);
lib/std/io/buffered_reader.zig
@@ -20,8 +20,8 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
var dest_index: usize = 0;
while (dest_index < dest.len) {
- const written = std.math.min(dest.len - dest_index, self.end - self.start);
- std.mem.copy(u8, dest[dest_index..], self.buf[self.start .. self.start + written]);
+ const written = @min(dest.len - dest_index, self.end - self.start);
+ @memcpy(dest[dest_index..][0..written], self.buf[self.start..][0..written]);
if (written == 0) {
// buf empty, fill it
const n = try self.unbuffered_reader.read(self.buf[0..]);
@@ -115,11 +115,8 @@ test "io.BufferedReader Block" {
}
fn read(self: *Self, dest: []u8) Error!usize {
- if (self.curr_read >= self.reads_allowed) {
- return 0;
- }
- std.debug.assert(dest.len >= self.block.len);
- std.mem.copy(u8, dest, self.block);
+ if (self.curr_read >= self.reads_allowed) return 0;
+ @memcpy(dest[0..self.block.len], self.block);
self.curr_read += 1;
return self.block.len;
lib/std/io/buffered_writer.zig
@@ -30,8 +30,9 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty
return self.unbuffered_writer.write(bytes);
}
- mem.copy(u8, self.buf[self.end..], bytes);
- self.end += bytes.len;
+ const new_end = self.end + bytes.len;
+ @memcpy(self.buf[self.end..new_end], bytes);
+ self.end = new_end;
return bytes.len;
}
};
lib/std/io/fixed_buffer_stream.zig
@@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
}
pub fn read(self: *Self, dest: []u8) ReadError!usize {
- const size = std.math.min(dest.len, self.buffer.len - self.pos);
+ const size = @min(dest.len, self.buffer.len - self.pos);
const end = self.pos + size;
- mem.copy(u8, dest[0..size], self.buffer[self.pos..end]);
+ @memcpy(dest[0..size], self.buffer[self.pos..end]);
self.pos = end;
return size;
@@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
else
self.buffer.len - self.pos;
- mem.copy(u8, self.buffer[self.pos .. self.pos + n], bytes[0..n]);
+ @memcpy(self.buffer[self.pos..][0..n], bytes[0..n]);
self.pos += n;
if (n == 0) return error.NoSpaceLeft;
lib/std/io/writer.zig
@@ -35,7 +35,7 @@ pub fn Writer(
pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {
var bytes: [256]u8 = undefined;
- mem.set(u8, bytes[0..], byte);
+ @memset(bytes[0..], byte);
var remaining: usize = n;
while (remaining > 0) {
lib/std/json/test.zig
@@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {
// StreamingParser has multiple internal fields set to undefined. This causes issues when using
// expectEqual so these are zeroed. We are testing for equality here only because this is a
// known small test reproduction which hits the relevant LLVM issue.
- std.mem.set(u8, @ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);
+ @memset(@ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);
try std.testing.expectEqual(parser, parser);
}
lib/std/math/big/int.zig
@@ -176,7 +176,7 @@ pub const Mutable = struct {
/// Asserts the value fits in the limbs buffer.
pub fn copy(self: *Mutable, other: Const) void {
if (self.limbs.ptr != other.limbs.ptr) {
- mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);
+ @memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
}
self.positive = other.positive;
self.len = other.limbs.len;
@@ -199,7 +199,7 @@ pub const Mutable = struct {
/// can be modified separately from the original.
/// Asserts that limbs is big enough to store the value.
pub fn clone(other: Mutable, limbs: []Limb) Mutable {
- mem.copy(Limb, limbs, other.limbs[0..other.len]);
+ @memcpy(limbs[0..other.len], other.limbs[0..other.len]);
return .{
.limbs = limbs,
.len = other.len,
@@ -344,7 +344,7 @@ pub const Mutable = struct {
.min => {
// Negative bound, signed = -0x80.
r.len = req_limbs;
- mem.set(Limb, r.limbs[0 .. r.len - 1], 0);
+ @memset(r.limbs[0 .. r.len - 1], 0);
r.limbs[r.len - 1] = signmask;
r.positive = false;
},
@@ -363,7 +363,7 @@ pub const Mutable = struct {
const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
r.len = new_req_limbs;
- std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
+ @memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
r.limbs[r.len - 1] = new_mask;
}
},
@@ -376,7 +376,7 @@ pub const Mutable = struct {
.max => {
// Max bound, unsigned = 0xFF
r.len = req_limbs;
- std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
+ @memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
r.limbs[r.len - 1] = mask;
},
},
@@ -489,7 +489,7 @@ pub const Mutable = struct {
if (msl < req_limbs) {
r.limbs[msl] = 1;
r.len = req_limbs;
- mem.set(Limb, r.limbs[msl + 1 .. req_limbs], 0);
+ @memset(r.limbs[msl + 1 .. req_limbs], 0);
} else {
carry_truncated = true;
}
@@ -637,14 +637,14 @@ pub const Mutable = struct {
const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
const start = buf_index;
- mem.copy(Limb, limbs_buffer[buf_index..], a.limbs);
+ @memcpy(limbs_buffer[buf_index..][0..a.limbs.len], a.limbs);
buf_index += a.limbs.len;
break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
} else a;
const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
const start = buf_index;
- mem.copy(Limb, limbs_buffer[buf_index..], b.limbs);
+ @memcpy(limbs_buffer[buf_index..][0..b.limbs.len], b.limbs);
buf_index += b.limbs.len;
break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();
} else b;
@@ -676,7 +676,7 @@ pub const Mutable = struct {
}
}
- mem.set(Limb, rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);
+ @memset(rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);
llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);
@@ -708,7 +708,7 @@ pub const Mutable = struct {
const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
const start = buf_index;
const a_len = math.min(req_limbs, a.limbs.len);
- mem.copy(Limb, limbs_buffer[buf_index..], a.limbs[0..a_len]);
+ @memcpy(limbs_buffer[buf_index..][0..a_len], a.limbs[0..a_len]);
buf_index += a_len;
break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
} else a;
@@ -716,7 +716,7 @@ pub const Mutable = struct {
const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
const start = buf_index;
const b_len = math.min(req_limbs, b.limbs.len);
- mem.copy(Limb, limbs_buffer[buf_index..], b.limbs[0..b_len]);
+ @memcpy(limbs_buffer[buf_index..][0..b_len], b.limbs[0..b_len]);
buf_index += b_len;
break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
} else b;
@@ -751,7 +751,7 @@ pub const Mutable = struct {
const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];
const b_limbs = b.limbs[0..math.min(req_limbs, b.limbs.len)];
- mem.set(Limb, rma.limbs[0..req_limbs], 0);
+ @memset(rma.limbs[0..req_limbs], 0);
llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);
rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));
@@ -919,7 +919,7 @@ pub const Mutable = struct {
_ = opt_allocator;
assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
- mem.set(Limb, rma.limbs, 0);
+ @memset(rma.limbs, 0);
llsquareBasecase(rma.limbs, a.limbs);
@@ -1522,7 +1522,7 @@ pub const Mutable = struct {
if (xy_trailing != 0) {
// Manually shift here since we know its limb aligned.
mem.copyBackwards(Limb, r.limbs[xy_trailing..], r.limbs[0..r.len]);
- mem.set(Limb, r.limbs[0..xy_trailing], 0);
+ @memset(r.limbs[0..xy_trailing], 0);
r.len += xy_trailing;
}
}
@@ -1556,7 +1556,7 @@ pub const Mutable = struct {
// for 0 <= j <= n - t, set q[j] to 0
q.len = shift + 1;
q.positive = true;
- mem.set(Limb, q.limbs[0..q.len], 0);
+ @memset(q.limbs[0..q.len], 0);
// 2.
// while x >= y * b^(n - t):
@@ -1691,7 +1691,7 @@ pub const Mutable = struct {
r.addScalar(a.abs(), -1);
if (req_limbs > r.len) {
- mem.set(Limb, r.limbs[r.len..req_limbs], 0);
+ @memset(r.limbs[r.len..req_limbs], 0);
}
assert(r.limbs.len >= req_limbs);
@@ -1730,7 +1730,7 @@ pub const Mutable = struct {
// Zero-extend the result
if (req_limbs > r.len) {
- mem.set(Limb, r.limbs[r.len..req_limbs], 0);
+ @memset(r.limbs[r.len..req_limbs], 0);
}
// Truncate to required number of limbs.
@@ -1921,8 +1921,8 @@ pub const Const = struct {
/// The result is an independent resource which is managed by the caller.
pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {
- const limbs = try allocator.alloc(Limb, math.max(Managed.default_capacity, self.limbs.len));
- mem.copy(Limb, limbs, self.limbs);
+ const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
+ @memcpy(limbs[0..self.limbs.len], self.limbs);
return Managed{
.allocator = allocator,
.limbs = limbs,
@@ -1935,7 +1935,7 @@ pub const Const = struct {
/// Asserts `limbs` is big enough to store the value.
pub fn toMutable(self: Const, limbs: []Limb) Mutable {
- mem.copy(Limb, limbs, self.limbs[0..self.limbs.len]);
+ @memcpy(limbs[0..self.limbs.len], self.limbs[0..self.limbs.len]);
return .{
.limbs = limbs,
.positive = self.positive,
@@ -2253,7 +2253,7 @@ pub const Const = struct {
.positive = true, // Make absolute by ignoring self.positive.
.len = self.limbs.len,
};
- mem.copy(Limb, q.limbs, self.limbs);
+ @memcpy(q.limbs[0..self.limbs.len], self.limbs);
var r: Mutable = .{
.limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],
@@ -2587,8 +2587,8 @@ pub const Managed = struct {
.allocator = allocator,
.metadata = other.metadata,
.limbs = block: {
- var limbs = try allocator.alloc(Limb, other.len());
- mem.copy(Limb, limbs[0..], other.limbs[0..other.len()]);
+ const limbs = try allocator.alloc(Limb, other.len());
+ @memcpy(limbs, other.limbs[0..other.len()]);
break :block limbs;
},
};
@@ -2600,7 +2600,7 @@ pub const Managed = struct {
if (self.limbs.ptr == other.limbs.ptr) return;
try self.ensureCapacity(other.limbs.len);
- mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);
+ @memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
self.setMetadata(other.positive, other.limbs.len);
}
@@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(
// Note, we don't need to compute all of p2, just enough limbs to satisfy r.
const p2_limbs = math.min(limbs_after_split, a1.len + b1.len);
- mem.set(Limb, tmp[0..p2_limbs], 0);
+ @memset(tmp[0..p2_limbs], 0);
llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);
const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];
@@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(
// Compute p0.
// Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.
const p0_limbs = a0.len + b0.len;
- mem.set(Limb, tmp[0..p0_limbs], 0);
+ @memset(tmp[0..p0_limbs], 0);
llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);
const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];
@@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(
return;
}
- mem.set(Limb, tmp, 0);
+ @memset(tmp, 0);
// p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.
// Note that in this case, we again need some storage for intermediary results
@@ -3666,7 +3666,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
}
r[limb_shift - 1] = carry;
- mem.set(Limb, r[0 .. limb_shift - 1], 0);
+ @memset(r[0 .. limb_shift - 1], 0);
}
fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
@@ -4061,8 +4061,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
tmp2 = tmp_limbs;
}
- mem.copy(Limb, tmp1, a);
- mem.set(Limb, tmp1[a.len..], 0);
+ @memcpy(tmp1[0..a.len], a);
+ @memset(tmp1[a.len..], 0);
// Scan the exponent as a binary number, from left to right, dropping the
// most significant bit set.
@@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
var i: usize = 0;
while (i < exp_bits) : (i += 1) {
// Square
- mem.set(Limb, tmp2, 0);
+ @memset(tmp2, 0);
llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);
mem.swap([]Limb, &tmp1, &tmp2);
// Multiply by a
const ov = @shlWithOverflow(exp, 1);
exp = ov[0];
if (ov[1] != 0) {
- mem.set(Limb, tmp2, 0);
+ @memset(tmp2, 0);
llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);
mem.swap([]Limb, &tmp1, &tmp2);
}
lib/std/mem/Allocator.zig
@@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {
/// Copies `m` to newly allocated memory. Caller owns the memory.
pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {
const new_buf = try allocator.alloc(T, m.len);
- mem.copy(T, new_buf, m);
+ @memcpy(new_buf, m);
return new_buf;
}
/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.
pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {
const new_buf = try allocator.alloc(T, m.len + 1);
- mem.copy(T, new_buf, m);
+ @memcpy(new_buf[0..m.len], m);
new_buf[m.len] = 0;
return new_buf[0..m.len :0];
}
lib/std/os/linux/io_uring.zig
@@ -1855,7 +1855,7 @@ test "write_fixed/read_fixed" {
var raw_buffers: [2][11]u8 = undefined;
// First buffer will be written to the file.
- std.mem.set(u8, &raw_buffers[0], 'z');
+ @memset(&raw_buffers[0], 'z');
std.mem.copy(u8, &raw_buffers[0], "foobar");
var buffers = [2]os.iovec{
@@ -2966,7 +2966,7 @@ test "provide_buffers: read" {
// Provide 1 buffer again
// Deliberately put something we don't expect in the buffers
- mem.set(u8, mem.sliceAsBytes(&buffers), 42);
+ @memset(mem.sliceAsBytes(&buffers), 42);
const reprovided_buffer_id = 2;
@@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {
// Do 4 recv which should consume all buffers
// Deliberately put something we don't expect in the buffers
- mem.set(u8, mem.sliceAsBytes(&buffers), 1);
+ @memset(mem.sliceAsBytes(&buffers), 1);
var i: usize = 0;
while (i < buffers.len) : (i += 1) {
@@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {
// Final recv which should work
// Deliberately put something we don't expect in the buffers
- mem.set(u8, mem.sliceAsBytes(&buffers), 1);
+ @memset(mem.sliceAsBytes(&buffers), 1);
{
var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
lib/std/os/linux/tls.zig
@@ -275,7 +275,7 @@ inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {
/// architecture-specific value of the thread-pointer register
pub fn prepareTLS(area: []u8) usize {
// Clear the area we're going to use, just to be safe
- mem.set(u8, area, 0);
+ @memset(area, 0);
// Prepare the DTV
const dtv = alignPtrCast(DTV, area.ptr + tls_image.dtv_offset);
dtv.entries = 1;
lib/std/os/test.zig
@@ -587,7 +587,7 @@ test "mmap" {
try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
// Make sure the memory is writeable as requested
- std.mem.set(u8, data, 0x55);
+ @memset(data, 0x55);
try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
}
lib/std/rand/ChaCha.zig
@@ -40,7 +40,8 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {
}
if (i < bytes.len) {
var k = [_]u8{0} ** Cipher.key_length;
- mem.copy(u8, k[0..], bytes[i..]);
+ const src = bytes[i..];
+ @memcpy(k[0..src.len], src);
Cipher.xor(
self.state[0..Cipher.key_length],
self.state[0..Cipher.key_length],
@@ -72,8 +73,8 @@ pub fn fill(self: *Self, buf_: []u8) void {
if (avail > 0) {
// Bytes from the current block
const n = @min(avail, buf.len);
- mem.copy(u8, buf[0..n], bytes[self.offset..][0..n]);
- mem.set(u8, bytes[self.offset..][0..n], 0);
+ @memcpy(buf[0..n], bytes[self.offset..][0..n]);
+ @memset(bytes[self.offset..][0..n], 0);
buf = buf[n..];
self.offset += n;
}
@@ -83,15 +84,15 @@ pub fn fill(self: *Self, buf_: []u8) void {
// Full blocks
while (buf.len >= bytes.len) {
- mem.copy(u8, buf[0..bytes.len], bytes);
+ @memcpy(buf[0..bytes.len], bytes);
buf = buf[bytes.len..];
self.refill();
}
// Remaining bytes
if (buf.len > 0) {
- mem.copy(u8, buf, bytes[0..buf.len]);
- mem.set(u8, bytes[0..buf.len], 0);
+ @memcpy(buf, bytes[0..buf.len]);
+ @memset(bytes[0..buf.len], 0);
self.offset = buf.len;
}
}
lib/std/rand/Isaac64.zig
@@ -87,7 +87,7 @@ fn next(self: *Isaac64) u64 {
fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
// We ignore the multi-pass requirement since we don't currently expose full access to
// seeding the self.m array completely.
- mem.set(u64, self.m[0..], 0);
+ @memset(self.m[0..], 0);
self.m[0] = init_s;
// prescrambled golden ratio constants
@@ -143,7 +143,7 @@ fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
}
}
- mem.set(u64, self.r[0..], 0);
+ @memset(self.r[0..], 0);
self.a = 0;
self.b = 0;
self.c = 0;
lib/std/testing/failing_allocator.zig
@@ -66,7 +66,7 @@ pub const FailingAllocator = struct {
const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
if (self.index == self.fail_index) {
if (!self.has_induced_failure) {
- mem.set(usize, &self.stack_addresses, 0);
+ @memset(&self.stack_addresses, 0);
var stack_trace = std.builtin.StackTrace{
.instruction_addresses = &self.stack_addresses,
.index = 0,
lib/std/zig/system/NativeTargetInfo.zig
@@ -877,17 +877,17 @@ pub fn abiAndDynamicLinkerFromFile(
const cpu_arch = @tagName(result.target.cpu.arch);
const os_tag = @tagName(result.target.os.tag);
const abi = @tagName(result.target.abi);
- mem.copy(u8, path_buf[index..], prefix);
+ @memcpy(path_buf[index..][0..prefix.len], prefix);
index += prefix.len;
- mem.copy(u8, path_buf[index..], cpu_arch);
+ @memcpy(path_buf[index..][0..cpu_arch.len], cpu_arch);
index += cpu_arch.len;
path_buf[index] = '-';
index += 1;
- mem.copy(u8, path_buf[index..], os_tag);
+ @memcpy(path_buf[index..][0..os_tag.len], os_tag);
index += os_tag.len;
path_buf[index] = '-';
index += 1;
- mem.copy(u8, path_buf[index..], abi);
+ @memcpy(path_buf[index..][0..abi.len], abi);
index += abi.len;
const rpath = path_buf[0..index];
if (glibcVerFromRPath(rpath)) |ver| {
lib/std/zig/system/windows.zig
@@ -171,10 +171,10 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);
switch (@field(args, field.name).value_type) {
REG.DWORD, REG.DWORD_BIG_ENDIAN => {
- mem.copy(u8, @field(args, field.name).value_buf[0..4], entry[0..4]);
+ @memcpy(@field(args, field.name).value_buf[0..4], entry[0..4]);
},
REG.QWORD => {
- mem.copy(u8, @field(args, field.name).value_buf[0..8], entry[0..8]);
+ @memcpy(@field(args, field.name).value_buf[0..8], entry[0..8]);
},
else => unreachable,
}
lib/std/zig/render.zig
@@ -1889,11 +1889,11 @@ fn renderArrayInit(
// A place to store the width of each expression and its column's maximum
const widths = try gpa.alloc(usize, row_exprs.len + row_size);
defer gpa.free(widths);
- mem.set(usize, widths, 0);
+ @memset(widths, 0);
const expr_newlines = try gpa.alloc(bool, row_exprs.len);
defer gpa.free(expr_newlines);
- mem.set(bool, expr_newlines, false);
+ @memset(expr_newlines, false);
const expr_widths = widths[0..row_exprs.len];
const column_widths = widths[row_exprs.len..];
lib/std/array_hash_map.zig
@@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(
self.entries.len = 0;
if (self.index_header) |header| {
switch (header.capacityIndexType()) {
- .u8 => mem.set(Index(u8), header.indexes(u8), Index(u8).empty),
- .u16 => mem.set(Index(u16), header.indexes(u16), Index(u16).empty),
- .u32 => mem.set(Index(u32), header.indexes(u32), Index(u32).empty),
+ .u8 => @memset(header.indexes(u8), Index(u8).empty),
+ .u16 => @memset(header.indexes(u16), Index(u16).empty),
+ .u32 => @memset(header.indexes(u32), Index(u32).empty),
}
}
}
lib/std/array_list.zig
@@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
}
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
- mem.copy(T, new_memory, self.items);
+ @memcpy(new_memory, self.items);
@memset(self.items, undefined);
self.clearAndFree();
return new_memory;
@@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
self.items.len += items.len;
mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
- mem.copy(T, self.items[i .. i + items.len], items);
+ @memcpy(self.items[i..][0..items.len], items);
}
/// Replace range of elements `list[start..start+len]` with `new_items`.
@@ -182,15 +182,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
const range = self.items[start..after_range];
if (range.len == new_items.len)
- mem.copy(T, range, new_items)
+ @memcpy(range[0..new_items.len], new_items)
else if (range.len < new_items.len) {
const first = new_items[0..range.len];
const rest = new_items[range.len..];
- mem.copy(T, range, first);
+ @memcpy(range[0..first.len], first);
try self.insertSlice(after_range, rest);
} else {
- mem.copy(T, range, new_items);
+ @memcpy(range[0..new_items.len], new_items);
const after_subrange = start + new_items.len;
for (self.items[after_range..], 0..) |item, i| {
@@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
const new_len = old_len + items.len;
assert(new_len <= self.capacity);
self.items.len = new_len;
- mem.copy(T, self.items[old_len..], items);
+ @memcpy(self.items[old_len..][0..items.len], items);
}
/// Append an unaligned slice of items to the list. Allocates more
@@ -401,7 +401,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
self.capacity = new_capacity;
} else {
const new_memory = try self.allocator.alignedAlloc(T, alignment, new_capacity);
- mem.copy(T, new_memory, self.items);
+ @memcpy(new_memory[0..self.items.len], self.items);
self.allocator.free(old_memory);
self.items.ptr = new_memory.ptr;
self.capacity = new_memory.len;
@@ -600,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
}
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
- mem.copy(T, new_memory, self.items);
+ @memcpy(new_memory, self.items);
@memset(self.items, undefined);
self.clearAndFree(allocator);
return new_memory;
@@ -651,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
self.items.len += items.len;
mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
- mem.copy(T, self.items[i .. i + items.len], items);
+ @memcpy(self.items[i..][0..items.len], items);
}
/// Replace range of elements `list[start..start+len]` with `new_items`
@@ -720,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
const new_len = old_len + items.len;
assert(new_len <= self.capacity);
self.items.len = new_len;
- mem.copy(T, self.items[old_len..], items);
+ @memcpy(self.items[old_len..][0..items.len], items);
}
/// Append the slice of items to the list. Allocates more
@@ -823,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
},
};
- mem.copy(T, new_memory, self.items[0..new_len]);
+ @memcpy(new_memory, self.items[0..new_len]);
allocator.free(old_memory);
self.items = new_memory;
self.capacity = new_memory.len;
@@ -885,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
self.capacity = new_capacity;
} else {
const new_memory = try allocator.alignedAlloc(T, alignment, new_capacity);
- mem.copy(T, new_memory, self.items);
+ @memcpy(new_memory[0..self.items.len], self.items);
allocator.free(old_memory);
self.items.ptr = new_memory.ptr;
self.capacity = new_memory.len;
lib/std/base64.zig
@@ -309,11 +309,11 @@ test "base64 padding dest overflow" {
const input = "foo";
var expect: [128]u8 = undefined;
- std.mem.set(u8, &expect, 0);
+ @memset(&expect, 0);
_ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);
var got: [128]u8 = undefined;
- std.mem.set(u8, &got, 0);
+ @memset(&got, 0);
_ = url_safe.Encoder.encode(&got, input);
try std.testing.expectEqualSlices(u8, &expect, &got);
lib/std/bit_set.zig
@@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {
// fill in any new masks
if (new_masks > old_masks) {
const fill_value = std.math.boolMask(MaskInt, fill);
- std.mem.set(MaskInt, self.masks[old_masks..new_masks], fill_value);
+ @memset(self.masks[old_masks..new_masks], fill_value);
}
}
lib/std/bounded_array.zig
@@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(
/// Copy the content of an existing slice.
pub fn fromSlice(m: []const T) error{Overflow}!Self {
var list = try init(m.len);
- std.mem.copy(T, list.slice(), m);
+ @memcpy(list.slice(), m);
return list;
}
@@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(
try self.ensureUnusedCapacity(items.len);
self.len += items.len;
mem.copyBackwards(T, self.slice()[i + items.len .. self.len], self.constSlice()[i .. self.len - items.len]);
- mem.copy(T, self.slice()[i .. i + items.len], items);
+ @memcpy(self.slice()[i..][0..items.len], items);
}
/// Replace range of elements `slice[start..start+len]` with `new_items`.
@@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(
var range = self.slice()[start..after_range];
if (range.len == new_items.len) {
- mem.copy(T, range, new_items);
+ @memcpy(range[0..new_items.len], new_items);
} else if (range.len < new_items.len) {
const first = new_items[0..range.len];
const rest = new_items[range.len..];
- mem.copy(T, range, first);
+ @memcpy(range[0..first.len], first);
try self.insertSlice(after_range, rest);
} else {
- mem.copy(T, range, new_items);
+ @memcpy(range[0..new_items.len], new_items);
const after_subrange = start + new_items.len;
for (self.constSlice()[after_range..], 0..) |item, i| {
self.slice()[after_subrange..][i] = item;
@@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(
/// Append the slice of items to the slice, asserting the capacity is already
/// enough to store the new items.
pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
- const oldlen = self.len;
+ const old_len = self.len;
self.len += items.len;
- mem.copy(T, self.slice()[oldlen..], items);
+ @memcpy(self.slice()[old_len..][0..items.len], items);
}
/// Append a value to the slice `n` times.
@@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(
pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {
const old_len = self.len;
try self.resize(old_len + n);
- mem.set(T, self.slice()[old_len..self.len], value);
+ @memset(self.slice()[old_len..self.len], value);
}
/// Append a value to the slice `n` times.
@@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(
const old_len = self.len;
self.len += n;
assert(self.len <= buffer_capacity);
- mem.set(T, self.slice()[old_len..self.len], value);
+ @memset(self.slice()[old_len..self.len], value);
}
pub const Writer = if (T != u8)
@@ -329,7 +329,7 @@ test "BoundedArray" {
try testing.expectEqual(a.popOrNull(), 0);
try testing.expectEqual(a.popOrNull(), null);
var unused = a.unusedCapacitySlice();
- mem.set(u8, unused[0..8], 2);
+ @memset(unused[0..8], 2);
unused[8] = 3;
unused[9] = 4;
try testing.expectEqual(unused.len, a.capacity());
lib/std/buf_set.zig
@@ -97,7 +97,7 @@ pub const BufSet = struct {
fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
const result = try self.hash_map.allocator.alloc(u8, value.len);
- mem.copy(u8, result, value);
+ @memcpy(result, value);
return result;
}
};
lib/std/Build.zig
@@ -1693,10 +1693,10 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u
u8,
name.len + if (value) |value_slice| value_slice.len + 1 else 0,
) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable;
- mem.copy(u8, macro, name);
+ @memcpy(macro[0..name.len], name);
if (value) |value_slice| {
macro[name.len] = '=';
- mem.copy(u8, macro[name.len + 1 ..], value_slice);
+ @memcpy(macro[name.len + 1 ..][0..value_slice.len], value_slice);
}
return macro;
}
lib/std/child_process.zig
@@ -259,7 +259,7 @@ pub const ChildProcess = struct {
fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {
if (fifo.head > 0) {
- std.mem.copy(u8, fifo.buf[0..fifo.count], fifo.buf[fifo.head .. fifo.head + fifo.count]);
+ @memcpy(fifo.buf[0..fifo.count], fifo.buf[fifo.head..][0..fifo.count]);
}
const result = std.ArrayList(u8){
.items = fifo.buf[0..fifo.count],
@@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !
var i: usize = 0;
while (it.next()) |pair| : (i += 1) {
const env_buf = try arena.allocSentinel(u8, pair.key_ptr.len + pair.value_ptr.len + 1, 0);
- mem.copy(u8, env_buf, pair.key_ptr.*);
+ @memcpy(env_buf[0..pair.key_ptr.len], pair.key_ptr.*);
env_buf[pair.key_ptr.len] = '=';
- mem.copy(u8, env_buf[pair.key_ptr.len + 1 ..], pair.value_ptr.*);
+ @memcpy(env_buf[pair.key_ptr.len + 1 ..][0..pair.value_ptr.len], pair.value_ptr.*);
envp_buf[i] = env_buf.ptr;
}
assert(i == envp_count);
lib/std/cstr.zig
@@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {
/// Caller owns the returned memory.
pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {
const result = try allocator.alloc(u8, slice.len + 1);
- mem.copy(u8, result, slice);
+ @memcpy(result[0..slice.len], slice);
result[slice.len] = 0;
return result[0..slice.len :0];
}
@@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {
for (slice) |inner| {
index_buf[i] = buf.ptr + write_index;
i += 1;
- mem.copy(u8, buf[write_index..], inner);
+ @memcpy(buf[write_index..][0..inner.len], inner);
write_index += inner.len;
buf[write_index] = 0;
write_index += 1;
lib/std/dynamic_library.zig
@@ -210,7 +210,7 @@ pub const ElfDynLib = struct {
-1,
0,
);
- mem.copy(u8, sect_mem, file_bytes[0..ph.p_filesz]);
+ @memcpy(sect_mem[0..ph.p_filesz], file_bytes[0..ph.p_filesz]);
}
},
else => {},
lib/std/enums.zig
@@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
.bits = Self.BitSet.initFull(),
.values = undefined,
};
- std.mem.set(V, &result.values, value);
+ @memset(&result.values, value);
return result;
}
/// Initializes a full mapping with supplied values.
@@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)
pub fn initFill(v: Value) Self {
var self: Self = undefined;
- std.mem.set(Value, &self.values, v);
+ @memset(&self.values, v);
return self;
}
lib/std/fifo.zig
@@ -86,19 +86,17 @@ pub fn LinearFifo(
pub fn realign(self: *Self) void {
if (self.buf.len - self.head >= self.count) {
- // this copy overlaps
- mem.copy(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
+ mem.copyForwards(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
self.head = 0;
} else {
var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;
while (self.head != 0) {
- const n = math.min(self.head, tmp.len);
+ const n = @min(self.head, tmp.len);
const m = self.buf.len - n;
- mem.copy(T, tmp[0..n], self.buf[0..n]);
- // this middle copy overlaps; the others here don't
- mem.copy(T, self.buf[0..m], self.buf[n..][0..m]);
- mem.copy(T, self.buf[m..], tmp[0..n]);
+ @memcpy(tmp[0..n], self.buf[0..n]);
+ mem.copyForwards(T, self.buf[0..m], self.buf[n..][0..m]);
+ @memcpy(self.buf[m..][0..n], tmp[0..n]);
self.head -= n;
}
}
@@ -223,8 +221,8 @@ pub fn LinearFifo(
while (dst_left.len > 0) {
const slice = self.readableSlice(0);
if (slice.len == 0) break;
- const n = math.min(slice.len, dst_left.len);
- mem.copy(T, dst_left, slice[0..n]);
+ const n = @min(slice.len, dst_left.len);
+ @memcpy(dst_left[0..n], slice[0..n]);
self.discard(n);
dst_left = dst_left[n..];
}
@@ -289,8 +287,8 @@ pub fn LinearFifo(
while (src_left.len > 0) {
const writable_slice = self.writableSlice(0);
assert(writable_slice.len != 0);
- const n = math.min(writable_slice.len, src_left.len);
- mem.copy(T, writable_slice, src_left[0..n]);
+ const n = @min(writable_slice.len, src_left.len);
+ @memcpy(writable_slice[0..n], src_left[0..n]);
self.update(n);
src_left = src_left[n..];
}
@@ -354,11 +352,11 @@ pub fn LinearFifo(
const slice = self.readableSliceMut(0);
if (src.len < slice.len) {
- mem.copy(T, slice, src);
+ @memcpy(slice[0..src.len], src);
} else {
- mem.copy(T, slice, src[0..slice.len]);
+ @memcpy(slice, src[0..slice.len]);
const slice2 = self.readableSliceMut(slice.len);
- mem.copy(T, slice2, src[slice.len..]);
+ @memcpy(slice2[0 .. src.len - slice.len], src[slice.len..]);
}
}
lib/std/json.zig
@@ -1667,7 +1667,7 @@ fn parseInternal(
const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
if (r.len != stringToken.decodedLength()) return error.LengthMismatch;
switch (stringToken.escapes) {
- .None => mem.copy(u8, &r, source_slice),
+ .None => @memcpy(r[0..source_slice.len], source_slice),
.Some => try unescapeValidString(&r, source_slice),
}
return r;
@@ -1733,7 +1733,7 @@ fn parseInternal(
try allocator.alloc(u8, len);
errdefer allocator.free(output);
switch (stringToken.escapes) {
- .None => mem.copy(u8, output, source_slice),
+ .None => @memcpy(output[0..source_slice.len], source_slice),
.Some => try unescapeValidString(output, source_slice),
}
lib/std/mem.zig
@@ -192,12 +192,14 @@ test "Allocator.resize" {
}
}
+/// Deprecated: use `copyForwards`
+pub const copy = copyForwards;
+
/// Copy all of source into dest at position 0.
/// dest.len must be >= source.len.
/// If the slices overlap, dest.ptr must be <= src.ptr.
-pub fn copy(comptime T: type, dest: []T, source: []const T) void {
- for (dest[0..source.len], source) |*d, s|
- d.* = s;
+pub fn copyForwards(comptime T: type, dest: []T, source: []const T) void {
+ for (dest[0..source.len], source) |*d, s| d.* = s;
}
/// Copy all of source into dest at position 0.
@@ -3124,7 +3126,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen
var replacements: usize = 0;
while (slide < input.len) {
if (mem.startsWith(T, input[slide..], needle)) {
- mem.copy(T, output[i .. i + replacement.len], replacement);
+ @memcpy(output[i..][0..replacement.len], replacement);
i += replacement.len;
slide += needle.len;
replacements += 1;
lib/std/multi_array_list.zig
@@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
- mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
+ @memcpy(other_slice.items(field), self_slice.items(field));
}
}
gpa.free(self.allocatedBytes());
@@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
- mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
+ @memcpy(other_slice.items(field), self_slice.items(field));
}
}
gpa.free(self.allocatedBytes());
@@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
- mem.copy(field_info.type, result_slice.items(field), self_slice.items(field));
+ @memcpy(result_slice.items(field), self_slice.items(field));
}
}
return result;
lib/std/net.zig
@@ -106,7 +106,7 @@ pub const Address = extern union {
// Add 1 to ensure a terminating 0 is present in the path array for maximum portability.
if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;
- mem.set(u8, &sock_addr.path, 0);
+ @memset(&sock_addr.path, 0);
mem.copy(u8, &sock_addr.path, path);
return Address{ .un = sock_addr };
@@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {
if (!saw_any_digits) {
if (abbrv) return error.InvalidCharacter; // ':::'
if (i != 0) abbrv = true;
- mem.set(u8, ip_slice[index..], 0);
+ @memset(ip_slice[index..], 0);
ip_slice = tail[0..];
index = 0;
continue;
@@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {
if (!saw_any_digits) {
if (abbrv) return error.InvalidCharacter; // ':::'
if (i != 0) abbrv = true;
- mem.set(u8, ip_slice[index..], 0);
+ @memset(ip_slice[index..], 0);
ip_slice = tail[0..];
index = 0;
continue;
lib/std/os.zig
@@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(
while (it.next()) |search_path| {
const path_len = search_path.len + file_slice.len + 1;
if (path_buf.len < path_len + 1) return error.NameTooLong;
- mem.copy(u8, &path_buf, search_path);
+ @memcpy(path_buf[0..search_path.len], search_path);
path_buf[search_path.len] = '/';
- mem.copy(u8, path_buf[search_path.len + 1 ..], file_slice);
+ @memcpy(path_buf[search_path.len + 1 ..][0..file_slice.len], file_slice);
path_buf[path_len] = 0;
const full_path = path_buf[0..path_len :0].ptr;
switch (arg0_expand) {
@@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
if (builtin.link_libc) {
var small_key_buf: [64]u8 = undefined;
if (key.len < small_key_buf.len) {
- mem.copy(u8, &small_key_buf, key);
+ @memcpy(small_key_buf[0..key.len], key);
small_key_buf[key.len] = 0;
const key0 = small_key_buf[0..key.len :0];
return getenvZ(key0);
@@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
const path = ".";
if (out_buffer.len < path.len) return error.NameTooLong;
- std.mem.copy(u8, out_buffer, path);
- return out_buffer[0..path.len];
+ const result = out_buffer[0..path.len];
+ @memcpy(result, path);
+ return result;
}
const err = if (builtin.link_libc) blk: {
@@ -2673,7 +2674,7 @@ pub fn renameatW(
.FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong
.FileName = undefined,
};
- std.mem.copy(u16, @as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
+ @memcpy(@as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
var io_status_block: windows.IO_STATUS_BLOCK = undefined;
@@ -5264,8 +5265,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
}
const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;
if (len == 0) return error.NameTooLong;
- mem.copy(u8, out_buffer, kfile.path[0..len]);
- return out_buffer[0..len];
+ const result = out_buffer[0..len];
+ @memcpy(result, kfile.path[0..len]);
+ return result;
} else {
// This fallback implementation reimplements libutil's `kinfo_getfile()`.
// The motivation is to avoid linking -lutil when building zig or general
@@ -5296,8 +5298,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
if (kf.fd == fd) {
len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
if (len == 0) return error.NameTooLong;
- mem.copy(u8, out_buffer, kf.path[0..len]);
- return out_buffer[0..len];
+ const result = out_buffer[0..len];
+ @memcpy(result, kf.path[0..len]);
+ return result;
}
i += @intCast(usize, kf.structsize);
}
@@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
if (builtin.os.tag == .linux) {
const uts = uname();
const hostname = mem.sliceTo(&uts.nodename, 0);
- mem.copy(u8, name_buffer, hostname);
- return name_buffer[0..hostname.len];
+ const result = name_buffer[0..hostname.len];
+ @memcpy(result, hostname);
+ return result;
}
@compileError("TODO implement gethostname for this OS");
@@ -5725,7 +5729,7 @@ pub fn res_mkquery(
@memset(q[0..n], 0);
q[2] = @as(u8, op) * 8 + 1;
q[5] = 1;
- mem.copy(u8, q[13..], name);
+ @memcpy(q[13..][0..name.len], name);
var i: usize = 13;
var j: usize = undefined;
while (q[i] != 0) : (i = j + 1) {
@@ -5748,7 +5752,7 @@ pub fn res_mkquery(
q[0] = @truncate(u8, id / 256);
q[1] = @truncate(u8, id);
- mem.copy(u8, buf, q[0..n]);
+ @memcpy(buf[0..n], q[0..n]);
return n;
}
@@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;
// >= rather than > to make room for the null byte
if (name.len >= MFD_MAX_NAME_LEN) return error.NameTooLong;
- mem.copy(u8, &path_with_null, name);
+ @memcpy(path_with_null[0..name.len], name);
path_with_null[name.len] = 0;
return path_with_null;
}
lib/std/process.zig
@@ -855,7 +855,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 {
const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]);
const result_contents = buf[slice_list_bytes..];
- mem.copy(u8, result_contents, contents_slice);
+ @memcpy(result_contents[0..contents_slice.len], contents_slice);
var contents_index: usize = 0;
for (slice_sizes, 0..) |len, i| {
lib/std/Progress.zig
@@ -374,7 +374,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
self.columns_written += self.output_buffer.len - end.*;
end.* = self.output_buffer.len;
const suffix = "... ";
- std.mem.copy(u8, self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);
+ @memcpy(self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);
},
}
}
lib/std/segmented_list.zig
@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
allocator.free(new_dynamic_segments);
} else {
// Good thing we allocated that new memory slice.
- mem.copy([*]T, new_dynamic_segments, self.dynamic_segments[0..new_cap_shelf_count]);
+ @memcpy(new_dynamic_segments, self.dynamic_segments[0..new_cap_shelf_count]);
allocator.free(self.dynamic_segments);
self.dynamic_segments = new_dynamic_segments;
}
@@ -248,24 +248,21 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
var i = start;
if (end <= prealloc_item_count) {
- mem.copy(T, dest[i - start ..], self.prealloc_segment[i..end]);
+ const src = self.prealloc_segment[i..end];
+ @memcpy(dest[i - start ..][0..src.len], src);
return;
} else if (i < prealloc_item_count) {
- mem.copy(T, dest[i - start ..], self.prealloc_segment[i..]);
+ const src = self.prealloc_segment[i..];
+ @memcpy(dest[i - start ..][0..src.len], src);
i = prealloc_item_count;
}
while (i < end) {
const shelf_index = shelfIndex(i);
const copy_start = boxIndex(i, shelf_index);
- const copy_end = std.math.min(shelfSize(shelf_index), copy_start + end - i);
-
- mem.copy(
- T,
- dest[i - start ..],
- self.dynamic_segments[shelf_index][copy_start..copy_end],
- );
-
+ const copy_end = @min(shelfSize(shelf_index), copy_start + end - i);
+ const src = self.dynamic_segments[shelf_index][copy_start..copy_end];
+ @memcpy(dest[i - start ..][0..src.len], src);
i += (copy_end - copy_start);
}
}
@@ -498,11 +495,11 @@ fn testSegmentedList(comptime prealloc: usize) !void {
control[@intCast(usize, i)] = i + 1;
}
- mem.set(i32, dest[0..], 0);
+ @memset(dest[0..], 0);
list.writeToSlice(dest[0..], 0);
try testing.expect(mem.eql(i32, control[0..], dest[0..]));
- mem.set(i32, dest[0..], 0);
+ @memset(dest[0..], 0);
list.writeToSlice(dest[50..], 50);
try testing.expect(mem.eql(i32, control[50..], dest[50..]));
}
lib/std/sort.zig
@@ -361,8 +361,10 @@ pub fn sort(
if (lessThan(context, items[B1.end - 1], items[A1.start])) {
// the two ranges are in reverse order, so copy them in reverse order into the cache
- mem.copy(T, cache[B1.length()..], items[A1.start..A1.end]);
- mem.copy(T, cache[0..], items[B1.start..B1.end]);
+ const a1_items = items[A1.start..A1.end];
+ @memcpy(cache[B1.length()..][0..a1_items.len], a1_items);
+ const b1_items = items[B1.start..B1.end];
+ @memcpy(cache[0..b1_items.len], b1_items);
} else if (lessThan(context, items[B1.start], items[A1.end - 1])) {
// these two ranges weren't already in order, so merge them into the cache
mergeInto(T, items, A1, B1, context, lessThan, cache[0..]);
@@ -371,23 +373,29 @@ pub fn sort(
if (!lessThan(context, items[B2.start], items[A2.end - 1]) and !lessThan(context, items[A2.start], items[B1.end - 1])) continue;
// copy A1 and B1 into the cache in the same order
- mem.copy(T, cache[0..], items[A1.start..A1.end]);
- mem.copy(T, cache[A1.length()..], items[B1.start..B1.end]);
+ const a1_items = items[A1.start..A1.end];
+ @memcpy(cache[0..a1_items.len], a1_items);
+ const b1_items = items[B1.start..B1.end];
+ @memcpy(cache[A1.length()..][0..b1_items.len], b1_items);
}
A1 = Range.init(A1.start, B1.end);
// merge A2 and B2 into the cache
if (lessThan(context, items[B2.end - 1], items[A2.start])) {
// the two ranges are in reverse order, so copy them in reverse order into the cache
- mem.copy(T, cache[A1.length() + B2.length() ..], items[A2.start..A2.end]);
- mem.copy(T, cache[A1.length()..], items[B2.start..B2.end]);
+ const a2_items = items[A2.start..A2.end];
+ @memcpy(cache[A1.length() + B2.length() ..][0..a2_items.len], a2_items);
+ const b2_items = items[B2.start..B2.end];
+ @memcpy(cache[A1.length()..][0..b2_items.len], b2_items);
} else if (lessThan(context, items[B2.start], items[A2.end - 1])) {
// these two ranges weren't already in order, so merge them into the cache
mergeInto(T, items, A2, B2, context, lessThan, cache[A1.length()..]);
} else {
// copy A2 and B2 into the cache in the same order
- mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);
- mem.copy(T, cache[A1.length() + A2.length() ..], items[B2.start..B2.end]);
+ const a2_items = items[A2.start..A2.end];
+ @memcpy(cache[A1.length()..][0..a2_items.len], a2_items);
+ const b2_items = items[B2.start..B2.end];
+ @memcpy(cache[A1.length() + A2.length() ..][0..b2_items.len], b2_items);
}
A2 = Range.init(A2.start, B2.end);
@@ -397,15 +405,19 @@ pub fn sort(
if (lessThan(context, cache[B3.end - 1], cache[A3.start])) {
// the two ranges are in reverse order, so copy them in reverse order into the items
- mem.copy(T, items[A1.start + A2.length() ..], cache[A3.start..A3.end]);
- mem.copy(T, items[A1.start..], cache[B3.start..B3.end]);
+ const a3_items = cache[A3.start..A3.end];
+ @memcpy(items[A1.start + A2.length() ..][0..a3_items.len], a3_items);
+ const b3_items = cache[B3.start..B3.end];
+ @memcpy(items[A1.start..][0..b3_items.len], b3_items);
} else if (lessThan(context, cache[B3.start], cache[A3.end - 1])) {
// these two ranges weren't already in order, so merge them back into the items
mergeInto(T, cache[0..], A3, B3, context, lessThan, items[A1.start..]);
} else {
// copy A3 and B3 into the items in the same order
- mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);
- mem.copy(T, items[A1.start + A1.length() ..], cache[B3.start..B3.end]);
+ const a3_items = cache[A3.start..A3.end];
+ @memcpy(items[A1.start..][0..a3_items.len], a3_items);
+ const b3_items = cache[B3.start..B3.end];
+ @memcpy(items[A1.start + A1.length() ..][0..b3_items.len], b3_items);
}
}
@@ -423,7 +435,8 @@ pub fn sort(
mem.rotate(T, items[A.start..B.end], A.length());
} else if (lessThan(context, items[B.start], items[A.end - 1])) {
// these two ranges weren't already in order, so we'll need to merge them!
- mem.copy(T, cache[0..], items[A.start..A.end]);
+ const a_items = items[A.start..A.end];
+ @memcpy(cache[0..a_items.len], a_items);
mergeExternal(T, items, A, B, context, lessThan, cache[0..]);
}
}
@@ -718,7 +731,8 @@ pub fn sort(
// if the first unevenly sized A block fits into the cache, copy it there for when we go to Merge it
// otherwise, if the second buffer is available, block swap the contents into that
if (lastA.length() <= cache.len) {
- mem.copy(T, cache[0..], items[lastA.start..lastA.end]);
+ const last_a_items = items[lastA.start..lastA.end];
+ @memcpy(cache[0..last_a_items.len], last_a_items);
} else if (buffer2.length() > 0) {
blockSwap(T, items, lastA.start, buffer2.start, lastA.length());
}
@@ -762,7 +776,7 @@ pub fn sort(
if (buffer2.length() > 0 or block_size <= cache.len) {
// copy the previous A block into the cache or buffer2, since that's where we need it to be when we go to merge it anyway
if (block_size <= cache.len) {
- mem.copy(T, cache[0..], items[blockA.start .. blockA.start + block_size]);
+ @memcpy(cache[0..block_size], items[blockA.start..][0..block_size]);
} else {
blockSwap(T, items, blockA.start, buffer2.start, block_size);
}
@@ -1122,7 +1136,8 @@ fn mergeInto(
insert_index += 1;
if (A_index == A_last) {
// copy the remainder of B into the final array
- mem.copy(T, into[insert_index..], from[B_index..B_last]);
+ const from_b = from[B_index..B_last];
+ @memcpy(into[insert_index..][0..from_b.len], from_b);
break;
}
} else {
@@ -1131,7 +1146,8 @@ fn mergeInto(
insert_index += 1;
if (B_index == B_last) {
// copy the remainder of A into the final array
- mem.copy(T, into[insert_index..], from[A_index..A_last]);
+ const from_a = from[A_index..A_last];
+ @memcpy(into[insert_index..][0..from_a.len], from_a);
break;
}
}
@@ -1171,7 +1187,8 @@ fn mergeExternal(
}
// copy the remainder of A into the final array
- mem.copy(T, items[insert_index..], cache[A_index..A_last]);
+ const cache_a = cache[A_index..A_last];
+ @memcpy(items[insert_index..][0..cache_a.len], cache_a);
}
fn swap(
@@ -1305,7 +1322,7 @@ test "sort" {
for (u8cases) |case| {
var buf: [8]u8 = undefined;
const slice = buf[0..case[0].len];
- mem.copy(u8, slice, case[0]);
+ @memcpy(slice, case[0]);
sort(u8, slice, {}, asc_u8);
try testing.expect(mem.eql(u8, slice, case[1]));
}
@@ -1340,7 +1357,7 @@ test "sort" {
for (i32cases) |case| {
var buf: [8]i32 = undefined;
const slice = buf[0..case[0].len];
- mem.copy(i32, slice, case[0]);
+ @memcpy(slice, case[0]);
sort(i32, slice, {}, asc_i32);
try testing.expect(mem.eql(i32, slice, case[1]));
}
@@ -1377,7 +1394,7 @@ test "sort descending" {
for (rev_cases) |case| {
var buf: [8]i32 = undefined;
const slice = buf[0..case[0].len];
- mem.copy(i32, slice, case[0]);
+ @memcpy(slice, case[0]);
sort(i32, slice, {}, desc_i32);
try testing.expect(mem.eql(i32, slice, case[1]));
}
lib/std/target.zig
@@ -1596,7 +1596,7 @@ pub const Target = struct {
/// Asserts that the length is less than or equal to 255 bytes.
pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
if (dl_or_null) |dl| {
- mem.copy(u8, &self.buffer, dl);
+ @memcpy(self.buffer[0..dl.len], dl);
self.max_byte = @intCast(u8, dl.len - 1);
} else {
self.max_byte = null;
@@ -1612,7 +1612,7 @@ pub const Target = struct {
return r.*;
}
fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
- mem.copy(u8, &r.buffer, s);
+ @memcpy(r.buffer[0..s.len], s);
r.max_byte = @intCast(u8, s.len - 1);
return r.*;
}
lib/std/Thread.zig
@@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
const name_with_terminator = blk: {
var name_buf: [max_name_len:0]u8 = undefined;
- std.mem.copy(u8, &name_buf, name);
+ @memcpy(name_buf[0..name.len], name);
name_buf[name.len] = 0;
break :blk name_buf[0..name.len :0];
};
lib/std/tz.zig
@@ -137,7 +137,7 @@ pub const Tz = struct {
const name = std.mem.sliceTo(designators[tt.name_data[0]..], 0);
// We are mandating the "SHOULD" 6-character limit so we can pack the struct better, and to conform to POSIX.
if (name.len > 6) return error.Malformed; // rfc8536: Time zone designations SHOULD consist of at least three (3) and no more than six (6) ASCII characters.
- std.mem.copy(u8, tt.name_data[0..], name);
+ @memcpy(tt.name_data[0..name.len], name);
tt.name_data[name.len] = 0;
}
src/arch/aarch64/CodeGen.zig
@@ -1630,7 +1630,7 @@ fn allocRegs(
const read_locks = locks[0..read_args.len];
const write_locks = locks[read_args.len..];
- std.mem.set(?RegisterLock, locks, null);
+ @memset(locks, null);
defer for (locks) |lock| {
if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
};
@@ -4395,7 +4395,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
if (args.len + 1 <= Liveness.bpi - 1) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
buf[0] = callee;
- std.mem.copy(Air.Inst.Ref, buf[1..], args);
+ @memcpy(buf[1..][0..args.len], args);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, 1 + args.len);
@@ -5348,7 +5348,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
buf_index += 1;
}
if (buf_index + inputs.len > buf.len) break :simple;
- std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
+ @memcpy(buf[buf_index..][0..inputs.len], inputs);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
@@ -6055,7 +6055,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
if (elements.len <= Liveness.bpi - 1) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
- std.mem.copy(Air.Inst.Ref, &buf, elements);
+ @memcpy(buf[0..elements.len], elements);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/arm/CodeGen.zig
@@ -3114,7 +3114,7 @@ fn allocRegs(
const read_locks = locks[0..read_args.len];
const write_locks = locks[read_args.len..];
- std.mem.set(?RegisterLock, locks, null);
+ @memset(locks, null);
defer for (locks) |lock| {
if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
};
@@ -4341,7 +4341,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
if (args.len <= Liveness.bpi - 2) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
buf[0] = callee;
- std.mem.copy(Air.Inst.Ref, buf[1..], args);
+ @memcpy(buf[1..][0..args.len], args);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, 1 + args.len);
@@ -5263,7 +5263,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
buf_index += 1;
}
if (buf_index + inputs.len > buf.len) break :simple;
- std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
+ @memcpy(buf[buf_index..][0..inputs.len], inputs);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
@@ -6000,7 +6000,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
if (elements.len <= Liveness.bpi - 1) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
- std.mem.copy(Air.Inst.Ref, &buf, elements);
+ @memcpy(buf[0..elements.len], elements);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/riscv64/CodeGen.zig
@@ -1784,7 +1784,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
if (args.len <= Liveness.bpi - 2) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
buf[0] = callee;
- std.mem.copy(Air.Inst.Ref, buf[1..], args);
+ @memcpy(buf[1..][0..args.len], args);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, 1 + args.len);
@@ -2225,7 +2225,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
buf_index += 1;
}
if (buf_index + inputs.len > buf.len) break :simple;
- std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
+ @memcpy(buf[buf_index..][0..inputs.len], inputs);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
@@ -2500,7 +2500,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
if (elements.len <= Liveness.bpi - 1) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
- std.mem.copy(Air.Inst.Ref, &buf, elements);
+ @memcpy(buf[0..elements.len], elements);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/sparc64/CodeGen.zig
@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
if (elements.len <= Liveness.bpi - 1) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
- std.mem.copy(Air.Inst.Ref, &buf, elements);
+ @memcpy(buf[0..elements.len], elements);
return self.finishAir(inst, result, buf);
}
var bt = try self.iterateBigTomb(inst, elements.len);
@@ -987,7 +987,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
buf_index += 1;
}
if (buf_index + inputs.len > buf.len) break :simple;
- std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
+ @memcpy(buf[buf_index..][0..inputs.len], inputs);
return self.finishAir(inst, result, buf);
}
@@ -1314,7 +1314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
if (args.len + 1 <= Liveness.bpi - 1) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
buf[0] = callee;
- std.mem.copy(Air.Inst.Ref, buf[1..], args);
+ @memcpy(buf[1..][0..args.len], args);
return self.finishAir(inst, result, buf);
}
src/arch/x86_64/abi.zig
@@ -321,7 +321,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class {
byte_i = 0;
result_i += 1;
}
- std.mem.copy(Class, result[result_i..], field_class);
+ @memcpy(result[result_i..][0..field_class.len], field_class);
result_i += field_class.len;
// If there are any bytes leftover, we have to try to combine
// the next field with them.
src/arch/x86_64/CodeGen.zig
@@ -7117,7 +7117,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
buf_index += 1;
}
if (buf_index + inputs.len > buf.len) break :simple;
- std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);
+ @memcpy(buf[buf_index..][0..inputs.len], inputs);
return self.finishAir(inst, result, buf);
}
var bt = self.liveness.iterateBigTomb(inst);
@@ -8505,7 +8505,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
if (elements.len <= Liveness.bpi - 1) {
var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
- std.mem.copy(Air.Inst.Ref, &buf, elements);
+ @memcpy(buf[0..elements.len], elements);
return self.finishAir(inst, result, buf);
}
var bt = self.liveness.iterateBigTomb(inst);
src/arch/x86_64/encoder.zig
@@ -182,7 +182,7 @@ pub const Instruction = struct {
.encoding = encoding,
.ops = [1]Operand{.none} ** 4,
};
- std.mem.copy(Operand, &inst.ops, ops);
+ @memcpy(inst.ops[0..ops.len], ops);
return inst;
}
@@ -859,7 +859,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co
const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
var padding = try testing.allocator.alloc(u8, idx + 5);
defer testing.allocator.free(padding);
- std.mem.set(u8, padding, ' ');
+ @memset(padding, ' ');
std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{
assembly,
expected_fmt,
src/arch/x86_64/Encoding.zig
@@ -546,7 +546,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op
.encoding = encoding,
.ops = [1]Operand{.none} ** 4,
};
- std.mem.copy(Operand, &inst.ops, ops);
+ @memcpy(inst.ops[0..ops.len], ops);
var cwriter = std.io.countingWriter(std.io.null_writer);
inst.encode(cwriter.writer(), .{ .allow_frame_loc = true }) catch unreachable; // Not allowed to fail here unless OOM.
src/codegen/c.zig
@@ -2411,9 +2411,9 @@ pub fn genErrDecls(o: *Object) !void {
const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);
defer o.dg.gpa.free(name_buf);
- mem.copy(u8, name_buf, name_prefix);
+ @memcpy(name_buf[0..name_prefix.len], name_prefix);
for (o.dg.module.error_name_list.items) |name| {
- mem.copy(u8, name_buf[name_prefix.len..], name);
+ @memcpy(name_buf[name_prefix.len..][0..name.len], name);
const identifier = name_buf[0 .. name_prefix.len + name.len];
var name_ty_pl = Type.Payload.Len{ .base = .{ .tag = .array_u8_sentinel_0 }, .data = name.len };
@@ -4877,7 +4877,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
const literal = mem.sliceTo(asm_source[src_i..], '%');
src_i += literal.len;
- mem.copy(u8, fixed_asm_source[dst_i..], literal);
+ @memcpy(fixed_asm_source[dst_i..][0..literal.len], literal);
dst_i += literal.len;
if (src_i >= asm_source.len) break;
@@ -4902,9 +4902,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
const name = desc[0..colon];
const modifier = desc[colon + 1 ..];
- mem.copy(u8, fixed_asm_source[dst_i..], modifier);
+ @memcpy(fixed_asm_source[dst_i..][0..modifier.len], modifier);
dst_i += modifier.len;
- mem.copy(u8, fixed_asm_source[dst_i..], name);
+ @memcpy(fixed_asm_source[dst_i..][0..name.len], name);
dst_i += name.len;
src_i += desc.len;
@@ -7455,7 +7455,7 @@ fn formatIntLiteral(
var int_buf: Value.BigIntSpace = undefined;
const int = if (data.val.isUndefDeep()) blk: {
undef_limbs = try allocator.alloc(BigIntLimb, BigInt.calcTwosCompLimbCount(data.int_info.bits));
- mem.set(BigIntLimb, undef_limbs, undefPattern(BigIntLimb));
+ @memset(undef_limbs, undefPattern(BigIntLimb));
var undef_int = BigInt.Mutable{
.limbs = undef_limbs,
@@ -7550,7 +7550,7 @@ fn formatIntLiteral(
} else {
try data.cty.renderLiteralPrefix(writer, data.kind);
wrap.convertToTwosComplement(int, data.int_info.signedness, c_bits);
- mem.set(BigIntLimb, wrap.limbs[wrap.len..], 0);
+ @memset(wrap.limbs[wrap.len..], 0);
wrap.len = wrap.limbs.len;
const limbs_per_c_limb = @divExact(wrap.len, c_limb_info.count);
src/link/MachO/Object.zig
@@ -156,7 +156,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
// Prepopulate relocations per section lookup table.
try self.section_relocs_lookup.resize(allocator, nsects);
- mem.set(u32, self.section_relocs_lookup.items, 0);
+ @memset(self.section_relocs_lookup.items, 0);
// Parse symtab.
const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {
@@ -189,10 +189,10 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
};
}
- mem.set(i64, self.globals_lookup, -1);
- mem.set(AtomIndex, self.atom_by_index_table, 0);
- mem.set(Entry, self.source_section_index_lookup, .{});
- mem.set(Entry, self.relocs_lookup, .{});
+ @memset(self.globals_lookup, -1);
+ @memset(self.atom_by_index_table, 0);
+ @memset(self.source_section_index_lookup, .{});
+ @memset(self.relocs_lookup, .{});
// You would expect that the symbol table is at least pre-sorted based on symbol's type:
// local < extern defined < undefined. Unfortunately, this is not guaranteed! For instance,
@@ -252,7 +252,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
self.unwind_info_sect_id = self.getSourceSectionIndexByName("__LD", "__compact_unwind");
if (self.hasUnwindRecords()) {
self.unwind_relocs_lookup = try allocator.alloc(Record, self.getUnwindRecords().len);
- mem.set(Record, self.unwind_relocs_lookup, .{ .dead = true, .reloc = .{} });
+ @memset(self.unwind_relocs_lookup, .{ .dead = true, .reloc = .{} });
}
}
src/link/MachO/Trie.zig
@@ -499,7 +499,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {
const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
var padding = try testing.allocator.alloc(u8, idx + 5);
defer testing.allocator.free(padding);
- mem.set(u8, padding, ' ');
+ @memset(padding, ' ');
std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });
return error.TestFailed;
}
src/link/MachO/UnwindInfo.zig
@@ -659,7 +659,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
const padding = buffer.items.len - cwriter.bytes_written;
if (padding > 0) {
const offset = math.cast(usize, cwriter.bytes_written) orelse return error.Overflow;
- mem.set(u8, buffer.items[offset..], 0);
+ @memset(buffer.items[offset..], 0);
}
try zld.file.pwriteAll(buffer.items, sect.offset);
src/link/MachO/zld.zig
@@ -2140,7 +2140,7 @@ pub const Zld = struct {
var buffer = try gpa.alloc(u8, needed_size);
defer gpa.free(buffer);
- mem.set(u8, buffer, 0);
+ @memset(buffer, 0);
var stream = std.io.fixedBufferStream(buffer);
const writer = stream.writer();
@@ -2352,7 +2352,7 @@ pub const Zld = struct {
const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
defer self.gpa.free(buffer);
- mem.set(u8, buffer, 0);
+ @memset(buffer, 0);
mem.copy(u8, buffer, mem.sliceAsBytes(out_dice.items));
log.debug("writing data-in-code from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });
@@ -2484,7 +2484,7 @@ pub const Zld = struct {
const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
defer self.gpa.free(buffer);
- mem.set(u8, buffer, 0);
+ @memset(buffer, 0);
mem.copy(u8, buffer, self.strtab.buffer.items);
try self.file.pwriteAll(buffer, offset);
@@ -3199,7 +3199,7 @@ pub const Zld = struct {
scoped_log.debug(" object({d}): {s}", .{ id, object.name });
if (object.in_symtab == null) continue;
for (object.symtab, 0..) |sym, sym_id| {
- mem.set(u8, &buf, '_');
+ @memset(&buf, '_');
scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{
sym_id,
object.getSymbolName(@intCast(u32, sym_id)),
@@ -4007,7 +4007,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });
var padding = try zld.gpa.alloc(u8, size);
defer zld.gpa.free(padding);
- mem.set(u8, padding, 0);
+ @memset(padding, 0);
try zld.file.pwriteAll(padding, start);
}
}
src/link/Coff.zig
@@ -2367,12 +2367,12 @@ pub fn getAtomIndexForSymbol(self: *const Coff, sym_loc: SymbolWithLoc) ?Atom.In
fn setSectionName(self: *Coff, header: *coff.SectionHeader, name: []const u8) !void {
if (name.len <= 8) {
mem.copy(u8, &header.name, name);
- mem.set(u8, header.name[name.len..], 0);
+ @memset(header.name[name.len..], 0);
return;
}
const offset = try self.strtab.insert(self.base.allocator, name);
const name_offset = fmt.bufPrint(&header.name, "/{d}", .{offset}) catch unreachable;
- mem.set(u8, header.name[name_offset.len..], 0);
+ @memset(header.name[name_offset.len..], 0);
}
fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const u8 {
@@ -2386,16 +2386,16 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const
fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {
if (name.len <= 8) {
mem.copy(u8, &symbol.name, name);
- mem.set(u8, symbol.name[name.len..], 0);
+ @memset(symbol.name[name.len..], 0);
return;
}
const offset = try self.strtab.insert(self.base.allocator, name);
- mem.set(u8, symbol.name[0..4], 0);
+ @memset(symbol.name[0..4], 0);
mem.writeIntLittle(u32, symbol.name[4..8], offset);
}
fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {
- mem.set(u8, buf[0..4], '_');
+ @memset(buf[0..4], '_');
switch (sym.section_number) {
.UNDEFINED => {
buf[3] = 'u';
src/link/Dwarf.zig
@@ -1189,7 +1189,7 @@ pub fn commitDeclState(
if (needed_size > segment_size) {
log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});
try debug_line.resize(self.allocator, needed_size);
- mem.set(u8, debug_line.items[segment_size..], 0);
+ @memset(debug_line.items[segment_size..], 0);
}
debug_line.items.len = needed_size;
}
@@ -1458,7 +1458,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
if (needed_size > segment_size) {
log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});
try debug_info.resize(self.allocator, needed_size);
- mem.set(u8, debug_info.items[segment_size..], 0);
+ @memset(debug_info.items[segment_size..], 0);
}
debug_info.items.len = needed_size;
}
@@ -2076,9 +2076,9 @@ fn writeDbgInfoNopsToArrayList(
buffer.items.len,
offset + content.len + next_padding_size + 1,
));
- mem.set(u8, buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));
+ @memset(buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));
mem.copy(u8, buffer.items[offset..], content);
- mem.set(u8, buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));
+ @memset(buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));
if (trailing_zero) {
buffer.items[offset + content.len + next_padding_size] = 0;
src/link/Elf.zig
@@ -1997,7 +1997,7 @@ fn writeElfHeader(self: *Elf) !void {
// OS ABI, often set to 0 regardless of target platform
// ABI Version, possibly used by glibc but not by static executables
// padding
- mem.set(u8, hdr_buf[index..][0..9], 0);
+ @memset(hdr_buf[index..][0..9], 0);
index += 9;
assert(index == 16);
src/link/MachO.zig
@@ -1454,7 +1454,7 @@ fn createThreadLocalDescriptorAtom(self: *MachO, sym_name: []const u8, target: S
});
var code: [size]u8 = undefined;
- mem.set(u8, &code, 0);
+ @memset(&code, 0);
try self.writeAtom(atom_index, &code);
return atom_index;
@@ -3234,7 +3234,7 @@ fn writeDyldInfoData(self: *MachO) !void {
var buffer = try gpa.alloc(u8, needed_size);
defer gpa.free(buffer);
- mem.set(u8, buffer, 0);
+ @memset(buffer, 0);
var stream = std.io.fixedBufferStream(buffer);
const writer = stream.writer();
@@ -3389,7 +3389,7 @@ fn writeStrtab(self: *MachO) !void {
const buffer = try gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
defer gpa.free(buffer);
- mem.set(u8, buffer, 0);
+ @memset(buffer, 0);
mem.copy(u8, buffer, self.strtab.buffer.items);
try self.base.file.?.pwriteAll(buffer, offset);
@@ -4096,8 +4096,8 @@ pub fn logSections(self: *MachO) void {
}
fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
- mem.set(u8, buf[0..4], '_');
- mem.set(u8, buf[4..], ' ');
+ @memset(buf[0..4], '_');
+ @memset(buf[4..], ' ');
if (sym.sect()) {
buf[0] = 's';
}
src/link/Wasm.zig
@@ -1976,7 +1976,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
// We do not have to do this when exporting the memory (the default) because the runtime
// will do it for us, and we do not emit the bss segment at all.
if ((wasm.base.options.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {
- std.mem.set(u8, atom.code.items, 0);
+ @memset(atom.code.items, 0);
}
const should_merge = wasm.base.options.output_mode != .Obj;
src/Compilation.zig
@@ -2165,7 +2165,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
const digest_start = 2; // "o/[digest]/[basename]"
if (comp.whole_bin_sub_path) |sub_path| {
- mem.copy(u8, sub_path[digest_start..], digest);
+ @memcpy(sub_path[digest_start..][0..digest.len], digest);
comp.bin_file.options.emit = .{
.directory = comp.local_cache_directory,
@@ -2174,7 +2174,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
}
if (comp.whole_implib_sub_path) |sub_path| {
- mem.copy(u8, sub_path[digest_start..], digest);
+ @memcpy(sub_path[digest_start..][0..digest.len], digest);
comp.bin_file.options.implib_emit = .{
.directory = comp.local_cache_directory,
@@ -4432,7 +4432,7 @@ pub fn addCCArgs(
assert(prefix.len == prefix_len);
var march_buf: [prefix_len + letters.len + 1]u8 = undefined;
var march_index: usize = prefix_len;
- mem.copy(u8, &march_buf, prefix);
+ @memcpy(march_buf[0..prefix.len], prefix);
if (std.Target.riscv.featureSetHas(target.cpu.features, .e)) {
march_buf[march_index] = 'e';
src/Liveness.zig
@@ -156,7 +156,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {
errdefer a.special.deinit(gpa);
defer a.extra.deinit(gpa);
- std.mem.set(usize, a.tomb_bits, 0);
+ @memset(a.tomb_bits, 0);
const main_body = air.getMainBody();
@@ -1841,7 +1841,7 @@ fn analyzeInstSwitchBr(
var case_infos = try gpa.alloc(ControlBranchInfo, ncases + 1); // +1 for else
defer gpa.free(case_infos);
- std.mem.set(ControlBranchInfo, case_infos, .{});
+ @memset(case_infos, .{});
defer for (case_infos) |*info| {
info.branch_deaths.deinit(gpa);
info.live_set.deinit(gpa);
@@ -1898,7 +1898,7 @@ fn analyzeInstSwitchBr(
const mirrored_deaths = try gpa.alloc(DeathList, ncases + 1);
defer gpa.free(mirrored_deaths);
- std.mem.set(DeathList, mirrored_deaths, .{});
+ @memset(mirrored_deaths, .{});
defer for (mirrored_deaths) |*md| md.deinit(gpa);
{
@@ -1993,7 +1993,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
};
errdefer a.gpa.free(extra_tombs);
- std.mem.set(u32, extra_tombs, 0);
+ @memset(extra_tombs, 0);
const will_die_immediately: bool = switch (pass) {
.loop_analysis => false, // track everything, since we don't have full liveness information yet
src/objcopy.zig
@@ -1088,7 +1088,7 @@ fn ElfFile(comptime is_64: bool) type {
const crc_offset = std.mem.alignForward(link.name.len + 1, 4);
const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);
std.mem.copy(u8, buf[0..link.name.len], link.name);
- std.mem.set(u8, buf[link.name.len..crc_offset], 0);
+ @memset(buf[link.name.len..crc_offset], 0);
std.mem.copy(u8, buf[crc_offset..], std.mem.asBytes(&link.crc32));
break :payload buf;
};
src/print_air.zig
@@ -846,7 +846,7 @@ const Writer = struct {
else blk: {
const slice = w.gpa.alloc([]const Air.Inst.Index, switch_br.data.cases_len + 1) catch
@panic("out of memory");
- std.mem.set([]const Air.Inst.Index, slice, &.{});
+ @memset(slice, &.{});
break :blk Liveness.SwitchBrTable{ .deaths = slice };
};
defer w.gpa.free(liveness.deaths);
src/print_zir.zig
@@ -682,7 +682,7 @@ const Writer = struct {
const limbs = try self.gpa.alloc(std.math.big.Limb, inst_data.len);
defer self.gpa.free(limbs);
- mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);
+ @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
const big_int: std.math.big.int.Const = .{
.limbs = limbs,
.positive = true,
src/Sema.zig
@@ -206,9 +206,9 @@ pub const InstMap = struct {
const start_diff = old_start - better_start;
const new_items = try allocator.alloc(Air.Inst.Ref, better_capacity);
- mem.set(Air.Inst.Ref, new_items[0..start_diff], .none);
- mem.copy(Air.Inst.Ref, new_items[start_diff..], map.items);
- mem.set(Air.Inst.Ref, new_items[start_diff + map.items.len ..], .none);
+ @memset(new_items[0..start_diff], .none);
+ @memcpy(new_items[start_diff..][0..map.items.len], map.items);
+ @memset(new_items[start_diff + map.items.len ..], .none);
allocator.free(map.items);
map.items = new_items;
@@ -4307,7 +4307,7 @@ fn validateStructInit(
// Maps field index to field_ptr index of where it was already initialized.
const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount());
defer gpa.free(found_fields);
- mem.set(Zir.Inst.Index, found_fields, 0);
+ @memset(found_fields, 0);
var struct_ptr_zir_ref: Zir.Inst.Ref = undefined;
@@ -5113,7 +5113,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
const byte_count = int.len * @sizeOf(std.math.big.Limb);
const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];
const limbs = try arena.alloc(std.math.big.Limb, int.len);
- mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);
+ @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
return sema.addConstant(
Type.initTag(.comptime_int),
@@ -5967,7 +5967,7 @@ fn addDbgVar(
const elements_used = name.len / 4 + 1;
try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
- mem.copy(u8, buffer, name);
+ @memcpy(buffer[0..name.len], name);
buffer[name.len] = 0;
sema.air_extra.items.len += elements_used;
@@ -10354,7 +10354,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
.Enum => {
seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount());
empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum();
- mem.set(?Module.SwitchProngSrc, seen_enum_fields, null);
+ @memset(seen_enum_fields, null);
// `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
var extra_index: usize = special.end;
@@ -12809,8 +12809,8 @@ fn analyzeTupleMul(
}
i = 0;
while (i < factor) : (i += 1) {
- mem.copy(Type, types[tuple_len * i ..], types[0..tuple_len]);
- mem.copy(Value, values[tuple_len * i ..], values[0..tuple_len]);
+ mem.copyForwards(Type, types[tuple_len * i ..], types[0..tuple_len]);
+ mem.copyForwards(Value, values[tuple_len * i ..], values[0..tuple_len]);
}
break :rs runtime_src;
};
@@ -12835,7 +12835,7 @@ fn analyzeTupleMul(
}
i = 1;
while (i < factor) : (i += 1) {
- mem.copy(Air.Inst.Ref, element_refs[tuple_len * i ..], element_refs[0..tuple_len]);
+ @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);
}
return block.addAggregateInit(tuple_ty, element_refs);
@@ -15057,29 +15057,29 @@ fn zirAsm(
sema.appendRefsAssumeCapacity(args);
for (outputs) |o| {
const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
- mem.copy(u8, buffer, o.c);
+ @memcpy(buffer[0..o.c.len], o.c);
buffer[o.c.len] = 0;
- mem.copy(u8, buffer[o.c.len + 1 ..], o.n);
+ @memcpy(buffer[o.c.len + 1 ..][0..o.n.len], o.n);
buffer[o.c.len + 1 + o.n.len] = 0;
sema.air_extra.items.len += (o.c.len + o.n.len + (2 + 3)) / 4;
}
for (inputs) |input| {
const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
- mem.copy(u8, buffer, input.c);
+ @memcpy(buffer[0..input.c.len], input.c);
buffer[input.c.len] = 0;
- mem.copy(u8, buffer[input.c.len + 1 ..], input.n);
+ @memcpy(buffer[input.c.len + 1 ..][0..input.n.len], input.n);
buffer[input.c.len + 1 + input.n.len] = 0;
sema.air_extra.items.len += (input.c.len + input.n.len + (2 + 3)) / 4;
}
for (clobbers) |clobber| {
const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
- mem.copy(u8, buffer, clobber);
+ @memcpy(buffer[0..clobber.len], clobber);
buffer[clobber.len] = 0;
sema.air_extra.items.len += clobber.len / 4 + 1;
}
{
const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
- mem.copy(u8, buffer, asm_source);
+ @memcpy(buffer[0..asm_source.len], asm_source);
sema.air_extra.items.len += (asm_source.len + 3) / 4;
}
return asm_air;
@@ -17582,7 +17582,7 @@ fn structInitEmpty(
// The init values to use for the struct instance.
const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());
defer gpa.free(field_inits);
- mem.set(Air.Inst.Ref, field_inits, .none);
+ @memset(field_inits, .none);
return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false);
}
@@ -17675,7 +17675,7 @@ fn zirStructInit(
// The init values to use for the struct instance.
const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount());
defer gpa.free(field_inits);
- mem.set(Air.Inst.Ref, field_inits, .none);
+ @memset(field_inits, .none);
var field_i: u32 = 0;
var extra_index = extra.end;
@@ -27079,7 +27079,7 @@ fn beginComptimePtrMutation(
const array_len_including_sentinel =
try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
const elems = try arena.alloc(Value, array_len_including_sentinel);
- mem.set(Value, elems, Value.undef);
+ @memset(elems, Value.undef);
val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
@@ -27277,7 +27277,7 @@ fn beginComptimePtrMutation(
switch (parent.ty.zigTypeTag()) {
.Struct => {
const fields = try arena.alloc(Value, parent.ty.structFieldCount());
- mem.set(Value, fields, Value.undef);
+ @memset(fields, Value.undef);
val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
@@ -28425,7 +28425,7 @@ fn coerceTupleToStruct(
const fields = struct_ty.structFields();
const field_vals = try sema.arena.alloc(Value, fields.count());
const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
- mem.set(Air.Inst.Ref, field_refs, .none);
+ @memset(field_refs, .none);
const inst_ty = sema.typeOf(inst);
var runtime_src: ?LazySrcLoc = null;
@@ -28514,7 +28514,7 @@ fn coerceTupleToTuple(
const dest_field_count = tuple_ty.structFieldCount();
const field_vals = try sema.arena.alloc(Value, dest_field_count);
const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
- mem.set(Air.Inst.Ref, field_refs, .none);
+ @memset(field_refs, .none);
const inst_ty = sema.typeOf(inst);
const inst_field_count = inst_ty.structFieldCount();
src/value.zig
@@ -875,7 +875,7 @@ pub const Value = extern union {
.repeated => {
const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(target));
const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));
- std.mem.set(u8, result, byte);
+ @memset(result, byte);
return result;
},
.decl_ref => {
@@ -1287,7 +1287,7 @@ pub const Value = extern union {
const endian = target.cpu.arch.endian();
if (val.isUndef()) {
const size = @intCast(usize, ty.abiSize(target));
- std.mem.set(u8, buffer[0..size], 0xaa);
+ @memset(buffer[0..size], 0xaa);
return;
}
switch (ty.zigTypeTag()) {