summaryrefslogtreecommitdiff
path: root/src/gui/fonts.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-08-09 10:41:33 -0300
committerGabriel Schneider <[email protected]>2026-08-10 09:17:07 -0300
commit9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a (patch)
tree91fce278abc85e4f7491de8b5f02184c8a2d5a56 /src/gui/fonts.zig
parent2b1fac6fecbf7d7cc08f9dad24687b05e9968c9a (diff)
downloadpardes-9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a.tar.gz
pardes-9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a.zip
replace ArrayLists with bounded storage
Diffstat (limited to 'src/gui/fonts.zig')
-rw-r--r--src/gui/fonts.zig16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/gui/fonts.zig b/src/gui/fonts.zig
index e21f4674..1ad7dd84 100644
--- a/src/gui/fonts.zig
+++ b/src/gui/fonts.zig
@@ -65,7 +65,8 @@ pub var want: ?[]const u8 = null;
/// four in vendor/stb/font.c plus a UTF-16BE decode, and this file is where it
/// would land.
pub fn list(arena: std.mem.Allocator, want_name: ?[]const u8) []const Font {
- var out: std.ArrayList(Font) = .empty;
+ var found: [max_fonts]Font = undefined;
+ var found_len: usize = 0;
// Zig 0.16 moved the filesystem behind std.Io; the blocking
// single-threaded implementation is the synchronous walk a sans-IO core
// wants, the same one look.find uses.
@@ -87,7 +88,7 @@ pub fn list(arena: std.mem.Allocator, want_name: ?[]const u8) []const Font {
var w = dir.walkSelectively(arena) catch continue;
defer w.deinit();
var steps: usize = 0;
- while (steps < max_steps and out.items.len < max_fonts) {
+ while (steps < max_steps and found_len < found.len) {
steps += 1; // an unreadable dir burns a step too, so it cannot spin
const e = (w.next(io) catch continue) orelse break;
if (e.kind == .directory) {
@@ -103,21 +104,22 @@ pub fn list(arena: std.mem.Allocator, want_name: ?[]const u8) []const Font {
if (want_name) |wn| {
if (!std.mem.eql(u8, wn, name)) continue;
} else if (!monospaced(path)) continue;
- out.append(arena, .{
+ found[found_len] = .{
.name = arena.dupe(u8, name) catch break,
.path = arena.dupe(u8, path) catch break,
- }) catch break;
- if (want_name != null) return out.items; // asked for one, found it
+ };
+ found_len += 1;
+ if (want_name != null) return arena.dupe(Font, found[0..found_len]) catch &.{}; // asked for one, found it
}
}
// readdir order is undefined; sort so the picker is the same list twice
// running and n/N walks a font's own variants in a row
- std.mem.sort(Font, out.items, {}, struct {
+ std.mem.sort(Font, found[0..found_len], {}, struct {
fn lt(_: void, a: Font, b: Font) bool {
return std.mem.lessThan(u8, a.name, b.name);
}
}.lt);
- return out.items;
+ return arena.dupe(Font, found[0..found_len]) catch &.{};
}
/// Is every glyph in this font the same width? The terminal grid IS a