aboutsummaryrefslogtreecommitdiff
path: root/lib/std/packed_int_array.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-06-24 16:58:19 -0700
committerGitHub <noreply@github.com>2023-06-24 16:58:19 -0700
commit146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch)
tree67e3db8b444d65c667e314770fc983a7fc8ba293 /lib/std/packed_int_array.zig
parent13853bef0df3c90633021850cc6d6abaeea03282 (diff)
parent21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff)
downloadzig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz
zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'lib/std/packed_int_array.zig')
-rw-r--r--lib/std/packed_int_array.zig32
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/std/packed_int_array.zig b/lib/std/packed_int_array.zig
index 10d8af0575..cff9eb8cf1 100644
--- a/lib/std/packed_int_array.zig
+++ b/lib/std/packed_int_array.zig
@@ -73,25 +73,25 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
//read bytes as container
- const value_ptr = @ptrCast(*align(1) const Container, &bytes[start_byte]);
+ const value_ptr = @as(*align(1) const Container, @ptrCast(&bytes[start_byte]));
var value = value_ptr.*;
if (endian != native_endian) value = @byteSwap(value);
switch (endian) {
.Big => {
- value <<= @intCast(Shift, head_keep_bits);
- value >>= @intCast(Shift, head_keep_bits);
- value >>= @intCast(Shift, tail_keep_bits);
+ value <<= @as(Shift, @intCast(head_keep_bits));
+ value >>= @as(Shift, @intCast(head_keep_bits));
+ value >>= @as(Shift, @intCast(tail_keep_bits));
},
.Little => {
- value <<= @intCast(Shift, tail_keep_bits);
- value >>= @intCast(Shift, tail_keep_bits);
- value >>= @intCast(Shift, head_keep_bits);
+ value <<= @as(Shift, @intCast(tail_keep_bits));
+ value >>= @as(Shift, @intCast(tail_keep_bits));
+ value >>= @as(Shift, @intCast(head_keep_bits));
},
}
- return @bitCast(Int, @truncate(UnInt, value));
+ return @as(Int, @bitCast(@as(UnInt, @truncate(value))));
}
/// Sets the integer at `index` to `val` within the packed data beginning
@@ -115,21 +115,21 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
const head_keep_bits = bit_index - (start_byte * 8);
const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
const keep_shift = switch (endian) {
- .Big => @intCast(Shift, tail_keep_bits),
- .Little => @intCast(Shift, head_keep_bits),
+ .Big => @as(Shift, @intCast(tail_keep_bits)),
+ .Little => @as(Shift, @intCast(head_keep_bits)),
};
//position the bits where they need to be in the container
- const value = @intCast(Container, @bitCast(UnInt, int)) << keep_shift;
+ const value = @as(Container, @intCast(@as(UnInt, @bitCast(int)))) << keep_shift;
//read existing bytes
- const target_ptr = @ptrCast(*align(1) Container, &bytes[start_byte]);
+ const target_ptr = @as(*align(1) Container, @ptrCast(&bytes[start_byte]));
var target = target_ptr.*;
if (endian != native_endian) target = @byteSwap(target);
//zero the bits we want to replace in the existing bytes
- const inv_mask = @intCast(Container, std.math.maxInt(UnInt)) << keep_shift;
+ const inv_mask = @as(Container, @intCast(std.math.maxInt(UnInt))) << keep_shift;
const mask = ~inv_mask;
target &= mask;
@@ -156,7 +156,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
if (length == 0) return PackedIntSliceEndian(Int, endian).init(new_bytes[0..0], 0);
var new_slice = PackedIntSliceEndian(Int, endian).init(new_bytes, length);
- new_slice.bit_offset = @intCast(u3, (bit_index - (start_byte * 8)));
+ new_slice.bit_offset = @as(u3, @intCast((bit_index - (start_byte * 8))));
return new_slice;
}
@@ -398,7 +398,7 @@ test "PackedIntArray init" {
const PackedArray = PackedIntArray(u3, 8);
var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
var i = @as(usize, 0);
- while (i < packed_array.len) : (i += 1) try testing.expectEqual(@intCast(u3, i), packed_array.get(i));
+ while (i < packed_array.len) : (i += 1) try testing.expectEqual(@as(u3, @intCast(i)), packed_array.get(i));
}
test "PackedIntArray initAllTo" {
@@ -469,7 +469,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
var i = @as(usize, 0);
while (i < packed_array.len) : (i += 1) {
- packed_array.set(i, @intCast(Int, i % limit));
+ packed_array.set(i, @as(Int, @intCast(i % limit)));
}
//slice of array