diff options
Diffstat (limited to 'src/nvim/marktree.c')
-rw-r--r-- | src/nvim/marktree.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/src/nvim/marktree.c b/src/nvim/marktree.c index a04f250fc3..39c1e36147 100644 --- a/src/nvim/marktree.c +++ b/src/nvim/marktree.c @@ -49,9 +49,9 @@ #include <assert.h> -#include "nvim/marktree.h" -#include "nvim/lib/kvec.h" #include "nvim/garray.h" +#include "nvim/lib/kvec.h" +#include "nvim/marktree.h" #define T MT_BRANCH_FACTOR #define ILEN (sizeof(mtnode_t)+(2 * T) * sizeof(void *)) @@ -137,7 +137,9 @@ static inline int marktree_getp_aux(const mtnode_t *x, mtkey_t k, int *r) end = mid; } } - if (begin == x->n) { *rr = 1; return x->n - 1; } + if (begin == x->n) { + *rr = 1; return x->n - 1; + } if ((*rr = key_cmp(k, x->key[begin])) < 0) { begin--; } @@ -232,9 +234,8 @@ uint64_t marktree_put(MarkTree *b, int row, int col, bool right_gravity) return id; } -uint64_t marktree_put_pair(MarkTree *b, - int start_row, int start_col, bool start_right, - int end_row, int end_col, bool end_right) +uint64_t marktree_put_pair(MarkTree *b, int start_row, int start_col, bool start_right, int end_row, + int end_col, bool end_right) { uint64_t id = (b->next_id+=ID_INCR)|PAIRED; uint64_t start_id = id|(start_right?RIGHT_GRAVITY:0); @@ -466,7 +467,7 @@ static mtnode_t *merge_node(MarkTree *b, mtnode_t *p, int i) unrelative(x->key[x->n].pos, &x->key[x->n+1+k].pos); } if (x->level) { - memmove(&x->ptr[x->n+1], y->ptr, (size_t)(y->n + 1) * sizeof(mtnode_t *)); + memmove(&x->ptr[x->n+1], y->ptr, ((size_t)y->n + 1) * sizeof(mtnode_t *)); for (int k = 0; k < y->n+1; k++) { x->ptr[x->n+k+1]->parent = x; } @@ -488,7 +489,7 @@ static void pivot_right(MarkTree *b, mtnode_t *p, int i) mtnode_t *x = p->ptr[i], *y = p->ptr[i+1]; memmove(&y->key[1], y->key, (size_t)y->n * sizeof(mtkey_t)); if (y->level) { - memmove(&y->ptr[1], y->ptr, (size_t)(y->n + 1) * sizeof(mtnode_t *)); + memmove(&y->ptr[1], y->ptr, ((size_t)y->n + 1) * sizeof(mtnode_t *)); } y->key[0] = p->key[i]; refkey(b, y, 0); @@ -594,8 +595,8 @@ bool marktree_itr_get(MarkTree *b, int row, int col, MarkTreeIter *itr) itr, false, false, NULL); } -bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, - bool last, bool gravity, mtpos_t *oldbase) +bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool last, bool gravity, + mtpos_t *oldbase) { mtkey_t k = { .pos = p, .id = gravity ? RIGHT_GRAVITY : 0 }; if (last && !gravity) { @@ -695,8 +696,7 @@ bool marktree_itr_next(MarkTree *b, MarkTreeIter *itr) return marktree_itr_next_skip(b, itr, false, NULL); } -static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, - mtpos_t oldbase[]) +static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, mtpos_t oldbase[]) { if (!itr->node) { return false; @@ -819,8 +819,8 @@ mtmark_t marktree_itr_current(MarkTreeIter *itr) mtpos_t pos = marktree_itr_pos(itr); mtmark_t mark = { .row = pos.row, .col = pos.col, - .id = ANTIGRAVITY(keyid), - .right_gravity = keyid & RIGHT_GRAVITY }; + .id = ANTIGRAVITY(keyid), + .right_gravity = keyid & RIGHT_GRAVITY }; return mark; } return (mtmark_t){ -1, -1, 0, false }; @@ -833,14 +833,12 @@ static void swap_id(uint64_t *id1, uint64_t *id2) *id2 = temp; } -bool marktree_splice(MarkTree *b, - int start_line, int start_col, - int old_extent_line, int old_extent_col, - int new_extent_line, int new_extent_col) +bool marktree_splice(MarkTree *b, int start_line, int start_col, int old_extent_line, + int old_extent_col, int new_extent_line, int new_extent_col) { mtpos_t start = { start_line, start_col }; - mtpos_t old_extent = { (int)old_extent_line, old_extent_col }; - mtpos_t new_extent = { (int)new_extent_line, new_extent_col }; + mtpos_t old_extent = { old_extent_line, old_extent_col }; + mtpos_t new_extent = { new_extent_line, new_extent_col }; bool may_delete = (old_extent.row != 0 || old_extent.col != 0); bool same_line = old_extent.row == 0 && new_extent.row == 0; @@ -903,7 +901,7 @@ continue_same_node: refkey(b, itr->node, itr->i); refkey(b, enditr->node, enditr->i); } else { - past_right = true; // NOLINT + past_right = true; // NOLINT (void)past_right; break; } @@ -994,10 +992,8 @@ past_continue_same_node: return moved; } -void marktree_move_region(MarkTree *b, - int start_row, colnr_T start_col, - int extent_row, colnr_T extent_col, - int new_row, colnr_T new_col) +void marktree_move_region(MarkTree *b, int start_row, colnr_T start_col, int extent_row, + colnr_T extent_col, int new_row, colnr_T new_col) { mtpos_t start = { start_row, start_col }, size = { extent_row, extent_col }; mtpos_t end = size; @@ -1114,8 +1110,7 @@ void marktree_check(MarkTree *b) } #ifndef NDEBUG -static size_t check_node(MarkTree *b, mtnode_t *x, - mtpos_t *last, bool *last_right) +static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_right) { assert(x->n <= 2 * T - 1); // TODO(bfredl): too strict if checking "in repair" post-delete tree. @@ -1173,8 +1168,7 @@ char *mt_inspect_rec(MarkTree *b) void mt_inspect_node(MarkTree *b, garray_T *ga, mtnode_t *n, mtpos_t off) { static char buf[1024]; -#define GA_PUT(x) ga_concat(ga, (char_u *)(x)) - GA_PUT("["); + ga_concat(ga, "["); if (n->level) { mt_inspect_node(b, ga, n->ptr[0], off); } @@ -1182,14 +1176,13 @@ void mt_inspect_node(MarkTree *b, garray_T *ga, mtnode_t *n, mtpos_t off) mtpos_t p = n->key[i].pos; unrelative(off, &p); snprintf((char *)buf, sizeof(buf), "%d/%d", p.row, p.col); - GA_PUT(buf); + ga_concat(ga, buf); if (n->level) { mt_inspect_node(b, ga, n->ptr[i+1], p); } else { - GA_PUT(","); + ga_concat(ga, ","); } } - GA_PUT("]"); -#undef GA_PUT + ga_concat(ga, "]"); } |