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:
parent
c4e1c97ec1
commit
2d95f0e28b
5 changed files with 41 additions and 41 deletions
|
|
@ -77,7 +77,7 @@ const TimerEntry = struct {
|
|||
pub const AsyncLoop = struct {
|
||||
epoll_fd: std.posix.fd_t,
|
||||
events: [MAX_EVENTS]std.os.linux.epoll_event = undefined,
|
||||
timers: std.ArrayList(TimerEntry),
|
||||
timers: std.ArrayListUnmanaged(TimerEntry) = .{},
|
||||
next_timer_id: u32 = 1,
|
||||
stdin_added: bool = false,
|
||||
allocator: std.mem.Allocator,
|
||||
|
|
@ -87,7 +87,6 @@ pub const AsyncLoop = struct {
|
|||
const epoll_fd = try std.posix.epoll_create1(.{ .CLOEXEC = true });
|
||||
return .{
|
||||
.epoll_fd = epoll_fd,
|
||||
.timers = std.ArrayList(TimerEntry).init(allocator),
|
||||
.allocator = allocator,
|
||||
};
|
||||
}
|
||||
|
|
@ -98,7 +97,7 @@ pub const AsyncLoop = struct {
|
|||
for (self.timers.items) |timer| {
|
||||
std.posix.close(timer.fd);
|
||||
}
|
||||
self.timers.deinit();
|
||||
self.timers.deinit(self.allocator);
|
||||
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 self.timers.append(.{
|
||||
try self.timers.append(self.allocator, .{
|
||||
.id = timer_id,
|
||||
.fd = timer_fd,
|
||||
.interval_ms = interval_ms,
|
||||
|
|
|
|||
|
|
@ -131,8 +131,8 @@ pub const Diagnostic = struct {
|
|||
|
||||
/// Formats the diagnostic as a string.
|
||||
pub fn format(self: *const Diagnostic, allocator: std.mem.Allocator) ![]u8 {
|
||||
var result = std.ArrayList(u8).init(allocator);
|
||||
const writer = result.writer();
|
||||
var result: std.ArrayListUnmanaged(u8) = .{};
|
||||
const writer = result.writer(allocator);
|
||||
|
||||
// Header line with title
|
||||
try writer.writeAll("── ");
|
||||
|
|
@ -188,7 +188,7 @@ pub const Diagnostic = struct {
|
|||
try writer.writeAll("\n");
|
||||
}
|
||||
|
||||
return result.toOwnedSlice();
|
||||
return result.toOwnedSlice(allocator);
|
||||
}
|
||||
|
||||
/// Renders the diagnostic to a buffer.
|
||||
|
|
|
|||
|
|
@ -99,10 +99,10 @@ pub const SixelEncoder = struct {
|
|||
|
||||
/// Encodes pixels to Sixel format.
|
||||
pub fn encode(self: *SixelEncoder, pixels: []const Pixel, width: usize, height: usize) ![]u8 {
|
||||
var result = std.ArrayList(u8).init(self.allocator);
|
||||
errdefer result.deinit();
|
||||
var result: std.ArrayListUnmanaged(u8) = .{};
|
||||
errdefer result.deinit(self.allocator);
|
||||
|
||||
const writer = result.writer();
|
||||
const writer = result.writer(self.allocator);
|
||||
|
||||
// Sixel start sequence: ESC P q
|
||||
try writer.writeAll("\x1bPq");
|
||||
|
|
@ -129,7 +129,7 @@ pub const SixelEncoder = struct {
|
|||
// Sixel end sequence: ESC \
|
||||
try writer.writeAll("\x1b\\");
|
||||
|
||||
return result.toOwnedSlice();
|
||||
return result.toOwnedSlice(self.allocator);
|
||||
}
|
||||
|
||||
fn writePalette(self: *SixelEncoder, writer: anytype) !void {
|
||||
|
|
@ -170,9 +170,9 @@ pub const SixelEncoder = struct {
|
|||
var run_char: u8 = 0;
|
||||
|
||||
// Select color
|
||||
var color_data = std.ArrayList(u8).init(self.allocator);
|
||||
defer color_data.deinit();
|
||||
const color_writer = color_data.writer();
|
||||
var color_data: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer color_data.deinit(self.allocator);
|
||||
const color_writer = color_data.writer(self.allocator);
|
||||
|
||||
for (0..width) |x| {
|
||||
var sixel_bits: u8 = 0;
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ pub const FileEntry = struct {
|
|||
expanded: bool = false,
|
||||
|
||||
/// Child entries (loaded lazily for directories).
|
||||
children: std.ArrayList(FileEntry),
|
||||
children: std.ArrayListUnmanaged(FileEntry) = .{},
|
||||
|
||||
/// Whether children have been loaded.
|
||||
children_loaded: bool = false,
|
||||
|
|
@ -79,7 +79,6 @@ pub const FileEntry = struct {
|
|||
.name = try allocator.dupe(u8, name),
|
||||
.path = try allocator.dupe(u8, path),
|
||||
.file_type = file_type,
|
||||
.children = std.ArrayList(FileEntry).init(allocator),
|
||||
.allocator = allocator,
|
||||
};
|
||||
}
|
||||
|
|
@ -89,7 +88,7 @@ pub const FileEntry = struct {
|
|||
for (self.children.items) |*child| {
|
||||
child.deinit();
|
||||
}
|
||||
self.children.deinit();
|
||||
self.children.deinit(self.allocator);
|
||||
self.allocator.free(self.name);
|
||||
self.allocator.free(self.path);
|
||||
}
|
||||
|
|
@ -128,7 +127,7 @@ pub const FileEntry = struct {
|
|||
} else |_| {}
|
||||
}
|
||||
|
||||
try self.children.append(child);
|
||||
try self.children.append(self.allocator, child);
|
||||
}
|
||||
|
||||
// Sort: directories first, then alphabetically
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ const Borders = block_mod.Borders;
|
|||
/// A multi-line text input widget.
|
||||
pub const TextArea = struct {
|
||||
/// Lines of text.
|
||||
lines: std.ArrayList(std.ArrayList(u8)),
|
||||
lines: std.ArrayListUnmanaged(std.ArrayListUnmanaged(u8)) = .{},
|
||||
|
||||
/// Cursor position (line, column).
|
||||
cursor_line: usize = 0,
|
||||
|
|
@ -89,20 +89,20 @@ pub const TextArea = struct {
|
|||
/// Creates a new text area.
|
||||
pub fn init(allocator: Allocator) !TextArea {
|
||||
var ta = TextArea{
|
||||
.lines = std.ArrayList(std.ArrayList(u8)).init(allocator),
|
||||
.allocator = allocator,
|
||||
};
|
||||
// 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;
|
||||
}
|
||||
|
||||
/// Frees resources.
|
||||
pub fn deinit(self: *TextArea) void {
|
||||
for (self.lines.items) |*line| {
|
||||
line.deinit();
|
||||
line.deinit(self.allocator);
|
||||
}
|
||||
self.lines.deinit();
|
||||
self.lines.deinit(self.allocator);
|
||||
}
|
||||
|
||||
/// Sets placeholder text.
|
||||
|
|
@ -160,21 +160,22 @@ pub const TextArea = struct {
|
|||
pub fn setText(self: *TextArea, text: []const u8) !void {
|
||||
// Clear existing
|
||||
for (self.lines.items) |*line| {
|
||||
line.deinit();
|
||||
line.deinit(self.allocator);
|
||||
}
|
||||
self.lines.clearRetainingCapacity();
|
||||
|
||||
// Parse lines
|
||||
var iter = std.mem.splitScalar(u8, text, '\n');
|
||||
while (iter.next()) |line_text| {
|
||||
var line = std.ArrayList(u8).init(self.allocator);
|
||||
try line.appendSlice(line_text);
|
||||
try self.lines.append(line);
|
||||
var line: std.ArrayListUnmanaged(u8) = .{};
|
||||
try line.appendSlice(self.allocator, line_text);
|
||||
try self.lines.append(self.allocator, line);
|
||||
}
|
||||
|
||||
// Ensure at least one line
|
||||
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
|
||||
|
|
@ -187,10 +188,11 @@ pub const TextArea = struct {
|
|||
/// Clears all text.
|
||||
pub fn clear(self: *TextArea) !void {
|
||||
for (self.lines.items) |*line| {
|
||||
line.deinit();
|
||||
line.deinit(self.allocator);
|
||||
}
|
||||
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_col = 0;
|
||||
}
|
||||
|
|
@ -211,13 +213,13 @@ pub const TextArea = struct {
|
|||
const spaces = self.tab_width - @as(u8, @intCast(self.cursor_col % self.tab_width));
|
||||
var i: u8 = 0;
|
||||
while (i < spaces) : (i += 1) {
|
||||
try line.insert(self.cursor_col, ' ');
|
||||
try line.insert(self.allocator, self.cursor_col, ' ');
|
||||
self.cursor_col += 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try line.insert(self.cursor_col, c);
|
||||
try line.insert(self.allocator, self.cursor_col, c);
|
||||
self.cursor_col += 1;
|
||||
}
|
||||
|
||||
|
|
@ -233,14 +235,14 @@ pub const TextArea = struct {
|
|||
var current_line = &self.lines.items[self.cursor_line];
|
||||
|
||||
// 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
// 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
|
||||
self.cursor_line += 1;
|
||||
|
|
@ -257,11 +259,11 @@ pub const TextArea = struct {
|
|||
self.cursor_col -= 1;
|
||||
} else if (self.cursor_line > 0) {
|
||||
// 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_col = self.lines.items[self.cursor_line].items.len;
|
||||
self.lines.items[self.cursor_line].appendSlice(current_line.items) catch {};
|
||||
@constCast(¤t_line).deinit();
|
||||
self.lines.items[self.cursor_line].appendSlice(self.allocator, current_line.items) catch {};
|
||||
current_line.deinit(self.allocator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -275,9 +277,9 @@ pub const TextArea = struct {
|
|||
_ = line.orderedRemove(self.cursor_col);
|
||||
} else if (self.cursor_line < self.lines.items.len - 1) {
|
||||
// Merge with next line
|
||||
const next_line = self.lines.orderedRemove(self.cursor_line + 1);
|
||||
line.appendSlice(next_line.items) catch {};
|
||||
@constCast(&next_line).deinit();
|
||||
var next_line = self.lines.orderedRemove(self.cursor_line + 1);
|
||||
line.appendSlice(self.allocator, next_line.items) catch {};
|
||||
next_line.deinit(self.allocator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue