From 9df7e8fa07a234b6a7b33b52310e7ddaa884850f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 9 Jun 2020 17:31:28 +0200 Subject: [PATCH] term: print_insert: early return --- terminal.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/terminal.c b/terminal.c index 8181a610..f43c7320 100644 --- a/terminal.c +++ b/terminal.c @@ -2353,19 +2353,20 @@ print_insert(struct terminal *term, int width) { assert(width > 0); - if (unlikely(term->insert_mode)) { - struct row *row = term->grid->cur_row; - const size_t move_count = max(0, term->cols - term->grid->cursor.point.col - width); + if (likely(!term->insert_mode)) + return; - memmove( - &row->cells[term->grid->cursor.point.col + width], - &row->cells[term->grid->cursor.point.col], - move_count * sizeof(struct cell)); + struct row *row = term->grid->cur_row; + const size_t move_count = max(0, term->cols - term->grid->cursor.point.col - width); - /* Mark moved cells as dirty */ - for (size_t i = term->grid->cursor.point.col + width; i < term->cols; i++) - row->cells[i].attrs.clean = 0; - } + memmove( + &row->cells[term->grid->cursor.point.col + width], + &row->cells[term->grid->cursor.point.col], + move_count * sizeof(struct cell)); + + /* Mark moved cells as dirty */ + for (size_t i = term->grid->cursor.point.col + width; i < term->cols; i++) + row->cells[i].attrs.clean = 0; } void