mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18:18 +00:00
refactor(extmark): remove pointer indirection for extmark use of maps
This commit is contained in:
@@ -863,8 +863,8 @@ struct file_buffer {
|
|||||||
int b_mapped_ctrl_c; // modes where CTRL-C is mapped
|
int b_mapped_ctrl_c; // modes where CTRL-C is mapped
|
||||||
|
|
||||||
MarkTree b_marktree[1];
|
MarkTree b_marktree[1];
|
||||||
Map(uint64_t, ExtmarkItem) *b_extmark_index;
|
Map(uint64_t, ExtmarkItem) b_extmark_index[1];
|
||||||
Map(uint64_t, ExtmarkNs) *b_extmark_ns; // extmark namespaces
|
Map(uint64_t, ExtmarkNs) b_extmark_ns[1]; // extmark namespaces
|
||||||
|
|
||||||
// array of channel_id:s which have asked to receive updates for this
|
// array of channel_id:s which have asked to receive updates for this
|
||||||
// buffer.
|
// buffer.
|
||||||
|
@@ -150,7 +150,7 @@ bool decor_redraw_reset(buf_T *buf, DecorState *state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
kv_size(state->active) = 0;
|
kv_size(state->active) = 0;
|
||||||
return buf->b_extmark_index;
|
return map_size(buf->b_extmark_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -48,20 +48,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static ExtmarkNs *buf_ns_ref(buf_T *buf, uint64_t ns_id, bool put) {
|
static ExtmarkNs *buf_ns_ref(buf_T *buf, uint64_t ns_id, bool put) {
|
||||||
if (!buf->b_extmark_ns) {
|
return map_ref(uint64_t, ExtmarkNs)(buf->b_extmark_ns, ns_id, put);
|
||||||
if (!put) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
buf->b_extmark_ns = map_new(uint64_t, ExtmarkNs)();
|
|
||||||
buf->b_extmark_index = map_new(uint64_t, ExtmarkItem)();
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtmarkNs *ns = map_ref(uint64_t, ExtmarkNs)(buf->b_extmark_ns, ns_id, put);
|
|
||||||
if (put && ns->map == NULL) {
|
|
||||||
ns->map = map_new(uint64_t, uint64_t)();
|
|
||||||
ns->free_id = 1;
|
|
||||||
}
|
|
||||||
return ns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -195,7 +182,7 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
|
|||||||
int l_row, colnr_T l_col,
|
int l_row, colnr_T l_col,
|
||||||
int u_row, colnr_T u_col)
|
int u_row, colnr_T u_col)
|
||||||
{
|
{
|
||||||
if (!buf->b_extmark_ns) {
|
if (!map_size(buf->b_extmark_ns)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,12 +202,9 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the value is either zero or the lnum (row+1) if highlight was present.
|
// the value is either zero or the lnum (row+1) if highlight was present.
|
||||||
static Map(uint64_t, ssize_t) *delete_set = NULL;
|
static Map(uint64_t, ssize_t) delete_set = MAP_INIT;
|
||||||
typedef struct { Decoration *decor; int row1; } DecorItem;
|
typedef struct { Decoration *decor; int row1; } DecorItem;
|
||||||
static kvec_t(DecorItem) decors;
|
static kvec_t(DecorItem) decors;
|
||||||
if (delete_set == NULL) {
|
|
||||||
delete_set = map_new(uint64_t, ssize_t)();
|
|
||||||
}
|
|
||||||
|
|
||||||
MarkTreeIter itr[1] = { 0 };
|
MarkTreeIter itr[1] = { 0 };
|
||||||
marktree_itr_get(buf->b_marktree, l_row, l_col, itr);
|
marktree_itr_get(buf->b_marktree, l_row, l_col, itr);
|
||||||
@@ -231,7 +215,7 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
|
|||||||
|| (mark.row == u_row && mark.col > u_col)) {
|
|| (mark.row == u_row && mark.col > u_col)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ssize_t *del_status = map_ref(uint64_t, ssize_t)(delete_set, mark.id,
|
ssize_t *del_status = map_ref(uint64_t, ssize_t)(&delete_set, mark.id,
|
||||||
false);
|
false);
|
||||||
if (del_status) {
|
if (del_status) {
|
||||||
marktree_del_itr(buf->b_marktree, itr, false);
|
marktree_del_itr(buf->b_marktree, itr, false);
|
||||||
@@ -240,7 +224,7 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
|
|||||||
decor_redraw(buf, it.row1, mark.row, it.decor);
|
decor_redraw(buf, it.row1, mark.row, it.decor);
|
||||||
decor_free(it.decor);
|
decor_free(it.decor);
|
||||||
}
|
}
|
||||||
map_del(uint64_t, ssize_t)(delete_set, mark.id);
|
map_del(uint64_t, ssize_t)(&delete_set, mark.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +245,7 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
|
|||||||
kv_push(decors,
|
kv_push(decors,
|
||||||
((DecorItem) { .decor = item.decor, .row1 = mark.row }));
|
((DecorItem) { .decor = item.decor, .row1 = mark.row }));
|
||||||
}
|
}
|
||||||
map_put(uint64_t, ssize_t)(delete_set, other, decor_id);
|
map_put(uint64_t, ssize_t)(&delete_set, other, decor_id);
|
||||||
} else if (item.decor) {
|
} else if (item.decor) {
|
||||||
decor_redraw(buf, mark.row, mark.row, item.decor);
|
decor_redraw(buf, mark.row, mark.row, item.decor);
|
||||||
decor_free(item.decor);
|
decor_free(item.decor);
|
||||||
@@ -276,7 +260,7 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
|
|||||||
}
|
}
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
ssize_t decor_id;
|
ssize_t decor_id;
|
||||||
map_foreach(delete_set, id, decor_id, {
|
map_foreach((&delete_set), id, decor_id, {
|
||||||
mtpos_t pos = marktree_lookup(buf->b_marktree, id, itr);
|
mtpos_t pos = marktree_lookup(buf->b_marktree, id, itr);
|
||||||
assert(itr->node);
|
assert(itr->node);
|
||||||
marktree_del_itr(buf->b_marktree, itr, false);
|
marktree_del_itr(buf->b_marktree, itr, false);
|
||||||
@@ -286,7 +270,7 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
|
|||||||
decor_free(it.decor);
|
decor_free(it.decor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
map_clear(uint64_t, ssize_t)(delete_set);
|
map_clear(uint64_t, ssize_t)(&delete_set);
|
||||||
kv_size(decors) = 0;
|
kv_size(decors) = 0;
|
||||||
return marks_cleared;
|
return marks_cleared;
|
||||||
}
|
}
|
||||||
@@ -383,7 +367,7 @@ ExtmarkInfo extmark_from_id(buf_T *buf, uint64_t ns_id, uint64_t id)
|
|||||||
// free extmarks from the buffer
|
// free extmarks from the buffer
|
||||||
void extmark_free_all(buf_T *buf)
|
void extmark_free_all(buf_T *buf)
|
||||||
{
|
{
|
||||||
if (!buf->b_extmark_ns) {
|
if (!map_size(buf->b_extmark_ns)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,17 +379,17 @@ void extmark_free_all(buf_T *buf)
|
|||||||
|
|
||||||
map_foreach(buf->b_extmark_ns, id, ns, {
|
map_foreach(buf->b_extmark_ns, id, ns, {
|
||||||
(void)id;
|
(void)id;
|
||||||
map_free(uint64_t, uint64_t)(ns.map);
|
map_destroy(uint64_t, uint64_t)(ns.map);
|
||||||
});
|
});
|
||||||
map_free(uint64_t, ExtmarkNs)(buf->b_extmark_ns);
|
map_destroy(uint64_t, ExtmarkNs)(buf->b_extmark_ns);
|
||||||
buf->b_extmark_ns = NULL;
|
map_init(uint64_t, ExtmarkNs, buf->b_extmark_ns);
|
||||||
|
|
||||||
map_foreach(buf->b_extmark_index, id, item, {
|
map_foreach(buf->b_extmark_index, id, item, {
|
||||||
(void)id;
|
(void)id;
|
||||||
decor_free(item.decor);
|
decor_free(item.decor);
|
||||||
});
|
});
|
||||||
map_free(uint64_t, ExtmarkItem)(buf->b_extmark_index);
|
map_destroy(uint64_t, ExtmarkItem)(buf->b_extmark_index);
|
||||||
buf->b_extmark_index = NULL;
|
map_init(uint64_t, ExtmarkItem, buf->b_extmark_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -204,7 +204,7 @@ MAP_IMPL(ptr_t, ptr_t, DEFAULT_INITIALIZER)
|
|||||||
MAP_IMPL(uint64_t, ptr_t, DEFAULT_INITIALIZER)
|
MAP_IMPL(uint64_t, ptr_t, DEFAULT_INITIALIZER)
|
||||||
MAP_IMPL(uint64_t, ssize_t, SSIZE_INITIALIZER)
|
MAP_IMPL(uint64_t, ssize_t, SSIZE_INITIALIZER)
|
||||||
MAP_IMPL(uint64_t, uint64_t, DEFAULT_INITIALIZER)
|
MAP_IMPL(uint64_t, uint64_t, DEFAULT_INITIALIZER)
|
||||||
#define EXTMARK_NS_INITIALIZER { 0, 0 }
|
#define EXTMARK_NS_INITIALIZER { { MAP_INIT }, 1 }
|
||||||
MAP_IMPL(uint64_t, ExtmarkNs, EXTMARK_NS_INITIALIZER)
|
MAP_IMPL(uint64_t, ExtmarkNs, EXTMARK_NS_INITIALIZER)
|
||||||
#define EXTMARK_ITEM_INITIALIZER { 0, 0, NULL }
|
#define EXTMARK_ITEM_INITIALIZER { 0, 0, NULL }
|
||||||
MAP_IMPL(uint64_t, ExtmarkItem, EXTMARK_ITEM_INITIALIZER)
|
MAP_IMPL(uint64_t, ExtmarkItem, EXTMARK_ITEM_INITIALIZER)
|
||||||
|
@@ -46,7 +46,7 @@ MAP_DECLS(uint64_t, uint64_t)
|
|||||||
// NB: this is the only way to define a struct both containing and contained
|
// NB: this is the only way to define a struct both containing and contained
|
||||||
// in a map...
|
// in a map...
|
||||||
typedef struct ExtmarkNs { // For namespacing extmarks
|
typedef struct ExtmarkNs { // For namespacing extmarks
|
||||||
Map(uint64_t, uint64_t) *map; // For fast lookup
|
Map(uint64_t, uint64_t) map[1]; // For fast lookup
|
||||||
uint64_t free_id; // For automatically assigning id's
|
uint64_t free_id; // For automatically assigning id's
|
||||||
} ExtmarkNs;
|
} ExtmarkNs;
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ MAP_DECLS(String, handle_T)
|
|||||||
MAP_DECLS(ColorKey, ColorItem)
|
MAP_DECLS(ColorKey, ColorItem)
|
||||||
|
|
||||||
#define MAP_INIT { { 0, 0, 0, 0, NULL, NULL, NULL } }
|
#define MAP_INIT { { 0, 0, 0, 0, NULL, NULL, NULL } }
|
||||||
#define map_init(k, v, map) (*(map) = (Map(k, v))MAP_INIT)
|
#define map_init(k, v, map) do { *(map) = (Map(k, v))MAP_INIT; } while (false)
|
||||||
|
|
||||||
#define map_new(T, U) map_##T##_##U##_new
|
#define map_new(T, U) map_##T##_##U##_new
|
||||||
#define map_free(T, U) map_##T##_##U##_free
|
#define map_free(T, U) map_##T##_##U##_free
|
||||||
|
Reference in New Issue
Block a user