From 1e69599900a753e2d7275d7ba714202b7d9c843e Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 14:46:44 +0300 Subject: 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 --- src/pen.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/pen.h') diff --git a/src/pen.h b/src/pen.h index 8349566..f84d6e3 100644 --- a/src/pen.h +++ b/src/pen.h @@ -5,6 +5,7 @@ #include "term.h" #include #include +#include struct term_pen { uint32_t fg; @@ -28,6 +29,46 @@ struct pen_attr { uint16_t link; }; +/* 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. */ +struct text_pen { + uint32_t fg; + uint32_t bg; + uint32_t sl; +}; + +static inline struct text_pen text_pen(uint32_t fg, uint32_t bg, uint32_t sl) +{ + return (struct text_pen){ fg, bg, sl }; +} + +static inline uint32_t pen_sl(const struct pen_attr *p) +{ + uint32_t sl; + memcpy(&sl, &p->flags, 4); + return sl; +} + +static inline struct text_pen text_pen_from_attr(const struct pen_attr *p) +{ + return (struct text_pen){ p->fg, p->bg, pen_sl(p) }; +} + +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); +} + +static inline void pen_set_text(struct pen_attr *p, struct text_pen pen) +{ + p->fg = pen.fg; + p->bg = pen.bg; + memcpy(&p->flags, &pen.sl, 4); +} + static inline struct pen_attr pen_attr_default(void) { return (struct pen_attr){ .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG }; -- cgit v1.2.3