mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 03:46:31 +00:00
refactor(map): avoid duplicated khash_t types for values
This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before.
This commit is contained in:
@@ -169,7 +169,7 @@ static VTermScreenCallbacks vterm_screen_callbacks = {
|
||||
.sb_popline = term_sb_pop,
|
||||
};
|
||||
|
||||
static PMap(ptr_t) invalidated_terminals = MAP_INIT;
|
||||
static Set(ptr_t) invalidated_terminals = SET_INIT;
|
||||
|
||||
void terminal_init(void)
|
||||
{
|
||||
@@ -183,10 +183,10 @@ void terminal_teardown(void)
|
||||
time_watcher_stop(&refresh_timer);
|
||||
multiqueue_free(refresh_timer.events);
|
||||
time_watcher_close(&refresh_timer, NULL);
|
||||
pmap_destroy(ptr_t)(&invalidated_terminals);
|
||||
set_destroy(ptr_t, &invalidated_terminals);
|
||||
// terminal_destroy might be called after terminal_teardown is invoked
|
||||
// make sure it is in an empty, valid state
|
||||
pmap_init(ptr_t, &invalidated_terminals);
|
||||
invalidated_terminals = (Set(ptr_t)) SET_INIT;
|
||||
}
|
||||
|
||||
static void term_output_callback(const char *s, size_t len, void *user_data)
|
||||
@@ -652,12 +652,12 @@ void terminal_destroy(Terminal **termpp)
|
||||
}
|
||||
|
||||
if (!term->refcount) {
|
||||
if (pmap_has(ptr_t)(&invalidated_terminals, term)) {
|
||||
if (set_has(ptr_t, &invalidated_terminals, term)) {
|
||||
// flush any pending changes to the buffer
|
||||
block_autocmds();
|
||||
refresh_terminal(term);
|
||||
unblock_autocmds();
|
||||
pmap_del(ptr_t)(&invalidated_terminals, term);
|
||||
set_del(ptr_t, &invalidated_terminals, term);
|
||||
}
|
||||
for (size_t i = 0; i < term->sb_current; i++) {
|
||||
xfree(term->sb_buffer[i]);
|
||||
@@ -1027,7 +1027,7 @@ static int term_sb_push(int cols, const VTermScreenCell *cells, void *data)
|
||||
}
|
||||
|
||||
memcpy(sbrow->cells, cells, sizeof(cells[0]) * c);
|
||||
pmap_put(ptr_t)(&invalidated_terminals, term, NULL);
|
||||
set_put(ptr_t, &invalidated_terminals, term);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1068,7 +1068,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data)
|
||||
}
|
||||
|
||||
xfree(sbrow);
|
||||
pmap_put(ptr_t)(&invalidated_terminals, term, NULL);
|
||||
set_put(ptr_t, &invalidated_terminals, term);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1524,7 +1524,7 @@ static void invalidate_terminal(Terminal *term, int start_row, int end_row)
|
||||
term->invalid_end = MAX(term->invalid_end, end_row);
|
||||
}
|
||||
|
||||
pmap_put(ptr_t)(&invalidated_terminals, term, NULL);
|
||||
set_put(ptr_t, &invalidated_terminals, term);
|
||||
if (!refresh_pending) {
|
||||
time_watcher_start(&refresh_timer, refresh_timer_cb, REFRESH_DELAY, 0);
|
||||
refresh_pending = true;
|
||||
@@ -1567,10 +1567,10 @@ static void refresh_timer_cb(TimeWatcher *watcher, void *data)
|
||||
void *stub; (void)(stub);
|
||||
// don't process autocommands while updating terminal buffers
|
||||
block_autocmds();
|
||||
map_foreach(&invalidated_terminals, term, stub, {
|
||||
set_foreach(&invalidated_terminals, term, {
|
||||
refresh_terminal(term);
|
||||
});
|
||||
pmap_clear(ptr_t)(&invalidated_terminals);
|
||||
set_clear(ptr_t, &invalidated_terminals);
|
||||
unblock_autocmds();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user