aboutsummaryrefslogtreecommitdiff
path: root/lib/std/multi_array_list.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-06-22 18:46:56 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-06-24 16:56:39 -0700
commitf26dda21171e26f44aeec8c59a75bbb3331eeb2e (patch)
treec935248861ae2693b314f2c8bc78fe38d9961b6d /lib/std/multi_array_list.zig
parent447ca4e3fff021f471b748187b53f0a4744ad0bc (diff)
downloadzig-f26dda21171e26f44aeec8c59a75bbb3331eeb2e.tar.gz
zig-f26dda21171e26f44aeec8c59a75bbb3331eeb2e.zip
all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
Diffstat (limited to 'lib/std/multi_array_list.zig')
-rw-r--r--lib/std/multi_array_list.zig33
1 files changed, 16 insertions, 17 deletions
diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig
index 26ba6cc919..ffbff62da2 100644
--- a/lib/std/multi_array_list.zig
+++ b/lib/std/multi_array_list.zig
@@ -78,7 +78,7 @@ pub fn MultiArrayList(comptime T: type) type {
const casted_ptr: [*]F = if (@sizeOf(F) == 0)
undefined
else
- @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));
+ @ptrCast(@alignCast(byte_ptr));
return casted_ptr[0..self.len];
}
@@ -89,14 +89,14 @@ pub fn MultiArrayList(comptime T: type) type {
else => unreachable,
};
inline for (fields, 0..) |field_info, i| {
- self.items(@enumFromInt(Field, i))[index] = @field(e, field_info.name);
+ self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_info.name);
}
}
pub fn get(self: Slice, index: usize) T {
var result: Elem = undefined;
inline for (fields, 0..) |field_info, i| {
- @field(result, field_info.name) = self.items(@enumFromInt(Field, i))[index];
+ @field(result, field_info.name) = self.items(@as(Field, @enumFromInt(i)))[index];
}
return switch (@typeInfo(T)) {
.Struct => result,
@@ -110,10 +110,9 @@ pub fn MultiArrayList(comptime T: type) type {
return .{};
}
const unaligned_ptr = self.ptrs[sizes.fields[0]];
- const aligned_ptr = @alignCast(@alignOf(Elem), unaligned_ptr);
- const casted_ptr = @ptrCast([*]align(@alignOf(Elem)) u8, aligned_ptr);
+ const aligned_ptr: [*]align(@alignOf(Elem)) u8 = @alignCast(unaligned_ptr);
return .{
- .bytes = casted_ptr,
+ .bytes = aligned_ptr,
.len = self.len,
.capacity = self.capacity,
};
@@ -294,7 +293,7 @@ pub fn MultiArrayList(comptime T: type) type {
};
const slices = self.slice();
inline for (fields, 0..) |field_info, field_index| {
- const field_slice = slices.items(@enumFromInt(Field, field_index));
+ const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
var i: usize = self.len - 1;
while (i > index) : (i -= 1) {
field_slice[i] = field_slice[i - 1];
@@ -309,7 +308,7 @@ pub fn MultiArrayList(comptime T: type) type {
pub fn swapRemove(self: *Self, index: usize) void {
const slices = self.slice();
inline for (fields, 0..) |_, i| {
- const field_slice = slices.items(@enumFromInt(Field, i));
+ const field_slice = slices.items(@as(Field, @enumFromInt(i)));
field_slice[index] = field_slice[self.len - 1];
field_slice[self.len - 1] = undefined;
}
@@ -321,7 +320,7 @@ pub fn MultiArrayList(comptime T: type) type {
pub fn orderedRemove(self: *Self, index: usize) void {
const slices = self.slice();
inline for (fields, 0..) |_, field_index| {
- const field_slice = slices.items(@enumFromInt(Field, field_index));
+ const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
var i = index;
while (i < self.len - 1) : (i += 1) {
field_slice[i] = field_slice[i + 1];
@@ -358,7 +357,7 @@ pub fn MultiArrayList(comptime T: type) type {
const self_slice = self.slice();
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
- const field = @enumFromInt(Field, i);
+ const field = @as(Field, @enumFromInt(i));
const dest_slice = self_slice.items(field)[new_len..];
// We use memset here for more efficient codegen in safety-checked,
// valgrind-enabled builds. Otherwise the valgrind client request
@@ -379,7 +378,7 @@ pub fn MultiArrayList(comptime T: type) type {
const other_slice = other.slice();
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
- const field = @enumFromInt(Field, i);
+ const field = @as(Field, @enumFromInt(i));
@memcpy(other_slice.items(field), self_slice.items(field));
}
}
@@ -440,7 +439,7 @@ pub fn MultiArrayList(comptime T: type) type {
const other_slice = other.slice();
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
- const field = @enumFromInt(Field, i);
+ const field = @as(Field, @enumFromInt(i));
@memcpy(other_slice.items(field), self_slice.items(field));
}
}
@@ -459,7 +458,7 @@ pub fn MultiArrayList(comptime T: type) type {
const result_slice = result.slice();
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
- const field = @enumFromInt(Field, i);
+ const field = @as(Field, @enumFromInt(i));
@memcpy(result_slice.items(field), self_slice.items(field));
}
}
@@ -476,7 +475,7 @@ pub fn MultiArrayList(comptime T: type) type {
pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
- const field = @enumFromInt(Field, i);
+ const field = @as(Field, @enumFromInt(i));
const ptr = sc.slice.items(field);
mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
}
@@ -592,9 +591,9 @@ test "basic usage" {
var i: usize = 0;
while (i < 6) : (i += 1) {
try list.append(ally, .{
- .a = @intCast(u32, 4 + i),
+ .a = @as(u32, @intCast(4 + i)),
.b = "whatever",
- .c = @intCast(u8, 'd' + i),
+ .c = @as(u8, @intCast('d' + i)),
});
}
@@ -791,7 +790,7 @@ test "union" {
// Add 6 more things to force a capacity increase.
for (0..6) |i| {
- try list.append(ally, .{ .a = @intCast(u32, 4 + i) });
+ try list.append(ally, .{ .a = @as(u32, @intCast(4 + i)) });
}
try testing.expectEqualSlices(