From 65dd46e0bba74948c824370a06e509cba462cd72 Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Mon, 1 Dec 2025 22:08:13 -0700 Subject: main: make vis instance into a global This might be controversial to some but for the purposes of the editor there will never be more than one instance of vis. This allows the compiler to use more efficient rip relative addressing in the places where it knows the code is referring to the global instance. Once the code is compiling in a single translation unit with all functions declared static this will allow for much better optimization. From the perspective that vis is meant to be a library, which is what Marc clearly intended, changing vis_new() to vis_init() and vis_free() to vis_cleanup() is still better design. The library user should be allowed to place the vis instance wherever they want in memory. --- main.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 03a5918..953f6e4 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,8 @@ #include "array.h" #include "buffer.h" +static Vis vis[1]; + #define PAGE INT_MAX #define PAGE_HALF (INT_MAX-1) @@ -207,6 +209,10 @@ typedef enum { KEY_ACTION_LIST(ENUM) } VisActionKind; #undef ENUM +/* NOTE: must conform to the vis library signature, but we can rename the parameters */ +#undef KEY_ACTION_FN +#define KEY_ACTION_FN(name) const char *name(Vis *_unused, const char *keys, const Arg *arg) + /** key bindings functions */ static KEY_ACTION_FN(ka_nop) @@ -1271,8 +1277,6 @@ static KEY_ACTION_FN(ka_jumplist) return keys; } -static Vis *vis; - static void signal_handler(int signum, siginfo_t *siginfo, void *context) { vis_signal_handler(vis, signum, siginfo, context); } @@ -1283,7 +1287,8 @@ static const KeyAction vis_action[] = { KEY_ACTION_LIST(KEY_ACTION_STRUCT) }; #include "config.h" -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ for (int i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; @@ -1306,8 +1311,7 @@ int main(int argc, char *argv[]) { } } - vis = vis_new(); - if (!vis) + if (!vis_init(vis)) return EXIT_FAILURE; vis_event_emit(vis, VIS_EVENT_INIT); @@ -1403,6 +1407,6 @@ int main(int argc, char *argv[]) { } int status = vis_run(vis); - vis_free(vis); + vis_cleanup(vis); return status; } -- cgit v1.2.3