refactor(marktree): unpaired marktree_get_alt() returns itself

Avoids checking for invalid mark at callsite.
This commit is contained in:
Luuk van Baal 2024-01-13 17:09:59 +01:00
parent e6ddceda31
commit 4f544b3119
4 changed files with 5 additions and 15 deletions

View File

@ -151,7 +151,7 @@ static Array extmark_to_array(MTPair extmark, bool id, bool add_dict, bool hl_na
PUT(dict, "right_gravity", BOOLEAN_OBJ(mt_right(start)));
if (extmark.end_pos.row >= 0) {
if (mt_paired(start)) {
PUT(dict, "end_row", INTEGER_OBJ(extmark.end_pos.row));
PUT(dict, "end_col", INTEGER_OBJ(extmark.end_pos.col));
PUT(dict, "end_right_gravity", BOOLEAN_OBJ(extmark.end_right_gravity));

View File

@ -612,10 +612,6 @@ int decor_redraw_col(win_T *wp, int col, int win_col, bool hidden, DecorState *s
}
MTPos endpos = marktree_get_altpos(buf->b_marktree, mark, NULL);
if (endpos.row == -1) {
endpos = mark.pos;
}
decor_range_add_from_inline(state, mark.pos.row, mark.pos.col, endpos.row, endpos.col,
mt_decor(mark), false, mark.ns, mark.id);
@ -842,7 +838,7 @@ static void buf_signcols_validate_range(buf_T *buf, int row1, int row2, int add)
// Increment overlap array for the start and range of a paired sign mark.
if (!mt_invalid(mark) && !mt_end(mark) && (mark.flags & MT_FLAG_DECOR_SIGNTEXT)) {
MTPos end = marktree_get_altpos(buf->b_marktree, mark, NULL);
for (int i = currow; i <= MIN(row2, end.row < 0 ? currow : end.row); i++) {
for (int i = currow; i <= MIN(row2, end.row); i++) {
overlap[i - row1]++;
}
}

View File

@ -332,9 +332,6 @@ void extmark_splice_delete(buf_T *buf, int l_row, colnr_T l_col, int u_row, coln
// Invalidate/delete mark
if (!only_copy && !mt_invalid(mark) && mt_invalidate(mark) && !mt_end(mark)) {
MTPos endpos = marktree_get_altpos(buf->b_marktree, mark, NULL);
if (endpos.row < 0) {
endpos = mark.pos;
}
// Invalidate unpaired marks in deleted lines and paired marks whose entire
// range has been deleted.
if ((!mt_paired(mark) && mark.pos.row < u_row)
@ -404,7 +401,7 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
MTKey mark = marktree_lookup(curbuf->b_marktree, pos.mark, itr);
mt_itr_rawkey(itr).flags &= (uint16_t) ~MT_FLAG_INVALID;
MTPos end = marktree_get_altpos(curbuf->b_marktree, mark, itr);
buf_put_decor(curbuf, mt_decor(mark), mark.pos.row, end.row < 0 ? mark.pos.row : end.row);
buf_put_decor(curbuf, mt_decor(mark), mark.pos.row, end.row);
}
// Redo
} else {

View File

@ -1972,13 +1972,10 @@ MTPos marktree_get_altpos(MarkTree *b, MTKey mark, MarkTreeIter *itr)
return marktree_get_alt(b, mark, itr).pos;
}
/// @return alt mark for a paired mark or mark itself for unpaired mark
MTKey marktree_get_alt(MarkTree *b, MTKey mark, MarkTreeIter *itr)
{
MTKey end = MT_INVALID_KEY;
if (mt_paired(mark)) {
end = marktree_lookup_ns(b, mark.ns, mark.id, !mt_end(mark), itr);
}
return end;
return mt_paired(mark) ? marktree_lookup_ns(b, mark.ns, mark.id, !mt_end(mark), itr) : mark;
}
static void marktree_itr_fix_pos(MarkTree *b, MarkTreeIter *itr)