Skip to content

Commit cb353a6

Browse files
sjorsdonkersmookums
authored andcommitted
avoid explicit memcpy
1 parent 2a9f31f commit cb353a6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/runtime/js.zig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,17 +1131,14 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
11311131
else => {},
11321132
},
11331133
.array => |arr| {
1134-
// Retrieve fixed-size array as slice then copy it
1134+
// Retrieve fixed-size array as slice
11351135
const slice_type = []arr.child;
11361136
const slice_value = try self.jsValueToZig(named_function, slice_type, js_value);
11371137
if (slice_value.len != arr.len) {
11381138
// Exact length match, we could allow smaller arrays, but we would not be able to communicate how many were written
11391139
return error.InvalidArgument;
11401140
}
1141-
1142-
var result: T = undefined;
1143-
@memcpy(&result, slice_value[0..arr.len]);
1144-
return result;
1141+
return @as(*T, @ptrCast(slice_value.ptr)).*;
11451142
},
11461143
.@"struct" => {
11471144
return try (self.jsValueToStruct(named_function, T, js_value)) orelse {

0 commit comments

Comments
 (0)