mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-25 16:41:44 +00:00
terminal: clean up overzealous inlining
This commit is contained in:
@@ -498,7 +498,14 @@ pub fn printRepeat(self: *Terminal, count_req: usize) !void {
|
||||
// identical to calling print per codepoint: ineligible characters
|
||||
// or terminal states (insert mode, grapheme clustering, hyperlinks,
|
||||
// etc.) fall back to the per-codepoint print() path internally.
|
||||
var buf: [4096]u32 = @splat(c);
|
||||
//
|
||||
// The buffer is filled with a runtime-bounded loop rather than
|
||||
// `= @splat(c)`: a comptime-known 4096-element splat gets fully
|
||||
// unrolled into ~33KB of consecutive stores (LLVM won't re-roll
|
||||
// or vectorize it, see quirks_memset.zig), and it would fill the
|
||||
// whole buffer even for the typical small repeat counts.
|
||||
var buf: [4096]u32 = undefined;
|
||||
for (buf[0..@min(remaining, buf.len)]) |*cp| cp.* = c;
|
||||
while (remaining > 0) {
|
||||
const n = @min(remaining, buf.len);
|
||||
try self.printSlice(buf[0..n]);
|
||||
|
||||
@@ -1268,32 +1268,17 @@ pub const PageFormatter = struct {
|
||||
if (style_id == invalid_style_id) break :fast;
|
||||
}
|
||||
|
||||
// Specialized on point tracking so that the common
|
||||
// non-tracking case has zero per-cell overhead.
|
||||
const consumed = if (self.point_map == null)
|
||||
try self.writeCellRun(
|
||||
emit,
|
||||
false,
|
||||
writer,
|
||||
cells_subset[cell_i..],
|
||||
x,
|
||||
y,
|
||||
style_id,
|
||||
current_hyperlink_id,
|
||||
&blank_cells,
|
||||
)
|
||||
else
|
||||
try self.writeCellRun(
|
||||
emit,
|
||||
true,
|
||||
writer,
|
||||
cells_subset[cell_i..],
|
||||
x,
|
||||
y,
|
||||
style_id,
|
||||
current_hyperlink_id,
|
||||
&blank_cells,
|
||||
);
|
||||
const consumed = try self.writeCellRun(
|
||||
emit,
|
||||
self.point_map != null,
|
||||
writer,
|
||||
cells_subset[cell_i..],
|
||||
x,
|
||||
y,
|
||||
style_id,
|
||||
current_hyperlink_id,
|
||||
&blank_cells,
|
||||
);
|
||||
|
||||
// Zero cells consumed means the first cell isn't
|
||||
// eligible for the fast path; handle it below.
|
||||
@@ -1579,10 +1564,15 @@ pub const PageFormatter = struct {
|
||||
/// Blank cell accounting matches the slow path: accumulated blanks
|
||||
/// are only materialized once a non-blank cell is found, and any
|
||||
/// remainder is written back to `blank_cells`.
|
||||
fn writeCellRun(
|
||||
// Deliberately not inlined: this is instantiated per emit format and
|
||||
// inlining every copy into formatWithStateEmit's row loop bloats the
|
||||
// binary. track_points is a runtime bool for the same reason: a
|
||||
// comptime bool doubles the instantiation count for one predictable
|
||||
// branch per emitted cell.
|
||||
noinline fn writeCellRun(
|
||||
self: *const PageFormatter,
|
||||
comptime emit: Format,
|
||||
comptime track_points: bool,
|
||||
track_points: bool,
|
||||
writer: *std.Io.Writer,
|
||||
cells: []const Cell,
|
||||
run_x: size.CellCountInt,
|
||||
@@ -1666,7 +1656,7 @@ pub const PageFormatter = struct {
|
||||
|
||||
// This cell produces output: materialize accumulated blanks.
|
||||
if (pending > 0) {
|
||||
if (comptime track_points) try self.appendBlankPoints(
|
||||
if (track_points) try self.appendBlankPoints(
|
||||
&self.point_map.?,
|
||||
pending,
|
||||
x,
|
||||
@@ -1718,7 +1708,7 @@ pub const PageFormatter = struct {
|
||||
}
|
||||
|
||||
// All of the cell's bytes map to the cell's coordinate.
|
||||
if (comptime track_points) {
|
||||
if (track_points) {
|
||||
const map = &self.point_map.?;
|
||||
map.map.appendNTimes(
|
||||
map.alloc,
|
||||
|
||||
Reference in New Issue
Block a user