From 18e53829093cd6654539f0b1e0be9c71c85fd7d6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 May 2024 08:55:19 -0700 Subject: [PATCH] font/coretext: do not assume capacity on arraylist append Now that we're padding the cells with blanks if we have shaped ligatures we don't actually know the exact count based on the CoreText APIs, so we should just dynamically add. --- src/font/shaper/coretext.zig | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/font/shaper/coretext.zig b/src/font/shaper/coretext.zig index b116ad933..53eb1b027 100644 --- a/src/font/shaper/coretext.zig +++ b/src/font/shaper/coretext.zig @@ -322,11 +322,6 @@ pub const Shaper = struct { advances, indices, ) |glyph, advance, index| { - try self.cell_buf.ensureUnusedCapacity( - self.alloc, - glyphs.len, - ); - // Our cluster is also our cell X position. If the cluster changes // then we need to reset our current cell offsets. const cluster = state.codepoints.items[index].cluster; @@ -341,7 +336,7 @@ pub const Shaper = struct { // If we have a gap between clusters then we need to // add empty cells to the buffer. for (cell_offset.cluster + 1..cluster) |x| { - self.cell_buf.appendAssumeCapacity(.{ + try self.cell_buf.append(self.alloc, .{ .x = @intCast(x), .glyph_index = null, }); @@ -350,7 +345,7 @@ pub const Shaper = struct { cell_offset = .{ .cluster = cluster }; } - self.cell_buf.appendAssumeCapacity(.{ + try self.cell_buf.append(self.alloc, .{ .x = @intCast(cluster), .x_offset = @intFromFloat(@round(cell_offset.x)), .y_offset = @intFromFloat(@round(cell_offset.y)), @@ -376,7 +371,7 @@ pub const Shaper = struct { // We need to go back to the last matched cluster and add // padding up to there. for (last_cell.x + 1..last_cp.cluster + 1) |x| { - self.cell_buf.appendAssumeCapacity(.{ + try self.cell_buf.append(self.alloc, .{ .x = @intCast(x), .glyph_index = null, });