From 4be63ed8cd2eb1c4861f0ab287f24ea695fd671e Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Wed, 14 Oct 2026 14:36:22 +0300 Subject: Optimize term_feed scalar dispatch, branchless range search, and invalid subparts --- src/core.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/core.h') diff --git a/src/core.h b/src/core.h index 79e6eb9..aab2cde 100644 --- a/src/core.h +++ b/src/core.h @@ -30,6 +30,39 @@ static inline void sc_print_ascii(struct term *t, const char *s, int n); /* Print one glyph (single codepoint or cluster handle). */ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags); +static inline void sc_print_cell(struct term *t, uint32_t cp, int width, uint16_t flags) +{ + if (TERM_EXPECT(width == 1 && !t->pending_wrap && !t->insert_mode && + !t->lr_margin_mode && t->cursor_x < t->cols, 1)) { + struct srow *srow = term_row(t, t->cursor_y); + int cx = t->cursor_x; + int len = srow->len; + if (TERM_EXPECT(srow->kind == ROW_CELLS && cx <= len, 1)) { + struct cell *row = srow->cells; + if (TERM_EXPECT(!((cx < len && (row[cx].flags & CELL_TRAIL)) || + (cx + 1 < len && (row[cx + 1].flags & CELL_TRAIL))), 1)) { + row[cx] = (struct cell){cp, + t->inverse ? t->cur_bg : t->cur_fg, + t->inverse ? t->cur_fg : t->cur_bg, + flags, t->cur_link}; + t->last_char = cp; + cx++; + if (cx > len) srow->len = (uint16_t)cx; + srow->version++; + if (cx < t->cols) { + t->cursor_x = cx; + t->pending_wrap = false; + } else { + t->cursor_x = t->cols - 1; + t->pending_wrap = t->autowrap; + } + return; + } + } + } + term_sc_print_glyph(t, cp, width, flags); +} + /* Extend the last printed glyph into a grapheme cluster. */ bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass); -- cgit v1.2.3