From 7664de7686276cfba431103847d35b9270433dee Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sat, 13 May 2023 06:53:31 -0700 Subject: [PATCH] leftover --- src/bench/string-handling.zig | 2 +- src/bun.js/webcore/blob.zig | 8 ++++---- src/bun.js/webcore/response.zig | 13 ++++++++----- src/bun.js/webcore/streams.zig | 1 - src/exact_size_matcher.zig | 10 +++++----- src/io/io_linux.zig | 4 ++-- src/js_lexer_tables.zig | 1 - src/sha.zig | 9 ++++----- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/bench/string-handling.zig b/src/bench/string-handling.zig index f9bee87e789efc..05f0f067f98f5b 100644 --- a/src/bench/string-handling.zig +++ b/src/bench/string-handling.zig @@ -34,7 +34,7 @@ pub fn main() anyerror!void { var i: usize = 0; while (j < amount) : (j += 1) { i = 0; - @memcpy(duped.ptr, contents.ptr, contents.len); + @memcpy(duped, contents); } if (index == std.math.maxInt(usize)) { diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 547dc73f15c8d9..25c7b20dd543a5 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -539,7 +539,7 @@ pub const Blob = struct { return JSPromise.resolvedPromiseValue(ctx.ptr(), cloned.toJS(ctx)).asObjectRef(); } else if (destination_type == .bytes and source_type == .file) { var fake_call_frame: [8]JSC.JSValue = undefined; - @memset(@ptrCast([*]u8, &fake_call_frame), 0, @sizeOf(@TypeOf(fake_call_frame))); + @memset(@ptrCast([*]u8, &fake_call_frame)[0..@sizeOf(@TypeOf(fake_call_frame))], 0); const blob_value = source_blob.getSlice(ctx, @ptrCast(*JSC.CallFrame, &fake_call_frame)); @@ -3689,10 +3689,10 @@ pub const InlineBlob = extern struct { var bytes_slice = inline_blob.bytes[0..total]; if (first.len > 0) - @memcpy(bytes_slice.ptr, first.ptr, first.len); + @memcpy(bytes_slice, first); if (second.len > 0) - @memcpy(bytes_slice.ptr + first.len, second.ptr, second.len); + @memcpy(bytes_slice[first.len..], second); inline_blob.len = @truncate(@TypeOf(inline_blob.len), total); return inline_blob; @@ -3707,7 +3707,7 @@ pub const InlineBlob = extern struct { }; if (data.len > 0) - @memcpy(&blob.bytes, data.ptr, data.len); + @memcpy(&blob.bytes, data); return blob; } diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index d283df5a09164c..4d3526ee99804e 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -1062,7 +1062,7 @@ pub const Fetch = struct { } else { var proxy_str = proxy_arg.toStringOrNull(globalThis) orelse return .zero; // proxy + url 1 allocation - var proxy_url_zig = proxy_str.getZigString(globalThis); + var proxy_url_zig = proxy_str.toSlice(globalThis); // ignore proxy if it is len = 0 if (proxy_url_zig.len == 0) { @@ -1073,9 +1073,9 @@ pub const Fetch = struct { JSC.JSError(bun.default_allocator, "Out of memory", .{}, ctx, exception); return .zero; }; - @memcpy(buffer.ptr, request.url.ptr, request.url.len); + @memcpy(buffer, request.url); var proxy_url_slice = buffer[request.url.len..]; - @memcpy(proxy_url_slice.ptr, proxy_url_zig.ptr, proxy_url_zig.len); + @memcpy(proxy_url_slice, proxy_url_zig.slice()); url = ZigURL.parse(buffer[0..request.url.len]); proxy = ZigURL.parse(proxy_url_slice); @@ -1228,9 +1228,12 @@ pub const Fetch = struct { JSC.JSError(bun.default_allocator, "Out of memory", .{}, ctx, exception); return .zero; }; - @memcpy(buffer.ptr, url_zig.ptr, url_zig.len); + var url_safe = url_zig.toSlice(globalThis); + defer url_safe.deinit(); + @memcpy(buffer, url_safe.slice()); var proxy_url_slice = buffer[url_zig.len..]; - @memcpy(proxy_url_slice.ptr, proxy_url_zig.ptr, proxy_url_zig.len); + var proxy_url_zig_slice = proxy_url_zig.toSlice(globalThis); + @memcpy(proxy_url_slice, proxy_url_zig_slice.slice()); url = ZigURL.parse(buffer[0..url_zig.len]); proxy = ZigURL.parse(proxy_url_slice); diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 52e023191a58c8..923689d3885cd7 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -4656,4 +4656,3 @@ pub fn NewReadyWatcher( // pub fn onError(this: *Streamer): anytype, // }; // } - diff --git a/src/exact_size_matcher.zig b/src/exact_size_matcher.zig index 5d47cee98f20b2..28d6aad56ab96a 100644 --- a/src/exact_size_matcher.zig +++ b/src/exact_size_matcher.zig @@ -19,11 +19,11 @@ pub fn ExactSizeMatcher(comptime max_bytes: usize) type { 1...max_bytes - 1 => { var tmp: [max_bytes]u8 = undefined; if (comptime std.meta.trait.isSlice(@TypeOf(str))) { - @memcpy(&tmp, str.ptr, str.len); - @memset(tmp[str.len..].ptr, 0, tmp[str.len..].len); + @memcpy(&tmp, str); + @memset(tmp[str.len..], 0); } else { - @memcpy(&tmp, str, str.len); - @memset(tmp[str.len..], 0, tmp[str.len..].len); + @memcpy(&tmp, str); + @memset(tmp[str.len..], 0); } return std.mem.readIntNative(T, &tmp); @@ -47,7 +47,7 @@ pub fn ExactSizeMatcher(comptime max_bytes: usize) type { for (str, 0..) |char, i| { tmp[i] = std.ascii.toLower(char); } - @memset(tmp[str.len..].ptr, 0, tmp[str.len..].len); + @memset(tmp[str.len..], 0); return std.mem.readIntNative(T, &tmp); }, max_bytes => { diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig index 10e1ede0c4798a..a21e2d2473842c 100644 --- a/src/io/io_linux.zig +++ b/src/io/io_linux.zig @@ -463,7 +463,7 @@ has_queued: usize = 0, wakeup_completion: Completion = undefined, fn queueForWakeup(this: *@This(), comptime Type: type, ctx: Type, comptime cb: anytype) void { - @memset(&this.eventfd_buf, 0, this.eventfd_buf.len); + @memset(&this.eventfd_buf, 0); const Callback = struct { pub fn callback(that: Type, completion: *Completion, _: ReadError!usize) void { var io = @fieldParentPtr(IO, "wakeup_completion", completion); @@ -640,7 +640,7 @@ fn flush(self: *IO, wait_nr: u32, timeouts: *usize, etime: *bool) !void { fn flush_completions(self: *IO, wait_nr: u32, timeouts: *usize, etime: *bool) !void { var cqes: [256]std.os.linux.io_uring_cqe = undefined; var completion_byttes = std.mem.asBytes(&cqes); - @memset(completion_byttes, 0, completion_byttes.len); + @memset(completion_byttes, 0); var wait_remaining = wait_nr; while (true) { // Guard against waiting indefinitely (if there are too few requests inflight), diff --git a/src/js_lexer_tables.zig b/src/js_lexer_tables.zig index dcf04573faf19b..8dacc693c8021b 100644 --- a/src/js_lexer_tables.zig +++ b/src/js_lexer_tables.zig @@ -842,4 +842,3 @@ test "tokenToString" { // expect(v == 0x223C); // } // } - diff --git a/src/sha.zig b/src/sha.zig index 64539eff00e40a..0c8074e28cd0b1 100644 --- a/src/sha.zig +++ b/src/sha.zig @@ -247,10 +247,10 @@ pub fn main() anyerror!void { var digest2: DigestType = undefined; var digest3: DigestType = undefined; var digest4: DigestType = undefined; - @memset(&digest1, 0, @sizeOf(DigestType)); - @memset(&digest2, 0, @sizeOf(DigestType)); - @memset(&digest3, 0, @sizeOf(DigestType)); - @memset(&digest4, 0, @sizeOf(DigestType)); + @memset(std.mem.asBytes(&digest1), 0); + @memset(std.mem.asBytes(&digest2), 0); + @memset(std.mem.asBytes(&digest3), 0); + @memset(std.mem.asBytes(&digest4), 0); defer { std.mem.doNotOptimizeAway(&digest1); std.mem.doNotOptimizeAway(&digest2); @@ -331,4 +331,3 @@ pub fn main() anyerror!void { // std.crypto.hash.sha2.Sha256.hash(value, &hash2, .{}); // try std.testing.expectEqual(hash, hash2); // } -