mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
perf(events): use hashy for event name lookup (#32802)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
local fileio_enum_file = arg[1]
|
local fileio_enum_file = arg[1]
|
||||||
local names_file = arg[2]
|
local names_file = arg[2]
|
||||||
|
|
||||||
|
local hashy = require('gen.hashy')
|
||||||
local auevents = require('nvim.auevents')
|
local auevents = require('nvim.auevents')
|
||||||
local events = auevents.events
|
local events = auevents.events
|
||||||
local aliases = auevents.aliases
|
local aliases = auevents.aliases
|
||||||
@@ -41,9 +42,27 @@ for i, name in ipairs(names) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
enum_tgt:write(('\n NUM_EVENTS = %u,'):format(#names))
|
enum_tgt:write(('\n NUM_EVENTS = %u,'):format(#names))
|
||||||
names_tgt:write('\n [NUM_EVENTS] = {0, NULL, (event_T)0},\n};\n')
|
|
||||||
names_tgt:write('\nstatic AutoCmdVec autocmds[NUM_EVENTS] = { 0 };\n')
|
|
||||||
names_tgt:close()
|
|
||||||
|
|
||||||
enum_tgt:write('\n} event_T;\n')
|
enum_tgt:write('\n} event_T;\n')
|
||||||
enum_tgt:close()
|
enum_tgt:close()
|
||||||
|
|
||||||
|
names_tgt:write('\n [NUM_EVENTS] = {0, NULL, (event_T)0},\n};\n')
|
||||||
|
names_tgt:write('\nstatic AutoCmdVec autocmds[NUM_EVENTS] = { 0 };\n')
|
||||||
|
|
||||||
|
local hashorder = vim.tbl_map(string.lower, names)
|
||||||
|
table.sort(hashorder)
|
||||||
|
local hashfun
|
||||||
|
hashorder, hashfun = hashy.hashy_hash('event_name2nr', hashorder, function(idx)
|
||||||
|
return 'event_names[event_hash[' .. idx .. ']].name'
|
||||||
|
end, true)
|
||||||
|
|
||||||
|
names_tgt:write([[
|
||||||
|
|
||||||
|
static const event_T event_hash[] = {]])
|
||||||
|
|
||||||
|
for _, lower_name in ipairs(hashorder) do
|
||||||
|
names_tgt:write(('\n EVENT_%s,'):format(lower_name:upper()))
|
||||||
|
end
|
||||||
|
|
||||||
|
names_tgt:write('\n};\n\n')
|
||||||
|
names_tgt:write('static ' .. hashfun)
|
||||||
|
names_tgt:close()
|
||||||
|
@@ -677,7 +677,7 @@ add_custom_command(OUTPUT ${GENERATED_FUNCS} ${FUNCS_DATA}
|
|||||||
|
|
||||||
add_custom_command(OUTPUT ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
|
add_custom_command(OUTPUT ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
|
||||||
COMMAND ${LUA_GEN} ${EVENTS_GENERATOR} ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
|
COMMAND ${LUA_GEN} ${EVENTS_GENERATOR} ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
|
||||||
DEPENDS ${LUA_GEN_DEPS} ${EVENTS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/auevents.lua
|
DEPENDS ${LUA_GEN_DEPS} ${EVENTS_GENERATOR} ${GENERATOR_HASHY} ${CMAKE_CURRENT_LIST_DIR}/auevents.lua
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_command(OUTPUT ${GENERATED_KEYCODE_NAMES}
|
add_custom_command(OUTPUT ${GENERATED_KEYCODE_NAMES}
|
||||||
|
@@ -618,36 +618,30 @@ bool is_aucmd_win(win_T *win)
|
|||||||
event_T event_name2nr(const char *start, char **end)
|
event_T event_name2nr(const char *start, char **end)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
int i;
|
|
||||||
|
|
||||||
// the event name ends with end of line, '|', a blank or a comma
|
// the event name ends with end of line, '|', a blank or a comma
|
||||||
for (p = start; *p && !ascii_iswhite(*p) && *p != ',' && *p != '|'; p++) {}
|
for (p = start; *p && !ascii_iswhite(*p) && *p != ',' && *p != '|'; p++) {}
|
||||||
for (i = 0; event_names[i].name != NULL; i++) {
|
|
||||||
int len = (int)event_names[i].len;
|
int hash_idx = event_name2nr_hash(start, (size_t)(p - start));
|
||||||
if (len == p - start && STRNICMP(event_names[i].name, start, len) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (*p == ',') {
|
if (*p == ',') {
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*end = (char *)p;
|
*end = (char *)p;
|
||||||
if (event_names[i].name == NULL) {
|
if (hash_idx < 0) {
|
||||||
return NUM_EVENTS;
|
return NUM_EVENTS;
|
||||||
}
|
}
|
||||||
return (event_T)abs(event_names[i].event);
|
return (event_T)abs(event_names[event_hash[hash_idx]].event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the event number for event name "str".
|
/// Return the event number for event name "str".
|
||||||
/// Return NUM_EVENTS if the event name was not found.
|
/// Return NUM_EVENTS if the event name was not found.
|
||||||
event_T event_name2nr_str(String str)
|
event_T event_name2nr_str(String str)
|
||||||
{
|
{
|
||||||
for (int i = 0; event_names[i].name != NULL; i++) {
|
int hash_idx = event_name2nr_hash(str.data, str.size);
|
||||||
if (str.size == event_names[i].len && STRNICMP(str.data, event_names[i].name, str.size) == 0) {
|
if (hash_idx < 0) {
|
||||||
return (event_T)abs(event_names[i].event);
|
return NUM_EVENTS;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return NUM_EVENTS;
|
return (event_T)abs(event_names[event_hash[hash_idx]].event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the name for event
|
/// Return the name for event
|
||||||
|
Reference in New Issue
Block a user