aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-05-16 19:36:08 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-05-16 19:36:08 +0000
commit1a8ccb0ffaeda73df855fd3fb70a83e718faa9ec (patch)
tree58567c4be04652d3703211cef7247ff4ecb372c1 /selection.c
parentterm: scrolling: clear selection *before* scrolling (diff)
selection/render: sync cells' 'selected' bit before rendering
For performance reasons, we track whether a cell is selected or not using a bit in a cell's attributes. This makes it easy for the renderer to determine if the cells should be rendered as selected or not - it just have to look at the 'selected' bit instead of doing a complex range check against the current selection. This works nicely in most cases. But, if the cell is updated, the 'selected' bit is cleared. This results in the renderer rendering the cell normally, i.e. _not_ selected. Checking for this, and re-setting the 'selected' bit when the cell is updated (printed to) is way too expensive as it is in the hot path. Instead, sync the 'selected' bits just before rendering. This isn't so bad as it may sound; if there is no selection this is a no-op. Even if there is a selection, only those cells whose 'selected' bit have been cleared are dirtied (and thus re-rendered) - these cells would have been re-rendered anyway.
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/selection.c b/selection.c
index 7e5a12ab..59cab9a7 100644
--- a/selection.c
+++ b/selection.c
@@ -403,6 +403,16 @@ selection_update(struct terminal *term, int col, int row)
selection_modify(term, term->selection.start, new_end);
}
+void
+selection_dirty_cells(struct terminal *term)
+{
+ if (term->selection.start.row == -1 || term->selection.end.row == -1)
+ return;
+
+ foreach_selected(
+ term, term->selection.start, term->selection.end, &mark_selected, NULL);
+}
+
static void
selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial)
{