aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-17 17:52:27 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-17 17:52:27 +0000
commit9902a5732f9d3d99955f3c7bf09ebc8db4bd1f82 (patch)
treebfb3f8a5014131babca701f4c4276fd0a1dd8138
parentRevert "term: new function: term_autowrap()" (diff)
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.
-rw-r--r--csi.c20
-rw-r--r--terminal.c24
-rw-r--r--terminal.h2
3 files changed, 17 insertions, 29 deletions
diff --git a/csi.c b/csi.c
index 012af5d6..1e8e3f68 100644
--- a/csi.c
+++ b/csi.c
@@ -330,9 +330,9 @@ csi_dispatch(struct terminal *term, uint8_t final)
case 'd': {
/* VPA - vertical line position absolute */
- struct coord new_cursor = term_cursor_rel_to_abs(
- term, vt_param_get(term, 0, 1) - 1, term->cursor.point.col);
- term_cursor_to(term, new_cursor.row, new_cursor.col);
+ int rel_row = vt_param_get(term, 0, 1) - 1;
+ int row = term_row_rel_to_abs(term, rel_row);
+ term_cursor_to(term, row, term->cursor.point.col);
break;
}
@@ -399,20 +399,18 @@ csi_dispatch(struct terminal *term, uint8_t final)
case '`':
case 'G': {
/* Cursor horizontal absolute */
- struct coord new_cursor = term_cursor_rel_to_abs(
- term, term->cursor.point.row, vt_param_get(term, 0, 1) - 1);
- term_cursor_to(term, new_cursor.row, new_cursor.col);
+ int col = min(vt_param_get(term, 0, 1), term->cols) - 1;
+ term_cursor_to(term, term->cursor.point.row, col);
break;
}
case 'f':
case 'H': {
/* Move cursor */
- struct coord new_cursor = term_cursor_rel_to_abs(
- term,
- vt_param_get(term, 0, 1) - 1,
- vt_param_get(term, 1, 1) - 1);
- term_cursor_to(term, new_cursor.row, new_cursor.col);
+ int rel_row = vt_param_get(term, 0, 1) - 1;
+ int row = term_row_rel_to_abs(term, rel_row);
+ int col = min(vt_param_get(term, 1, 1), term->cols) - 1;
+ term_cursor_to(term, row, col);
break;
}
diff --git a/terminal.c b/terminal.c
index 5511eba5..ba625fc5 100644
--- a/terminal.c
+++ b/terminal.c
@@ -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);
}
-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)
{
switch (term->origin) {
case ORIGIN_ABSOLUTE:
- return (struct coord) {
- .col = min(col, term->cols - 1),
- .row = min(row, term->rows - 1),
- };
- break;
+ return min(row, term->rows - 1);
- case ORIGIN_RELATIVE: {
- return (struct coord) {
- .col = min(col, term->cols - 1),
- .row = min(row + term->scroll_region.start, term->rows - 1),
- };
- break;
- }
+ case ORIGIN_RELATIVE:
+ return min(row + term->scroll_region.start, term->scroll_region.end - 1);
}
assert(false);
- return (struct coord){-1, -1};
+ return -1;
}
void
@@ -1036,8 +1027,7 @@ term_cursor_to(struct terminal *term, int row, int col)
void
term_cursor_home(struct terminal *term)
{
- struct coord new_cursor = term_cursor_rel_to_abs(term, 0, 0);
- term_cursor_to(term, new_cursor.row, new_cursor.col);
+ term_cursor_to(term, term_row_rel_to_abs(term, 0), 0);
}
void
diff --git a/terminal.h b/terminal.h
index f5d7658f..8e0e83c8 100644
--- a/terminal.h
+++ b/terminal.h
@@ -342,7 +342,7 @@ void term_damage_scroll(
void term_erase(
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_to(struct terminal *term, int row, int col);
void term_cursor_left(struct terminal *term, int count);