term: try to improve on a performance regression

When support was added for DECOM (absolute/relative row addressing), a
small but noticeable (~3.5%) performance regression was introduced.

Try to improve the situation by simplifying the relative-to-absolute
conversion; only the row needs to be transformed.
This commit is contained in:
Daniel Eklöf 2019-11-17 18:52:27 +01:00
parent cf75528e86
commit 9902a5732f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 17 additions and 29 deletions

20
csi.c
View file

@ -330,9 +330,9 @@ csi_dispatch(struct terminal *term, uint8_t final)
case 'd': { case 'd': {
/* VPA - vertical line position absolute */ /* VPA - vertical line position absolute */
struct coord new_cursor = term_cursor_rel_to_abs( int rel_row = vt_param_get(term, 0, 1) - 1;
term, vt_param_get(term, 0, 1) - 1, term->cursor.point.col); int row = term_row_rel_to_abs(term, rel_row);
term_cursor_to(term, new_cursor.row, new_cursor.col); term_cursor_to(term, row, term->cursor.point.col);
break; break;
} }
@ -399,20 +399,18 @@ csi_dispatch(struct terminal *term, uint8_t final)
case '`': case '`':
case 'G': { case 'G': {
/* Cursor horizontal absolute */ /* Cursor horizontal absolute */
struct coord new_cursor = term_cursor_rel_to_abs( int col = min(vt_param_get(term, 0, 1), term->cols) - 1;
term, term->cursor.point.row, vt_param_get(term, 0, 1) - 1); term_cursor_to(term, term->cursor.point.row, col);
term_cursor_to(term, new_cursor.row, new_cursor.col);
break; break;
} }
case 'f': case 'f':
case 'H': { case 'H': {
/* Move cursor */ /* Move cursor */
struct coord new_cursor = term_cursor_rel_to_abs( int rel_row = vt_param_get(term, 0, 1) - 1;
term, int row = term_row_rel_to_abs(term, rel_row);
vt_param_get(term, 0, 1) - 1, int col = min(vt_param_get(term, 1, 1), term->cols) - 1;
vt_param_get(term, 1, 1) - 1); term_cursor_to(term, row, col);
term_cursor_to(term, new_cursor.row, new_cursor.col);
break; break;
} }

View file

@ -995,28 +995,19 @@ term_erase(struct terminal *term, const struct coord *start, const struct coord
erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col); erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col);
} }
struct coord int
term_cursor_rel_to_abs(const struct terminal *term, int row, int col) term_row_rel_to_abs(const struct terminal *term, int row)
{ {
switch (term->origin) { switch (term->origin) {
case ORIGIN_ABSOLUTE: case ORIGIN_ABSOLUTE:
return (struct coord) { return min(row, term->rows - 1);
.col = min(col, term->cols - 1),
.row = min(row, term->rows - 1),
};
break;
case ORIGIN_RELATIVE: { case ORIGIN_RELATIVE:
return (struct coord) { return min(row + term->scroll_region.start, term->scroll_region.end - 1);
.col = min(col, term->cols - 1),
.row = min(row + term->scroll_region.start, term->rows - 1),
};
break;
}
} }
assert(false); assert(false);
return (struct coord){-1, -1}; return -1;
} }
void void
@ -1036,8 +1027,7 @@ term_cursor_to(struct terminal *term, int row, int col)
void void
term_cursor_home(struct terminal *term) term_cursor_home(struct terminal *term)
{ {
struct coord new_cursor = term_cursor_rel_to_abs(term, 0, 0); term_cursor_to(term, term_row_rel_to_abs(term, 0), 0);
term_cursor_to(term, new_cursor.row, new_cursor.col);
} }
void void

View file

@ -342,7 +342,7 @@ void term_damage_scroll(
void term_erase( void term_erase(
struct terminal *term, const struct coord *start, const struct coord *end); struct terminal *term, const struct coord *start, const struct coord *end);
struct coord term_cursor_rel_to_abs(const struct terminal *term, int row, int col); int term_row_rel_to_abs(const struct terminal *term, int row);
void term_cursor_home(struct terminal *term); void term_cursor_home(struct terminal *term);
void term_cursor_to(struct terminal *term, int row, int col); void term_cursor_to(struct terminal *term, int row, int col);
void term_cursor_left(struct terminal *term, int count); void term_cursor_left(struct terminal *term, int count);