Skip to content

Commit

Permalink
leftover
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed May 13, 2023
1 parent 498005b commit 7664de7
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/bench/string-handling.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/webcore/blob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
13 changes: 8 additions & 5 deletions src/bun.js/webcore/response.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/bun.js/webcore/streams.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4656,4 +4656,3 @@ pub fn NewReadyWatcher(
// pub fn onError(this: *Streamer): anytype,
// };
// }

10 changes: 5 additions & 5 deletions src/exact_size_matcher.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions src/io/io_linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion src/js_lexer_tables.zig
Original file line number Diff line number Diff line change
Expand Up @@ -842,4 +842,3 @@ test "tokenToString" {
// expect(v == 0x223C);
// }
// }

9 changes: 4 additions & 5 deletions src/sha.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -331,4 +331,3 @@ pub fn main() anyerror!void {
// std.crypto.hash.sha2.Sha256.hash(value, &hash2, .{});
// try std.testing.expectEqual(hash, hash2);
// }

0 comments on commit 7664de7

Please sign in to comment.