Sync OpenBSD patchset 282:

A few trivial optimisations: no need to check for zero size if calling
buffer_ensure in buffer.c; expand grid lines by a greater increase than one
each time; and don't read UTF-8 data unless it actually needs to be checked
when overwriting a cell.
This commit is contained in:
Tiago Cunha 2009-08-21 21:09:13 +00:00
parent 15556ad0d6
commit 4b883524d8
3 changed files with 23 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $Id: buffer.c,v 1.7 2009-06-25 16:21:32 nicm Exp $ */ /* $Id: buffer.c,v 1.8 2009-08-21 21:09:13 tcunha Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -100,9 +100,6 @@ buffer_remove(struct buffer *b, size_t size)
void void
buffer_write(struct buffer *b, const void *data, size_t size) buffer_write(struct buffer *b, const void *data, size_t size)
{ {
if (size == 0)
fatalx("zero size");
buffer_ensure(b, size); buffer_ensure(b, size);
memcpy(BUFFER_IN(b), data, size); memcpy(BUFFER_IN(b), data, size);
buffer_add(b, size); buffer_add(b, size);
@ -127,7 +124,7 @@ buffer_write8(struct buffer *b, uint8_t n)
{ {
buffer_ensure(b, 1); buffer_ensure(b, 1);
BUFFER_IN(b)[0] = n; BUFFER_IN(b)[0] = n;
buffer_add(b, 1); b->size++;
} }
/* Extract an 8-bit value. */ /* Extract an 8-bit value. */

6
grid.c
View File

@ -1,4 +1,4 @@
/* $Id: grid.c,v 1.30 2009-08-10 21:40:21 tcunha Exp $ */ /* $Id: grid.c,v 1.31 2009-08-21 21:09:13 tcunha Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -198,6 +198,10 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx)
if (sx <= gl->cellsize) if (sx <= gl->cellsize)
return; return;
if (gl->cellsize > gd->sx / 2)
sx = gd->sx;
else
sx = 1 + gl->cellsize * 2;
gl->celldata = xrealloc(gl->celldata, sx, sizeof *gl->celldata); gl->celldata = xrealloc(gl->celldata, sx, sizeof *gl->celldata);
for (xx = gl->cellsize; xx < sx; xx++) for (xx = gl->cellsize; xx < sx; xx++)
grid_put_cell(gd, xx, py, &grid_default_cell); grid_put_cell(gd, xx, py, &grid_default_cell);

View File

@ -1,4 +1,4 @@
/* $Id: screen-write.c,v 1.68 2009-08-14 21:32:38 tcunha Exp $ */ /* $Id: screen-write.c,v 1.69 2009-08-21 21:09:13 tcunha Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -858,6 +858,7 @@ screen_write_overwrite(struct screen_write_ctx *ctx)
u_int xx; u_int xx;
gc = grid_view_peek_cell(gd, s->cx, s->cy); gc = grid_view_peek_cell(gd, s->cx, s->cy);
if (gc->flags & GRID_FLAG_UTF8)
gu = grid_view_peek_utf8(gd, s->cx, s->cy); gu = grid_view_peek_utf8(gd, s->cx, s->cy);
if (gc->flags & GRID_FLAG_PADDING) { if (gc->flags & GRID_FLAG_PADDING) {
@ -885,7 +886,9 @@ screen_write_overwrite(struct screen_write_ctx *ctx)
break; break;
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
} }
} else if (gc->flags & GRID_FLAG_UTF8 && gu->width > 1) { } else if (gc->flags & GRID_FLAG_UTF8) {
gu = grid_view_peek_utf8(gd, s->cx, s->cy);
if (gu->width > 1) {
/* /*
* An UTF-8 wide cell; overwrite following padding cells only. * An UTF-8 wide cell; overwrite following padding cells only.
*/ */
@ -897,4 +900,5 @@ screen_write_overwrite(struct screen_write_ctx *ctx)
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
} }
} }
}
} }