aboutsummaryrefslogtreecommitdiff
path: root/tty.c
diff options
context:
space:
mode:
authornicm <nicm>2015-11-13 08:09:28 +0000
committernicm <nicm>2015-11-13 08:09:28 +0000
commitc5689a5a4031a43769b8b721cafa6d1eab6abc44 (patch)
tree8eb234cb05f7934a41365dc0674794ccb34561c5 /tty.c
parente71a9154126c7ee853b9a657678de40d475279eb (diff)
downloadrtmux-c5689a5a4031a43769b8b721cafa6d1eab6abc44.tar.gz
rtmux-c5689a5a4031a43769b8b721cafa6d1eab6abc44.tar.bz2
rtmux-c5689a5a4031a43769b8b721cafa6d1eab6abc44.zip
Long overdue change to the way we store cells in the grid: now, instead
of storing a full grid_cell with UTF-8 data and everything, store a new type grid_cell_entry. This can either be the cell itself (for ASCII cells), or an offset into an extended array (per line) for UTF-8 data. This avoid a large (8 byte) overhead on non-UTF-8 cells (by far the majority for most users) without the complexity of the shadow array we had before. Grid memory without any UTF-8 is about half. The disadvantage that cells can no longer be modified in place and need to be copied out of the grid and back but it turned out to be lot less complicated than I expected.
Diffstat (limited to 'tty.c')
-rw-r--r--tty.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/tty.c b/tty.c
index c0ae79bb..e67ebbb6 100644
--- a/tty.c
+++ b/tty.c
@@ -656,10 +656,8 @@ void
tty_draw_line(struct tty *tty, const struct window_pane *wp,
struct screen *s, u_int py, u_int ox, u_int oy)
{
- const struct grid_cell *gc;
+ struct grid_cell gc;
struct grid_line *gl;
- struct grid_cell tmpgc;
- struct utf8_data ud;
u_int i, sx;
int flags;
@@ -686,18 +684,13 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp,
tty_cursor(tty, ox, oy + py);
for (i = 0; i < sx; i++) {
- gc = grid_view_peek_cell(s->grid, i, py);
+ grid_view_get_cell(s->grid, i, py, &gc);
if (screen_check_selection(s, i, py)) {
- memcpy(&tmpgc, &s->sel.cell, sizeof tmpgc);
- grid_cell_get(gc, &ud);
- grid_cell_set(&tmpgc, &ud);
- tmpgc.flags = gc->flags &
- ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
- tmpgc.flags |= s->sel.cell.flags &
+ gc.flags &= ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
+ gc.flags |= s->sel.cell.flags &
(GRID_FLAG_FG256|GRID_FLAG_BG256);
- tty_cell(tty, &tmpgc, wp);
- } else
- tty_cell(tty, gc, wp);
+ }
+ tty_cell(tty, &gc, wp);
}
if (sx < tty->sx) {
@@ -1078,7 +1071,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
/* Is the cursor in the very last position? */
- width = grid_cell_width(ctx->cell);
+ width = ctx->cell->data.width;
if (ctx->ocx > wp->sx - width) {
if (ctx->xoff != 0 || wp->sx != tty->sx) {
/*
@@ -1095,7 +1088,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
* move as far left as possible and redraw the last
* cell to move into the last position.
*/
- cx = screen_size_x(s) - grid_cell_width(&ctx->last_cell);
+ cx = screen_size_x(s) - ctx->last_cell.data.width;
tty_cursor_pane(tty, ctx, cx, ctx->ocy);
tty_cell(tty, &ctx->last_cell, wp);
}
@@ -1155,8 +1148,7 @@ void
tty_cell(struct tty *tty, const struct grid_cell *gc,
const struct window_pane *wp)
{
- struct utf8_data ud;
- u_int i;
+ u_int i;
/* Skip last character if terminal is stupid. */
if (tty->term->flags & TERM_EARLYWRAP &&
@@ -1171,23 +1163,22 @@ tty_cell(struct tty *tty, const struct grid_cell *gc,
tty_attributes(tty, gc, wp);
/* Get the cell and if ASCII write with putc to do ACS translation. */
- grid_cell_get(gc, &ud);
- if (ud.size == 1) {
- if (*ud.data < 0x20 || *ud.data == 0x7f)
+ if (gc->data.size == 1) {
+ if (*gc->data.data < 0x20 || *gc->data.data == 0x7f)
return;
- tty_putc(tty, *ud.data);
+ tty_putc(tty, *gc->data.data);
return;
}
/* If not UTF-8, write _. */
if (!(tty->flags & TTY_UTF8)) {
- for (i = 0; i < ud.width; i++)
+ for (i = 0; i < gc->data.width; i++)
tty_putc(tty, '_');
return;
}
/* Write the data. */
- tty_putn(tty, ud.data, ud.size, ud.width);
+ tty_putn(tty, gc->data.data, gc->data.size, gc->data.width);
}
void