aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/marktree.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-03-08 15:18:02 +0100
committerbfredl <bjorn.linse@gmail.com>2023-11-22 09:28:54 +0100
commit0b38fe4dbb77c15ae6f5779174855acab25fc86c (patch)
treef37567ea2fe07b6e640386bec469bf8e5d9166d1 /src/nvim/marktree.c
parent8c6b0a5f21d5f0cf3781ef2b6fdbb306d5604a02 (diff)
downloadrneovim-0b38fe4dbb77c15ae6f5779174855acab25fc86c.tar.gz
rneovim-0b38fe4dbb77c15ae6f5779174855acab25fc86c.tar.bz2
rneovim-0b38fe4dbb77c15ae6f5779174855acab25fc86c.zip
refactor(decorations): break up Decoration struct into smaller pieces
Remove the monolithic Decoration struct. Before this change, each extmark could either represent just a hl_id + priority value as a inline decoration, or it would take a pointer to this monolitic 112 byte struct which has to be allocated. This change separates the decorations into two pieces: DecorSignHighlight for signs, highlights and simple set-flag decorations (like spell, ui-watched), and DecorVirtText for virtual text and lines. The main separation here is whether they are expected to allocate more memory. Currently this is not really true as sign text has to be an allocated string, but the plan is to get rid of this eventually (it can just be an array of two schar_T:s). Further refactors are expected to improve the representation of each decoration kind individually. The goal of this particular PR is to get things started by cutting the Gordian knot which was the monolithic struct Decoration. Now, each extmark can either contain chained indicies/pointers to these kinds of objects, or it can fit a subset of DecorSignHighlight inline. The point of this change is not only to make decorations smaller in memory. In fact, the main motivation is to later allow them to grow _larger_, but on a dynamic, on demand fashion. As a simple example, it would be possible to augment highlights to take a list of multiple `hl_group`:s, which then would trivially map to a chain of multiple DecorSignHighlight entries. One small feature improvement included with this refactor itself, is that the restriction that extmarks cannot be removed inside a decoration provider has been lifted. These are instead safely lifetime extended on a "to free" list until the current iteration of screen drawing is done. NB: flags is a mess. but DecorLevel is useless, this slightly less so
Diffstat (limited to 'src/nvim/marktree.c')
-rw-r--r--src/nvim/marktree.c25
1 files changed, 3 insertions, 22 deletions
diff --git a/src/nvim/marktree.c b/src/nvim/marktree.c
index f350001977..110683a35c 100644
--- a/src/nvim/marktree.c
+++ b/src/nvim/marktree.c
@@ -287,7 +287,7 @@ static inline void marktree_putp_aux(MarkTree *b, MTNode *x, MTKey k)
void marktree_put(MarkTree *b, MTKey key, int end_row, int end_col, bool end_right)
{
- assert(!(key.flags & ~MT_FLAG_EXTERNAL_MASK));
+ assert(!(key.flags & ~(MT_FLAG_EXTERNAL_MASK | MT_FLAG_RIGHT_GRAVITY)));
if (end_row >= 0) {
key.flags |= MT_FLAG_PAIRED;
}
@@ -1137,25 +1137,6 @@ static void marktree_free_node(MarkTree *b, MTNode *x)
b->n_nodes--;
}
-/// NB: caller must check not pair!
-void marktree_revise(MarkTree *b, MarkTreeIter *itr, uint8_t decor_level, MTKey key)
-{
- // TODO(bfredl): clean up this mess and re-instantiate &= and |= forms
- // once we upgrade to a non-broken version of gcc in functionaltest-lua CI
- rawkey(itr).flags = (uint16_t)(rawkey(itr).flags & (uint16_t) ~MT_FLAG_DECOR_MASK);
- rawkey(itr).flags = (uint16_t)(rawkey(itr).flags & (uint16_t) ~MT_FLAG_INVALID);
- rawkey(itr).flags = (uint16_t)(rawkey(itr).flags
- | (uint16_t)(decor_level << MT_FLAG_DECOR_OFFSET)
- | (uint16_t)(key.flags & MT_FLAG_DECOR_MASK)
- | (uint16_t)(key.flags & MT_FLAG_HL_EOL)
- | (uint16_t)(key.flags & MT_FLAG_NO_UNDO)
- | (uint16_t)(key.flags & MT_FLAG_INVALID)
- | (uint16_t)(key.flags & MT_FLAG_INVALIDATE));
- rawkey(itr).decor_full = key.decor_full;
- rawkey(itr).hl_id = key.hl_id;
- rawkey(itr).priority = key.priority;
-}
-
/// @param itr iterator is invalid after call
void marktree_move(MarkTree *b, MarkTreeIter *itr, int row, int col)
{
@@ -2003,8 +1984,8 @@ static void marktree_itr_fix_pos(MarkTree *b, MarkTreeIter *itr)
void marktree_put_test(MarkTree *b, uint32_t ns, uint32_t id, int row, int col, bool right_gravity,
int end_row, int end_col, bool end_right)
{
- uint16_t flags = mt_flags(right_gravity, false, false, false, 0);
- MTKey key = { { row, col }, ns, id, 0, flags, 0, NULL };
+ uint16_t flags = mt_flags(right_gravity, false, false, false);
+ MTKey key = { { row, col }, ns, id, flags, { .hl = DECOR_HIGHLIGHT_INLINE_INIT } };
marktree_put(b, key, end_row, end_col, end_right);
}