From 00c5b27bfaa34c57bd4e148fbd52b4f6e1e0262d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 6 Jul 2019 13:25:36 +0200 Subject: [PATCH] vt: add branch hinting to PRINT action --- terminal.h | 3 +++ vt.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/terminal.h b/terminal.h index 099e384a..235108af 100644 --- a/terminal.h +++ b/terminal.h @@ -12,6 +12,9 @@ #include "tllist.h" +#define likely(c) __builtin_expect(!!(c), 1) +#define unlikely(c) __builtin_expect(!!(c), 0) + struct wayland { struct wl_display *display; struct wl_registry *registry; diff --git a/vt.c b/vt.c index 12a5147d..a3ace1f2 100644 --- a/vt.c +++ b/vt.c @@ -698,7 +698,7 @@ action(struct terminal *term, enum action action, uint8_t c) break; case ACTION_PRINT: { - if (term->auto_margin && term->print_needs_wrap) { + if (unlikely(term->print_needs_wrap) && term->auto_margin) { if (term->cursor.row == term->scroll_region.end - 1) { term_scroll(term, 1); term_cursor_to(term, term->cursor.row, 0); @@ -709,7 +709,7 @@ action(struct terminal *term, enum action action, uint8_t c) struct cell *cell = &term->grid->cur_line[term->cursor.col]; term_damage_update(term, term->cursor.linear, 1); - if (term->insert_mode) { + if (unlikely(term->insert_mode)) { assert(false && "untested"); grid_memmove( term->grid, term->cursor.linear + 1, term->cursor.linear, @@ -735,7 +735,7 @@ action(struct terminal *term, enum action action, uint8_t c) "│", "≤", "≥", "π", "≠", "£", "·", /* x - ~ */ }; - if (term->charset[term->selected_charset] == CHARSET_GRAPHIC && + if (unlikely(term->charset[term->selected_charset] == CHARSET_GRAPHIC) && c >= 0x41 && c <= 0x7e) { strcpy(cell->c, vt100_0[c - 0x41]);