diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 14:46:44 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 14:46:44 +0300 |
| commit | 1e69599900a753e2d7275d7ba714202b7d9c843e (patch) | |
| tree | 13416f651319145aa5dbdd85b9947bec4858b366 /src/hist.h | |
| parent | 5ab6b560e8528c27ba934b90f94b1828b7771e27 (diff) | |
Eliminate pen style and history stream parameter smuggling
- Introduce struct text_pen bundling (fg, bg, sl) across screen and core
- Reduce text_append from 9 to 7 parameters
- Reduce text_commit from 8 to 6 parameters
- Reduce hist_runs_add_pen from 5 to 3 parameters
- Reduce sc_text_ascii and sc_ascii_fast from 6 to 4 parameters
- Remove unused fg, bg parameters from mark_row_blank
- Introduce struct hist_stream_state in src/hist.c, reducing stream_lines from 9 to 5 params and lf_rows from 10 to 6 params
- Introduce struct hist_view_pos in src/hist_view.h, reducing term_hist_view_row_pos from 9 to 7 params
Diffstat (limited to 'src/hist.h')
| -rw-r--r-- | src/hist.h | 39 |
1 files changed, 11 insertions, 28 deletions
@@ -91,31 +91,14 @@ struct text_row { #define TEXT_ROW_BYTES(cols) ((size_t)(cols) * 4 + 16) #define TEXT_ROW_RUNS(cols) (((size_t)(cols) + 2) * 22) -/* A pen as three words: fg, bg, and flags | link << 16 (the layout of - * pen_attr.flags and .link). The hot path reads and writes whole words, so - * a store is never read back through a wider load. */ -static inline uint32_t pen_sl(const struct pen_attr *p) -{ - uint32_t sl; - memcpy(&sl, &p->flags, 4); - return sl; -} - -static inline void pen_set(struct pen_attr *p, uint32_t fg, uint32_t bg, uint32_t sl) -{ - p->fg = fg; - p->bg = bg; - memcpy(&p->flags, &sl, 4); -} - /* Emit the pending run in the general form. */ void term_hist_runs_emit_slow(struct hist_runs *r); -/* Close the pending run and start one with the pen fg, bg, sl. The caller +/* Close the pending run and start one with the given pen. The caller * sized the buffer. A run that changes only colors and covers fewer than * 128 cells is a header byte (bit 0 fg, bit 1 bg), a count byte, and the * changed colors. */ -static inline void hist_runs_switch(struct hist_runs *r, uint32_t fg, uint32_t bg, uint32_t sl) +static inline void hist_runs_switch(struct hist_runs *r, struct text_pen pen) { if (r->count) { uint32_t psl = pen_sl(&r->pen); @@ -133,21 +116,21 @@ static inline void hist_runs_switch(struct hist_runs *r, uint32_t fg, uint32_t b } pen_set(&r->base, r->pen.fg, r->pen.bg, psl); } - pen_set(&r->pen, fg, bg, sl); + pen_set_text(&r->pen, pen); r->count = 0; } -static inline void hist_runs_add_pen(struct hist_runs *r, uint32_t fg, uint32_t bg, uint32_t sl, +static inline void hist_runs_add_pen(struct hist_runs *r, struct text_pen pen, uint32_t n) { - if (fg != r->pen.fg || bg != r->pen.bg || sl != pen_sl(&r->pen)) - hist_runs_switch(r, fg, bg, sl); + if (pen.fg != r->pen.fg || pen.bg != r->pen.bg || pen.sl != pen_sl(&r->pen)) + hist_runs_switch(r, pen); r->count += n; } static inline void hist_runs_add(struct hist_runs *r, const struct pen_attr *pen, uint32_t n) { - hist_runs_add_pen(r, pen->fg, pen->bg, pen_sl(pen), n); + hist_runs_add_pen(r, text_pen_from_attr(pen), n); } /* Start a text row. Each field gets its own store of its own width, because @@ -155,17 +138,17 @@ static inline void hist_runs_add(struct hist_runs *r, const struct pen_attr *pen static inline void text_row_start(struct text_row *row, const struct pen_attr *start) { if (row->storage) row->text = row->storage; - uint32_t fg = start->fg, bg = start->bg, sl = pen_sl(start); + struct text_pen pen = text_pen_from_attr(start); row->text_len = 0; row->cells = 0; row->wide = 0; row->fill_to = 0; row->flags = HLINE_NARROW; - pen_set(&row->start, fg, bg, sl); + pen_set_text(&row->start, pen); row->runs.len = 0; row->runs.count = 0; - pen_set(&row->runs.base, fg, bg, sl); - pen_set(&row->runs.pen, fg, bg, sl); + pen_set_text(&row->runs.base, pen); + pen_set_text(&row->runs.pen, pen); } static inline void text_row_unshare(struct text_row *row) |
