mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18:18 +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:
@@ -910,7 +910,7 @@ static void nlua_common_free_all_mem(lua_State *lstate)
|
||||
if (nlua_track_refs) {
|
||||
// in case there are leaked luarefs, leak the associated memory
|
||||
// to get LeakSanitizer stacktraces on exit
|
||||
pmap_destroy(handle_T)(&ref_state->ref_markers);
|
||||
map_destroy(int, &ref_state->ref_markers);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1285,7 +1285,7 @@ LuaRef nlua_ref(lua_State *lstate, nlua_ref_state_t *ref_state, int index)
|
||||
#ifdef NLUA_TRACK_REFS
|
||||
if (nlua_track_refs) {
|
||||
// dummy allocation to make LeakSanitizer track our luarefs
|
||||
pmap_put(handle_T)(&ref_state->ref_markers, ref, xmalloc(3));
|
||||
pmap_put(int)(&ref_state->ref_markers, ref, xmalloc(3));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1305,7 +1305,7 @@ void nlua_unref(lua_State *lstate, nlua_ref_state_t *ref_state, LuaRef ref)
|
||||
#ifdef NLUA_TRACK_REFS
|
||||
// NB: don't remove entry from map to track double-unref
|
||||
if (nlua_track_refs) {
|
||||
xfree(pmap_get(handle_T)(&ref_state->ref_markers, ref));
|
||||
xfree(pmap_get(int)(&ref_state->ref_markers, ref));
|
||||
}
|
||||
#endif
|
||||
luaL_unref(lstate, LUA_REGISTRYINDEX, ref);
|
||||
|
Reference in New Issue
Block a user