renderer/opengl: don't append assume capacity

Fixes #1815
This commit is contained in:
Mitchell Hashimoto
2024-06-03 20:54:53 -07:00
parent 0b971f6760
commit a502089582

View File

@ -926,27 +926,9 @@ pub fn rebuildCells(
cursor_style_: ?renderer.CursorStyle, cursor_style_: ?renderer.CursorStyle,
color_palette: *const terminal.color.Palette, color_palette: *const terminal.color.Palette,
) !void { ) !void {
const rows_usize: usize = @intCast(screen.pages.rows);
const cols_usize: usize = @intCast(screen.pages.cols);
// Bg cells at most will need space for the visible screen size // Bg cells at most will need space for the visible screen size
self.cells_bg.clearRetainingCapacity(); self.cells_bg.clearRetainingCapacity();
try self.cells_bg.ensureTotalCapacity(
self.alloc,
rows_usize * cols_usize,
);
// For now, we just ensure that we have enough cells for all the lines
// we have plus a full width. This is very likely too much but its
// the probably close enough while guaranteeing no more allocations.
self.cells.clearRetainingCapacity(); self.cells.clearRetainingCapacity();
try self.cells.ensureTotalCapacity(
self.alloc,
// * 3 for glyph + underline + strikethrough for each cell
// + 1 for cursor
(rows_usize * cols_usize * 3) + 1,
);
// Create an arena for all our temporary allocations while rebuilding // Create an arena for all our temporary allocations while rebuilding
var arena = ArenaAllocator.init(self.alloc); var arena = ArenaAllocator.init(self.alloc);
@ -1129,7 +1111,7 @@ pub fn rebuildCells(
break :cursor_style; break :cursor_style;
} }
_ = self.addCursor(screen, cursor_style); _ = try self.addCursor(screen, cursor_style);
if (cursor_cell) |*cell| { if (cursor_cell) |*cell| {
if (cell.mode == .fg) { if (cell.mode == .fg) {
if (self.config.cursor_text) |txt| { if (self.config.cursor_text) |txt| {
@ -1144,7 +1126,7 @@ pub fn rebuildCells(
cell.a = 255; cell.a = 255;
} }
} }
self.cells.appendAssumeCapacity(cell.*); try self.cells.append(self.alloc, cell.*);
} }
} }
@ -1182,7 +1164,7 @@ fn addPreeditCell(
}; };
// Add our opaque background cell // Add our opaque background cell
self.cells_bg.appendAssumeCapacity(.{ try self.cells_bg.append(self.alloc, .{
.mode = .bg, .mode = .bg,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(y), .grid_row = @intCast(y),
@ -1204,7 +1186,7 @@ fn addPreeditCell(
}); });
// Add our text // Add our text
self.cells.appendAssumeCapacity(.{ try self.cells.append(self.alloc, .{
.mode = .fg, .mode = .fg,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(y), .grid_row = @intCast(y),
@ -1230,7 +1212,7 @@ fn addCursor(
self: *OpenGL, self: *OpenGL,
screen: *terminal.Screen, screen: *terminal.Screen,
cursor_style: renderer.CursorStyle, cursor_style: renderer.CursorStyle,
) ?*const CellProgram.Cell { ) !?*const CellProgram.Cell {
// Add the cursor. We render the cursor over the wide character if // Add the cursor. We render the cursor over the wide character if
// we're on the wide characer tail. // we're on the wide characer tail.
const wide, const x = cell: { const wide, const x = cell: {
@ -1271,7 +1253,7 @@ fn addCursor(
return null; return null;
}; };
self.cells.appendAssumeCapacity(.{ try self.cells.append(self.alloc, .{
.mode = .fg, .mode = .fg,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(screen.cursor.y), .grid_row = @intCast(screen.cursor.y),
@ -1406,7 +1388,7 @@ fn updateCell(
break :bg_alpha @intFromFloat(bg_alpha); break :bg_alpha @intFromFloat(bg_alpha);
}; };
self.cells_bg.appendAssumeCapacity(.{ try self.cells_bg.append(self.alloc, .{
.mode = .bg, .mode = .bg,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(y), .grid_row = @intCast(y),
@ -1458,7 +1440,7 @@ fn updateCell(
.constrained => .fg_constrained, .constrained => .fg_constrained,
}; };
self.cells.appendAssumeCapacity(.{ try self.cells.append(self.alloc, .{
.mode = mode, .mode = mode,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(y), .grid_row = @intCast(y),
@ -1502,7 +1484,7 @@ fn updateCell(
const color = style.underlineColor(palette) orelse colors.fg; const color = style.underlineColor(palette) orelse colors.fg;
self.cells.appendAssumeCapacity(.{ try self.cells.append(self.alloc, .{
.mode = .fg, .mode = .fg,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(y), .grid_row = @intCast(y),
@ -1535,7 +1517,7 @@ fn updateCell(
}, },
); );
self.cells.appendAssumeCapacity(.{ try self.cells.append(self.alloc, .{
.mode = .fg, .mode = .fg,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(y), .grid_row = @intCast(y),