diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-05-06 02:26:17 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-05-06 02:34:37 -0400 |
commit | 3c25cdce7e21b8680f8fb6a472c30c8648293914 (patch) | |
tree | 663b6b63c70da05ec82eb7db2fa52d2e118f91f8 | |
parent | e07b9e065fa55449b362e417bc152e9a37d5f91a (diff) | |
download | runes-3c25cdce7e21b8680f8fb6a472c30c8648293914.tar.gz runes-3c25cdce7e21b8680f8fb6a472c30c8648293914.zip |
stop calling move_to so often when it's not necessary
-rw-r--r-- | src/screen.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/screen.c b/src/screen.c index 17d77cc..2e0c34c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -118,23 +118,24 @@ void runes_screen_show_string_ascii(RunesTerm *t, char *buf, size_t len) { RunesScreen *scr = &t->scr; size_t i; + int col = scr->grid->cur.col; for (i = 0; i < len; ++i) { struct runes_cell *cell; - if (scr->grid->cur.col >= scr->grid->max.col) { + if (col >= scr->grid->max.col) { runes_screen_row_at(t, scr->grid->cur.row)->wrapped = 1; runes_screen_move_to(t, scr->grid->cur.row + 1, 0); + col = 0; } - cell = runes_screen_cell_at(t, scr->grid->cur.row, scr->grid->cur.col); + cell = runes_screen_cell_at(t, scr->grid->cur.row, col++); cell->len = 1; cell->contents[0] = buf[i]; cell->attrs = scr->attrs; cell->is_wide = 0; - - runes_screen_move_to(t, scr->grid->cur.row, scr->grid->cur.col + 1); } + runes_screen_move_to(t, scr->grid->cur.row, col); scr->dirty = 1; } @@ -143,6 +144,7 @@ void runes_screen_show_string_utf8(RunesTerm *t, char *buf, size_t len) { RunesScreen *scr = &t->scr; char *c = buf, *next; + int col = scr->grid->cur.col; /* XXX need to detect combining characters and append them to the previous * cell */ @@ -161,9 +163,9 @@ void runes_screen_show_string_utf8(RunesTerm *t, char *buf, size_t len) || ctype == G_UNICODE_NON_SPACING_MARK; if (is_combining) { - if (scr->grid->cur.col > 0) { + if (col > 0) { cell = runes_screen_cell_at( - t, scr->grid->cur.row, scr->grid->cur.col - 1); + t, scr->grid->cur.row, col - 1); } else if (scr->grid->cur.row > 0 && runes_screen_row_at(t, scr->grid->cur.row - 1)->wrapped) { cell = runes_screen_cell_at( @@ -186,20 +188,19 @@ void runes_screen_show_string_utf8(RunesTerm *t, char *buf, size_t len) } } else { - if (scr->grid->cur.col + (is_wide ? 2 : 1) > scr->grid->max.col) { + if (col + (is_wide ? 2 : 1) > scr->grid->max.col) { runes_screen_row_at(t, scr->grid->cur.row)->wrapped = 1; runes_screen_move_to(t, scr->grid->cur.row + 1, 0); + col = 0; } - cell = runes_screen_cell_at( - t, scr->grid->cur.row, scr->grid->cur.col); + cell = runes_screen_cell_at(t, scr->grid->cur.row, col); cell->is_wide = is_wide; cell->len = next - c; memcpy(cell->contents, c, cell->len); cell->attrs = scr->attrs; - runes_screen_move_to( - t, scr->grid->cur.row, scr->grid->cur.col + (is_wide ? 2 : 1)); + col += is_wide ? 2 : 1; } c = next; @@ -207,6 +208,7 @@ void runes_screen_show_string_utf8(RunesTerm *t, char *buf, size_t len) break; } } + runes_screen_move_to(t, scr->grid->cur.row, col); scr->dirty = 1; } |