From 6261c1373168b265047db5704d9d0fd5f2e458f2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 26 Apr 2023 13:57:08 -0700 Subject: update codebase to use `@memset` and `@memcpy` --- lib/std/hash/cityhash.zig | 4 ++-- lib/std/hash/wyhash.zig | 5 +++-- lib/std/hash/xxhash.zig | 12 ++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/std/hash') diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index 23b3ce02da..d0884b135f 100644 --- a/lib/std/hash/cityhash.zig +++ b/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) { diff --git a/lib/std/hash/wyhash.zig b/lib/std/hash/wyhash.zig index 2f30c26b75..772395eab9 100644 --- a/lib/std/hash/wyhash.zig +++ b/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); } diff --git a/lib/std/hash/xxhash.zig b/lib/std/hash/xxhash.zig index bf4877e029..88db1dc1bd 100644 --- a/lib/std/hash/xxhash.zig +++ b/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; } -- cgit v1.2.3