Skip to content

Commit dc91e5b

Browse files
committed
aro: avoid BoundedArray
1 parent 6abc012 commit dc91e5b

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

lib/compiler/aro/aro/Driver/Multilib.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const std = @import("std");
22
const Filesystem = @import("Filesystem.zig").Filesystem;
33

4-
pub const Flags = std.BoundedArray([]const u8, 6);
4+
pub const Flags = std.ArrayListUnmanaged([]const u8);
55

66
/// Large enough for GCCDetector for Linux; may need to be increased to support other toolchains.
77
const max_multilibs = 4;
88

9-
const MultilibArray = std.BoundedArray(Multilib, max_multilibs);
9+
const MultilibArray = std.ArrayListUnmanaged(Multilib);
1010

1111
pub const Detected = struct {
1212
multilibs: MultilibArray = .{},
@@ -15,20 +15,20 @@ pub const Detected = struct {
1515

1616
pub fn filter(self: *Detected, multilib_filter: Filter, fs: Filesystem) void {
1717
var found_count: usize = 0;
18-
for (self.multilibs.constSlice()) |multilib| {
18+
for (self.multilibs.items) |multilib| {
1919
if (multilib_filter.exists(multilib, fs)) {
20-
self.multilibs.set(found_count, multilib);
20+
self.multilibs.items[found_count] = multilib;
2121
found_count += 1;
2222
}
2323
}
2424
self.multilibs.resize(found_count) catch unreachable;
2525
}
2626

27-
pub fn select(self: *Detected, flags: Flags) !bool {
27+
pub fn select(self: *Detected, flags: []const []const Flags) !bool {
2828
var filtered: MultilibArray = .{};
29-
for (self.multilibs.constSlice()) |multilib| {
30-
for (multilib.flags.constSlice()) |multilib_flag| {
31-
const matched = for (flags.constSlice()) |arg_flag| {
29+
for (self.multilibs.items) |multilib| {
30+
for (flags) |multilib_flag| {
31+
const matched = for (flags) |arg_flag| {
3232
if (std.mem.eql(u8, arg_flag[1..], multilib_flag[1..])) break arg_flag;
3333
} else multilib_flag;
3434
if (matched[0] != multilib_flag[0]) break;

lib/compiler/aro/aro/Toolchain.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
171171
/// TODO: this isn't exactly right since our target names don't necessarily match up
172172
/// with GCC's.
173173
/// For example the Zig target `arm-freestanding-eabi` would need the `arm-none-eabi` tools
174-
fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8) std.BoundedArray([]const u8, 2) {
175-
var possible_names: std.BoundedArray([]const u8, 2) = .{};
174+
fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8, possible_names: *std.ArrayListUnmanaged([]const u8)) void {
176175
if (raw_triple) |triple| {
177176
if (std.fmt.bufPrint(buf, "{s}-{s}", .{ triple, name })) |res| {
178177
possible_names.appendAssumeCapacity(res);
@@ -209,9 +208,11 @@ fn getProgramPath(tc: *const Toolchain, name: []const u8, buf: []u8) []const u8
209208
var fib = std.heap.FixedBufferAllocator.init(&path_buf);
210209

211210
var tool_specific_buf: [64]u8 = undefined;
212-
const possible_names = possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf);
211+
var possible_names_buffer: [2][]const u8 = undefined;
212+
var possible_names = std.ArrayListUnmanaged.initBuffer(&possible_names_buffer);
213+
possibleProgramNames(tc.driver.raw_target_triple, name, &tool_specific_buf, &possible_names);
213214

214-
for (possible_names.constSlice()) |tool_name| {
215+
for (possible_names.items) |tool_name| {
215216
for (tc.program_paths.items) |program_path| {
216217
defer fib.reset();
217218

lib/compiler/translate-c/Translator.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,8 +3439,8 @@ fn transStringLiteralInitializer(
34393439
const init_list = try t.arena.alloc(ZigNode, @intCast(num_inits));
34403440
for (init_list, 0..) |*item, i| {
34413441
const codepoint = switch (size) {
3442-
2 => @as(*const u16, @alignCast(@ptrCast(bytes.ptr + i * 2))).*,
3443-
4 => @as(*const u32, @alignCast(@ptrCast(bytes.ptr + i * 4))).*,
3442+
2 => @as(*const u16, @ptrCast(@alignCast(bytes.ptr + i * 2))).*,
3443+
4 => @as(*const u32, @ptrCast(@alignCast(bytes.ptr + i * 4))).*,
34443444
else => unreachable,
34453445
};
34463446
item.* = try t.createCharLiteralNode(false, codepoint);
@@ -3873,7 +3873,7 @@ fn createNumberNode(t: *Translator, num: anytype, num_kind: enum { int, float })
38733873

38743874
fn createCharLiteralNode(t: *Translator, narrow: bool, val: u32) TransError!ZigNode {
38753875
return ZigTag.char_literal.create(t.arena, if (narrow)
3876-
try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(&.{@as(u8, @intCast(val))})})
3876+
try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(@intCast(val))})
38773877
else
38783878
try std.fmt.allocPrint(t.arena, "'\\u{{{x}}}'", .{val}));
38793879
}

0 commit comments

Comments
 (0)