aboutsummaryrefslogtreecommitdiff
path: root/lib/std/segmented_list.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/segmented_list.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/segmented_list.zig')
-rw-r--r--lib/std/segmented_list.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/std/segmented_list.zig b/lib/std/segmented_list.zig
index 172fe4e7c3..1c9cffa766 100644
--- a/lib/std/segmented_list.zig
+++ b/lib/std/segmented_list.zig
@@ -107,7 +107,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
}
pub fn deinit(self: *Self, allocator: Allocator) void {
- self.freeShelves(allocator, @intCast(ShelfIndex, self.dynamic_segments.len), 0);
+ self.freeShelves(allocator, @as(ShelfIndex, @intCast(self.dynamic_segments.len)), 0);
allocator.free(self.dynamic_segments);
self.* = undefined;
}
@@ -171,7 +171,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
/// TODO update this and related methods to match the conventions set by ArrayList
pub fn setCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
if (prealloc_item_count != 0) {
- if (new_capacity <= @as(usize, 1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) {
+ if (new_capacity <= @as(usize, 1) << (prealloc_exp + @as(ShelfIndex, @intCast(self.dynamic_segments.len)))) {
return self.shrinkCapacity(allocator, new_capacity);
}
}
@@ -181,7 +181,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
/// Only grows capacity, or retains current capacity.
pub fn growCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
const new_cap_shelf_count = shelfCount(new_capacity);
- const old_shelf_count = @intCast(ShelfIndex, self.dynamic_segments.len);
+ const old_shelf_count = @as(ShelfIndex, @intCast(self.dynamic_segments.len));
if (new_cap_shelf_count <= old_shelf_count) return;
const new_dynamic_segments = try allocator.alloc([*]T, new_cap_shelf_count);
@@ -206,7 +206,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
/// It may fail to reduce the capacity in which case the capacity will remain unchanged.
pub fn shrinkCapacity(self: *Self, allocator: Allocator, new_capacity: usize) void {
if (new_capacity <= prealloc_item_count) {
- const len = @intCast(ShelfIndex, self.dynamic_segments.len);
+ const len = @as(ShelfIndex, @intCast(self.dynamic_segments.len));
self.freeShelves(allocator, len, 0);
allocator.free(self.dynamic_segments);
self.dynamic_segments = &[_][*]T{};
@@ -214,7 +214,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
}
const new_cap_shelf_count = shelfCount(new_capacity);
- const old_shelf_count = @intCast(ShelfIndex, self.dynamic_segments.len);
+ const old_shelf_count = @as(ShelfIndex, @intCast(self.dynamic_segments.len));
assert(new_cap_shelf_count <= old_shelf_count);
if (new_cap_shelf_count == old_shelf_count) return;
@@ -424,7 +424,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
{
var i: usize = 0;
while (i < 100) : (i += 1) {
- try list.append(testing.allocator, @intCast(i32, i + 1));
+ try list.append(testing.allocator, @as(i32, @intCast(i + 1)));
try testing.expect(list.len == i + 1);
}
}
@@ -432,7 +432,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
{
var i: usize = 0;
while (i < 100) : (i += 1) {
- try testing.expect(list.at(i).* == @intCast(i32, i + 1));
+ try testing.expect(list.at(i).* == @as(i32, @intCast(i + 1)));
}
}
@@ -492,7 +492,7 @@ fn testSegmentedList(comptime prealloc: usize) !void {
var i: i32 = 0;
while (i < 100) : (i += 1) {
try list.append(testing.allocator, i + 1);
- control[@intCast(usize, i)] = i + 1;
+ control[@as(usize, @intCast(i))] = i + 1;
}
@memset(dest[0..], 0);