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.
This commit is contained in:
nicm
2015-11-13 08:09:28 +00:00
parent e71a915412
commit c5689a5a40
12 changed files with 297 additions and 282 deletions

37
tty.c
View File

@ -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