From ac1f294bb930a0c05f96197b6a53b883ebc483f2 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 8 Feb 2017 15:41:41 +0000 Subject: Add a helper to store a cell, and some tidying. --- grid.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'grid.c') diff --git a/grid.c b/grid.c index 7fcddf61..741e9bf3 100644 --- a/grid.c +++ b/grid.c @@ -59,6 +59,25 @@ static size_t grid_string_cells_bg(const struct grid_cell *, int *); static void grid_string_cells_code(const struct grid_cell *, const struct grid_cell *, char *, size_t, int); +/* Store cell in entry. */ +static void +grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc, + u_char c) +{ + gce->flags = gc->flags; + + gce->data.fg = gc->fg & 0xff; + if (gc->fg & COLOUR_FLAG_256) + gce->flags |= GRID_FLAG_FG256; + + gce->data.bg = gc->bg & 0xff; + if (gc->bg & COLOUR_FLAG_256) + gce->flags |= GRID_FLAG_BG256; + + gce->data.attr = gc->attr; + gce->data.data = c; +} + /* Set cell as extended. */ static struct grid_cell * grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce, @@ -371,11 +390,10 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc) grid_expand_line(gd, py, px + 1, 8); gl = &gd->linedata[py]; - gce = &gl->celldata[px]; - if (px + 1 > gl->cellused) gl->cellused = px + 1; + gce = &gl->celldata[px]; extended = (gce->flags & GRID_FLAG_EXTENDED); if (!extended && (gc->data.size != 1 || gc->data.width != 1)) extended = 1; @@ -383,20 +401,10 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc) extended = 1; if (!extended && (gc->bg & COLOUR_FLAG_RGB)) extended = 1; - if (extended) { + if (extended) grid_extended_cell(gl, gce, gc); - return; - } - - gce->flags = gc->flags; - gce->data.attr = gc->attr; - gce->data.fg = gc->fg & 0xff; - if (gc->fg & COLOUR_FLAG_256) - gce->flags |= GRID_FLAG_FG256; - gce->data.bg = gc->bg & 0xff; - if (gc->bg & COLOUR_FLAG_256) - gce->flags |= GRID_FLAG_BG256; - gce->data.data = gc->data.data[0]; + else + grid_store_cell(gce, gc, gc->data.data[0]); } /* Clear area. */ -- cgit From 13a0b6bb3fe05454cace81f5ec7624f6fd9021a5 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 8 Feb 2017 16:45:18 +0000 Subject: Collect sequences of printable ASCII characters and process them together instead of handling them one by one. This is significantly faster. Sequences are terminated when we reach the end of the line, fill the internal buffer, or a different character is seen by the input parser (an escape sequence, or UTF-8). Rather than writing collected sequences out immediately, hold them until it is necessary (another screen modification, or we consume all available data). This means we can discard changes that would have no effect (for example, lines that would just be scrolled off the screen or cleared). This reduces the total amount of data we write out to the terminal - not important for fast terminals, but a big help with slow (like xterm). --- grid.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'grid.c') diff --git a/grid.c b/grid.c index 741e9bf3..388a2c1b 100644 --- a/grid.c +++ b/grid.c @@ -407,6 +407,36 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc) grid_store_cell(gce, gc, gc->data.data[0]); } +/* Set cells at relative position. */ +void +grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc, + const char *s, size_t slen) +{ + struct grid_line *gl; + struct grid_cell_entry *gce; + struct grid_cell *gcp; + u_int i; + + if (grid_check_y(gd, py) != 0) + return; + + grid_expand_line(gd, py, px + slen, 8); + + gl = &gd->linedata[py]; + if (px + slen > gl->cellused) + gl->cellused = px + slen; + + for (i = 0; i < slen; i++) { + gce = &gl->celldata[px + i]; + if (gce->flags & GRID_FLAG_EXTENDED) { + gcp = &gl->extddata[gce->offset]; + memcpy(gcp, gc, sizeof *gcp); + utf8_set(&gcp->data, s[i]); + } else + grid_store_cell(gce, gc, s[i]); + } +} + /* Clear area. */ void grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg) -- cgit