aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-08-22 10:41:18 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2021-08-22 10:46:04 +0200
commitb888018aed249174aad7586859ac5142f1a3ef10 (patch)
treeb9d09498bce6dd8852363f3acae71324be03ca4b
parentb2277a42790907424ed2cd37d3d991650bb88441 (diff)
downloadrneovim-b888018aed249174aad7586859ac5142f1a3ef10.tar.gz
rneovim-b888018aed249174aad7586859ac5142f1a3ef10.tar.bz2
rneovim-b888018aed249174aad7586859ac5142f1a3ef10.zip
refactor(marktree): embed the keymap in the MarkTree struct
-rw-r--r--src/nvim/map.h2
-rw-r--r--src/nvim/marktree.c7
-rw-r--r--src/nvim/marktree.h2
3 files changed, 6 insertions, 5 deletions
diff --git a/src/nvim/map.h b/src/nvim/map.h
index 7d77a229c5..6dc36f77ac 100644
--- a/src/nvim/map.h
+++ b/src/nvim/map.h
@@ -77,6 +77,7 @@ MAP_DECLS(ColorKey, ColorItem)
#define pmap_new(T) map_new(T, ptr_t)
#define pmap_free(T) map_free(T, ptr_t)
+#define pmap_destroy(T) map_destroy(T, ptr_t)
#define pmap_get(T) map_get(T, ptr_t)
#define pmap_has(T) map_has(T, ptr_t)
#define pmap_key(T) map_key(T, ptr_t)
@@ -85,6 +86,7 @@ MAP_DECLS(ColorKey, ColorItem)
/// @see pmap_del2
#define pmap_del(T) map_del(T, ptr_t)
#define pmap_clear(T) map_clear(T, ptr_t)
+#define pmap_init(k, map) map_init(k, ptr_t, map)
#define map_foreach(map, key, value, block) \
kh_foreach(&map->table, key, value, block)
diff --git a/src/nvim/marktree.c b/src/nvim/marktree.c
index d0d843cbf8..a04f250fc3 100644
--- a/src/nvim/marktree.c
+++ b/src/nvim/marktree.c
@@ -250,7 +250,6 @@ void marktree_put_key(MarkTree *b, int row, int col, uint64_t id)
if (!b->root) {
b->root = (mtnode_t *)xcalloc(1, ILEN);
- b->id2node = pmap_new(uint64_t)();
b->n_nodes++;
}
mtnode_t *r, *s;
@@ -547,9 +546,9 @@ void marktree_clear(MarkTree *b)
marktree_free_node(b->root);
b->root = NULL;
}
- if (b->id2node) {
- pmap_free(uint64_t)(b->id2node);
- b->id2node = NULL;
+ if (b->id2node->table.keys) {
+ pmap_destroy(uint64_t)(b->id2node);
+ pmap_init(uint64_t, b->id2node);
}
b->n_keys = 0;
b->n_nodes = 0;
diff --git a/src/nvim/marktree.h b/src/nvim/marktree.h
index 3b83e3c44d..7af23765c3 100644
--- a/src/nvim/marktree.h
+++ b/src/nvim/marktree.h
@@ -63,7 +63,7 @@ typedef struct {
uint64_t next_id;
// TODO(bfredl): the pointer to node could be part of the larger
// Map(uint64_t, ExtmarkItem) essentially;
- PMap(uint64_t) *id2node;
+ PMap(uint64_t) id2node[1];
} MarkTree;