refactor: Migrar ArrayList a ArrayListUnmanaged (Zig 0.15)

Archivos actualizados:
- async_loop.zig: timers
- diagnostic.zig: format()
- sixel.zig: encode(), encodeSixelRow()
- filepicker.zig: FileEntry.children
- textarea.zig: lines (ArrayList de ArrayList)

Cambio de API:
- std.ArrayList(T).init(alloc) → std.ArrayListUnmanaged(T) = .{}
- list.append(item) → list.append(alloc, item)
- list.deinit() → list.deinit(alloc)
- list.writer() → list.writer(alloc)
- list.toOwnedSlice() → list.toOwnedSlice(alloc)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
R.Eugenio 2025-12-23 01:39:41 +01:00
parent c4e1c97ec1
commit 2d95f0e28b
5 changed files with 41 additions and 41 deletions

View file

@ -77,7 +77,7 @@ const TimerEntry = struct {
pub const AsyncLoop = struct { pub const AsyncLoop = struct {
epoll_fd: std.posix.fd_t, epoll_fd: std.posix.fd_t,
events: [MAX_EVENTS]std.os.linux.epoll_event = undefined, events: [MAX_EVENTS]std.os.linux.epoll_event = undefined,
timers: std.ArrayList(TimerEntry), timers: std.ArrayListUnmanaged(TimerEntry) = .{},
next_timer_id: u32 = 1, next_timer_id: u32 = 1,
stdin_added: bool = false, stdin_added: bool = false,
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
@ -87,7 +87,6 @@ pub const AsyncLoop = struct {
const epoll_fd = try std.posix.epoll_create1(.{ .CLOEXEC = true }); const epoll_fd = try std.posix.epoll_create1(.{ .CLOEXEC = true });
return .{ return .{
.epoll_fd = epoll_fd, .epoll_fd = epoll_fd,
.timers = std.ArrayList(TimerEntry).init(allocator),
.allocator = allocator, .allocator = allocator,
}; };
} }
@ -98,7 +97,7 @@ pub const AsyncLoop = struct {
for (self.timers.items) |timer| { for (self.timers.items) |timer| {
std.posix.close(timer.fd); std.posix.close(timer.fd);
} }
self.timers.deinit(); self.timers.deinit(self.allocator);
std.posix.close(self.epoll_fd); std.posix.close(self.epoll_fd);
} }
@ -169,7 +168,7 @@ pub const AsyncLoop = struct {
try std.posix.epoll_ctl(self.epoll_fd, .ADD, timer_fd, &ev); try std.posix.epoll_ctl(self.epoll_fd, .ADD, timer_fd, &ev);
try self.timers.append(.{ try self.timers.append(self.allocator, .{
.id = timer_id, .id = timer_id,
.fd = timer_fd, .fd = timer_fd,
.interval_ms = interval_ms, .interval_ms = interval_ms,

View file

@ -131,8 +131,8 @@ pub const Diagnostic = struct {
/// Formats the diagnostic as a string. /// Formats the diagnostic as a string.
pub fn format(self: *const Diagnostic, allocator: std.mem.Allocator) ![]u8 { pub fn format(self: *const Diagnostic, allocator: std.mem.Allocator) ![]u8 {
var result = std.ArrayList(u8).init(allocator); var result: std.ArrayListUnmanaged(u8) = .{};
const writer = result.writer(); const writer = result.writer(allocator);
// Header line with title // Header line with title
try writer.writeAll("── "); try writer.writeAll("── ");
@ -188,7 +188,7 @@ pub const Diagnostic = struct {
try writer.writeAll("\n"); try writer.writeAll("\n");
} }
return result.toOwnedSlice(); return result.toOwnedSlice(allocator);
} }
/// Renders the diagnostic to a buffer. /// Renders the diagnostic to a buffer.

View file

@ -99,10 +99,10 @@ pub const SixelEncoder = struct {
/// Encodes pixels to Sixel format. /// Encodes pixels to Sixel format.
pub fn encode(self: *SixelEncoder, pixels: []const Pixel, width: usize, height: usize) ![]u8 { pub fn encode(self: *SixelEncoder, pixels: []const Pixel, width: usize, height: usize) ![]u8 {
var result = std.ArrayList(u8).init(self.allocator); var result: std.ArrayListUnmanaged(u8) = .{};
errdefer result.deinit(); errdefer result.deinit(self.allocator);
const writer = result.writer(); const writer = result.writer(self.allocator);
// Sixel start sequence: ESC P q // Sixel start sequence: ESC P q
try writer.writeAll("\x1bPq"); try writer.writeAll("\x1bPq");
@ -129,7 +129,7 @@ pub const SixelEncoder = struct {
// Sixel end sequence: ESC \ // Sixel end sequence: ESC \
try writer.writeAll("\x1b\\"); try writer.writeAll("\x1b\\");
return result.toOwnedSlice(); return result.toOwnedSlice(self.allocator);
} }
fn writePalette(self: *SixelEncoder, writer: anytype) !void { fn writePalette(self: *SixelEncoder, writer: anytype) !void {
@ -170,9 +170,9 @@ pub const SixelEncoder = struct {
var run_char: u8 = 0; var run_char: u8 = 0;
// Select color // Select color
var color_data = std.ArrayList(u8).init(self.allocator); var color_data: std.ArrayListUnmanaged(u8) = .{};
defer color_data.deinit(); defer color_data.deinit(self.allocator);
const color_writer = color_data.writer(); const color_writer = color_data.writer(self.allocator);
for (0..width) |x| { for (0..width) |x| {
var sixel_bits: u8 = 0; var sixel_bits: u8 = 0;

View file

@ -65,7 +65,7 @@ pub const FileEntry = struct {
expanded: bool = false, expanded: bool = false,
/// Child entries (loaded lazily for directories). /// Child entries (loaded lazily for directories).
children: std.ArrayList(FileEntry), children: std.ArrayListUnmanaged(FileEntry) = .{},
/// Whether children have been loaded. /// Whether children have been loaded.
children_loaded: bool = false, children_loaded: bool = false,
@ -79,7 +79,6 @@ pub const FileEntry = struct {
.name = try allocator.dupe(u8, name), .name = try allocator.dupe(u8, name),
.path = try allocator.dupe(u8, path), .path = try allocator.dupe(u8, path),
.file_type = file_type, .file_type = file_type,
.children = std.ArrayList(FileEntry).init(allocator),
.allocator = allocator, .allocator = allocator,
}; };
} }
@ -89,7 +88,7 @@ pub const FileEntry = struct {
for (self.children.items) |*child| { for (self.children.items) |*child| {
child.deinit(); child.deinit();
} }
self.children.deinit(); self.children.deinit(self.allocator);
self.allocator.free(self.name); self.allocator.free(self.name);
self.allocator.free(self.path); self.allocator.free(self.path);
} }
@ -128,7 +127,7 @@ pub const FileEntry = struct {
} else |_| {} } else |_| {}
} }
try self.children.append(child); try self.children.append(self.allocator, child);
} }
// Sort: directories first, then alphabetically // Sort: directories first, then alphabetically

View file

@ -37,7 +37,7 @@ const Borders = block_mod.Borders;
/// A multi-line text input widget. /// A multi-line text input widget.
pub const TextArea = struct { pub const TextArea = struct {
/// Lines of text. /// Lines of text.
lines: std.ArrayList(std.ArrayList(u8)), lines: std.ArrayListUnmanaged(std.ArrayListUnmanaged(u8)) = .{},
/// Cursor position (line, column). /// Cursor position (line, column).
cursor_line: usize = 0, cursor_line: usize = 0,
@ -89,20 +89,20 @@ pub const TextArea = struct {
/// Creates a new text area. /// Creates a new text area.
pub fn init(allocator: Allocator) !TextArea { pub fn init(allocator: Allocator) !TextArea {
var ta = TextArea{ var ta = TextArea{
.lines = std.ArrayList(std.ArrayList(u8)).init(allocator),
.allocator = allocator, .allocator = allocator,
}; };
// Start with one empty line // Start with one empty line
try ta.lines.append(std.ArrayList(u8).init(allocator)); const empty_line: std.ArrayListUnmanaged(u8) = .{};
try ta.lines.append(allocator, empty_line);
return ta; return ta;
} }
/// Frees resources. /// Frees resources.
pub fn deinit(self: *TextArea) void { pub fn deinit(self: *TextArea) void {
for (self.lines.items) |*line| { for (self.lines.items) |*line| {
line.deinit(); line.deinit(self.allocator);
} }
self.lines.deinit(); self.lines.deinit(self.allocator);
} }
/// Sets placeholder text. /// Sets placeholder text.
@ -160,21 +160,22 @@ pub const TextArea = struct {
pub fn setText(self: *TextArea, text: []const u8) !void { pub fn setText(self: *TextArea, text: []const u8) !void {
// Clear existing // Clear existing
for (self.lines.items) |*line| { for (self.lines.items) |*line| {
line.deinit(); line.deinit(self.allocator);
} }
self.lines.clearRetainingCapacity(); self.lines.clearRetainingCapacity();
// Parse lines // Parse lines
var iter = std.mem.splitScalar(u8, text, '\n'); var iter = std.mem.splitScalar(u8, text, '\n');
while (iter.next()) |line_text| { while (iter.next()) |line_text| {
var line = std.ArrayList(u8).init(self.allocator); var line: std.ArrayListUnmanaged(u8) = .{};
try line.appendSlice(line_text); try line.appendSlice(self.allocator, line_text);
try self.lines.append(line); try self.lines.append(self.allocator, line);
} }
// Ensure at least one line // Ensure at least one line
if (self.lines.items.len == 0) { if (self.lines.items.len == 0) {
try self.lines.append(std.ArrayList(u8).init(self.allocator)); const empty_line: std.ArrayListUnmanaged(u8) = .{};
try self.lines.append(self.allocator, empty_line);
} }
// Reset cursor // Reset cursor
@ -187,10 +188,11 @@ pub const TextArea = struct {
/// Clears all text. /// Clears all text.
pub fn clear(self: *TextArea) !void { pub fn clear(self: *TextArea) !void {
for (self.lines.items) |*line| { for (self.lines.items) |*line| {
line.deinit(); line.deinit(self.allocator);
} }
self.lines.clearRetainingCapacity(); self.lines.clearRetainingCapacity();
try self.lines.append(std.ArrayList(u8).init(self.allocator)); const empty_line: std.ArrayListUnmanaged(u8) = .{};
try self.lines.append(self.allocator, empty_line);
self.cursor_line = 0; self.cursor_line = 0;
self.cursor_col = 0; self.cursor_col = 0;
} }
@ -211,13 +213,13 @@ pub const TextArea = struct {
const spaces = self.tab_width - @as(u8, @intCast(self.cursor_col % self.tab_width)); const spaces = self.tab_width - @as(u8, @intCast(self.cursor_col % self.tab_width));
var i: u8 = 0; var i: u8 = 0;
while (i < spaces) : (i += 1) { while (i < spaces) : (i += 1) {
try line.insert(self.cursor_col, ' '); try line.insert(self.allocator, self.cursor_col, ' ');
self.cursor_col += 1; self.cursor_col += 1;
} }
return; return;
} }
try line.insert(self.cursor_col, c); try line.insert(self.allocator, self.cursor_col, c);
self.cursor_col += 1; self.cursor_col += 1;
} }
@ -233,14 +235,14 @@ pub const TextArea = struct {
var current_line = &self.lines.items[self.cursor_line]; var current_line = &self.lines.items[self.cursor_line];
// Create new line with text after cursor // Create new line with text after cursor
var new_line = std.ArrayList(u8).init(self.allocator); var new_line: std.ArrayListUnmanaged(u8) = .{};
if (self.cursor_col < current_line.items.len) { if (self.cursor_col < current_line.items.len) {
try new_line.appendSlice(current_line.items[self.cursor_col..]); try new_line.appendSlice(self.allocator, current_line.items[self.cursor_col..]);
current_line.shrinkRetainingCapacity(self.cursor_col); current_line.shrinkRetainingCapacity(self.cursor_col);
} }
// Insert new line // Insert new line
try self.lines.insert(self.cursor_line + 1, new_line); try self.lines.insert(self.allocator, self.cursor_line + 1, new_line);
// Move cursor // Move cursor
self.cursor_line += 1; self.cursor_line += 1;
@ -257,11 +259,11 @@ pub const TextArea = struct {
self.cursor_col -= 1; self.cursor_col -= 1;
} else if (self.cursor_line > 0) { } else if (self.cursor_line > 0) {
// Merge with previous line // Merge with previous line
const current_line = self.lines.orderedRemove(self.cursor_line); var current_line = self.lines.orderedRemove(self.cursor_line);
self.cursor_line -= 1; self.cursor_line -= 1;
self.cursor_col = self.lines.items[self.cursor_line].items.len; self.cursor_col = self.lines.items[self.cursor_line].items.len;
self.lines.items[self.cursor_line].appendSlice(current_line.items) catch {}; self.lines.items[self.cursor_line].appendSlice(self.allocator, current_line.items) catch {};
@constCast(&current_line).deinit(); current_line.deinit(self.allocator);
} }
} }
@ -275,9 +277,9 @@ pub const TextArea = struct {
_ = line.orderedRemove(self.cursor_col); _ = line.orderedRemove(self.cursor_col);
} else if (self.cursor_line < self.lines.items.len - 1) { } else if (self.cursor_line < self.lines.items.len - 1) {
// Merge with next line // Merge with next line
const next_line = self.lines.orderedRemove(self.cursor_line + 1); var next_line = self.lines.orderedRemove(self.cursor_line + 1);
line.appendSlice(next_line.items) catch {}; line.appendSlice(self.allocator, next_line.items) catch {};
@constCast(&next_line).deinit(); next_line.deinit(self.allocator);
} }
} }