refactor: comments, variable names

This commit is contained in:
vanaigr 2024-11-28 22:30:38 -06:00
parent c57397f981
commit fccef5ec35
3 changed files with 16 additions and 10 deletions

View File

@ -473,6 +473,8 @@ bool decor_redraw_line(win_T *wp, int row, DecorState *state)
int const cur_end = state->current_end; int const cur_end = state->current_end;
int fut_beg = state->future_begin; int fut_beg = state->future_begin;
// Move future ranges to start right after current ranges.
// Otherwise future ranges will grow forward indefinitely.
if (fut_beg == count) { if (fut_beg == count) {
fut_beg = count = cur_end; fut_beg = count = cur_end;
} else if (fut_beg != cur_end) { } else if (fut_beg != cur_end) {
@ -528,6 +530,7 @@ static void decor_range_insert(DecorState *state, DecorRange *range)
range->ordering = state->new_range_ordering++; range->ordering = state->new_range_ordering++;
int index; int index;
// Get space for a new `DecorRange` from the freelist or allocate.
if (state->free_slot_i >= 0) { if (state->free_slot_i >= 0) {
index = state->free_slot_i; index = state->free_slot_i;
DecorRangeSlot *slot = &kv_A(state->slots, index); DecorRangeSlot *slot = &kv_A(state->slots, index);
@ -635,11 +638,11 @@ void decor_init_draw_col(int win_col, bool hidden, DecorRange *item)
void decor_recheck_draw_col(int win_col, bool hidden, DecorState *state) void decor_recheck_draw_col(int win_col, bool hidden, DecorState *state)
{ {
int const count = state->current_end; int const end = state->current_end;
int *const indices = state->ranges_i.items; int *const indices = state->ranges_i.items;
DecorRangeSlot *const slots = state->slots.items; DecorRangeSlot *const slots = state->slots.items;
for (int i = 0; i < count; i++) { for (int i = 0; i < end; i++) {
DecorRange *const r = &slots[indices[i]].range; DecorRange *const r = &slots[indices[i]].range;
if (r->draw_col == -3) { if (r->draw_col == -3) {
decor_init_draw_col(win_col, hidden, r); decor_init_draw_col(win_col, hidden, r);
@ -683,6 +686,7 @@ next_mark:
int cur_end = state->current_end; int cur_end = state->current_end;
int fut_beg = state->future_begin; int fut_beg = state->future_begin;
// Promote future ranges before the cursor to active.
for (; fut_beg < count; fut_beg++) { for (; fut_beg < count; fut_beg++) {
int const index = indices[fut_beg]; int const index = indices[fut_beg];
DecorRange *const r = &slots[index].range; DecorRange *const r = &slots[index].range;
@ -711,7 +715,7 @@ next_mark:
cur_end++; cur_end++;
} }
if (fut_beg != count) { if (fut_beg < count) {
DecorRange *r = &slots[indices[fut_beg]].range; DecorRange *r = &slots[indices[fut_beg]].range;
if (r->start_row == row) { if (r->start_row == row) {
col_until = MIN(col_until, r->start_col - 1); col_until = MIN(col_until, r->start_col - 1);

View File

@ -27,17 +27,19 @@ typedef enum {
kDecorKindVirtText, kDecorKindVirtText,
kDecorKindVirtLines, kDecorKindVirtLines,
kDecorKindUIWatched, kDecorKindUIWatched,
} DecorRangeKind; } DecorRangeKindEnum;
typedef uint8_t DecorRangeKind;
typedef struct { typedef struct {
int start_row; int start_row;
int start_col; int start_col;
int end_row; int end_row;
int end_col; int end_col;
int ordering; int ordering; ///< range insertion order
DecorPriority priority; DecorPriority priority;
bool owned; ///< ephemeral decoration, free memory immediately bool owned; ///< ephemeral decoration, free memory immediately
DecorRangeKind kind: 8; DecorRangeKind kind;
// next pointers MUST NOT be used, these are separate ranges // next pointers MUST NOT be used, these are separate ranges
// vt->next could be pointing to freelist memory at this point // vt->next could be pointing to freelist memory at this point
union { union {

View File

@ -256,11 +256,11 @@ static void draw_virt_text(win_T *wp, buf_T *buf, int col_off, int *end_col, int
int right_pos = max_col; int right_pos = max_col;
bool const do_eol = state->eol_col > -1; bool const do_eol = state->eol_col > -1;
int const count = state->current_end; int const end = state->current_end;
int *const indices = state->ranges_i.items; int *const indices = state->ranges_i.items;
DecorRangeSlot *const slots = state->slots.items; DecorRangeSlot *const slots = state->slots.items;
for (int i = 0; i < count; i++) { for (int i = 0; i < end; i++) {
DecorRange *item = &slots[indices[i]].range; DecorRange *item = &slots[indices[i]].range;
if (!(item->start_row == state->row && decor_virt_pos(item))) { if (!(item->start_row == state->row && decor_virt_pos(item))) {
continue; continue;
@ -796,11 +796,11 @@ static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t
wlv->virt_inline = VIRTTEXT_EMPTY; wlv->virt_inline = VIRTTEXT_EMPTY;
wlv->virt_inline_i = 0; wlv->virt_inline_i = 0;
DecorState *state = &decor_state; DecorState *state = &decor_state;
int const count = state->current_end; int const end = state->current_end;
int *const indices = state->ranges_i.items; int *const indices = state->ranges_i.items;
DecorRangeSlot *const slots = state->slots.items; DecorRangeSlot *const slots = state->slots.items;
for (int i = 0; i < count; i++) { for (int i = 0; i < end; i++) {
DecorRange *item = &slots[indices[i]].range; DecorRange *item = &slots[indices[i]].range;
if (item->draw_col == -3) { if (item->draw_col == -3) {
// No more inline virtual text before this non-inline virtual text item, // No more inline virtual text before this non-inline virtual text item,