aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/event
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-12-01 15:22:22 +0800
committerGitHub <noreply@github.com>2023-12-01 15:22:22 +0800
commit548f03c66c08d0235d62505e884e8088bfda1804 (patch)
tree2c524d5d4561e600ca38c5072e9ae5df2cbd8672 /src/nvim/event
parent130cb4815a5c6625a938b1e93a7d60d7a38ad8dd (diff)
downloadrneovim-548f03c66c08d0235d62505e884e8088bfda1804.tar.gz
rneovim-548f03c66c08d0235d62505e884e8088bfda1804.tar.bz2
rneovim-548f03c66c08d0235d62505e884e8088bfda1804.zip
refactor: change event_create() to a macro (#26343)
A varargs functions can never be inlined, so a macro is faster.
Diffstat (limited to 'src/nvim/event')
-rw-r--r--src/nvim/event/defs.h24
-rw-r--r--src/nvim/event/loop.c2
-rw-r--r--src/nvim/event/loop.h6
-rw-r--r--src/nvim/event/multiqueue.c2
-rw-r--r--src/nvim/event/multiqueue.h4
-rw-r--r--src/nvim/event/process.c10
-rw-r--r--src/nvim/event/rstream.c8
-rw-r--r--src/nvim/event/signal.c2
-rw-r--r--src/nvim/event/socket.c3
-rw-r--r--src/nvim/event/time.c4
10 files changed, 21 insertions, 44 deletions
diff --git a/src/nvim/event/defs.h b/src/nvim/event/defs.h
index 11563b99b6..56e00171e2 100644
--- a/src/nvim/event/defs.h
+++ b/src/nvim/event/defs.h
@@ -6,29 +6,9 @@
enum { EVENT_HANDLER_MAX_ARGC = 10, };
typedef void (*argv_callback)(void **argv);
-typedef struct message {
+typedef struct {
argv_callback handler;
void *argv[EVENT_HANDLER_MAX_ARGC];
} Event;
-#define VA_EVENT_INIT(event, h, a) \
- do { \
- assert(a <= EVENT_HANDLER_MAX_ARGC); \
- (event)->handler = h; \
- if (a) { \
- va_list args; \
- va_start(args, a); \
- for (int i = 0; i < a; i++) { \
- (event)->argv[i] = va_arg(args, void *); \
- } \
- va_end(args); \
- } \
- } while (0)
-
-static inline Event event_create(argv_callback cb, int argc, ...)
-{
- assert(argc <= EVENT_HANDLER_MAX_ARGC);
- Event event;
- VA_EVENT_INIT(&event, cb, argc);
- return event;
-}
+#define event_create(cb, ...) ((Event){ .handler = cb, .argv = { __VA_ARGS__ } })
diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c
index d61666e6d4..697bdb7aa8 100644
--- a/src/nvim/event/loop.c
+++ b/src/nvim/event/loop.c
@@ -111,7 +111,7 @@ void loop_schedule_deferred(Loop *loop, Event event)
{
Event *eventp = xmalloc(sizeof(*eventp));
*eventp = event;
- loop_schedule_fast(loop, event_create(loop_deferred_event, 2, loop, eventp));
+ loop_schedule_fast(loop, event_create(loop_deferred_event, loop, eventp));
}
static void loop_deferred_event(void **argv)
{
diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h
index 5665332e95..442a159631 100644
--- a/src/nvim/event/loop.h
+++ b/src/nvim/event/loop.h
@@ -44,12 +44,12 @@ typedef struct loop {
bool closing; ///< Set to true if loop_close() has been called
} Loop;
-#define CREATE_EVENT(multiqueue, handler, argc, ...) \
+#define CREATE_EVENT(multiqueue, handler, ...) \
do { \
if (multiqueue) { \
- multiqueue_put((multiqueue), (handler), argc, __VA_ARGS__); \
+ multiqueue_put((multiqueue), (handler), __VA_ARGS__); \
} else { \
- void *argv[argc] = { __VA_ARGS__ }; \
+ void *argv[] = { __VA_ARGS__ }; \
(handler)(argv); \
} \
} while (0)
diff --git a/src/nvim/event/multiqueue.c b/src/nvim/event/multiqueue.c
index 677b7e8e6a..fd6f88153b 100644
--- a/src/nvim/event/multiqueue.c
+++ b/src/nvim/event/multiqueue.c
@@ -260,7 +260,7 @@ Event event_create_oneshot(Event ev, int num)
data->event = ev;
data->fired = false;
data->refcount = num;
- return event_create(multiqueue_oneshot_event, 1, data);
+ return event_create(multiqueue_oneshot_event, data);
}
static void multiqueue_oneshot_event(void **argv)
{
diff --git a/src/nvim/event/multiqueue.h b/src/nvim/event/multiqueue.h
index e01ee1e710..7de307f77e 100644
--- a/src/nvim/event/multiqueue.h
+++ b/src/nvim/event/multiqueue.h
@@ -9,7 +9,9 @@ typedef struct multiqueue MultiQueue;
typedef void (*PutCallback)(MultiQueue *multiq, void *data);
#define multiqueue_put(q, h, ...) \
- multiqueue_put_event(q, event_create(h, __VA_ARGS__));
+ do { \
+ multiqueue_put_event(q, event_create(h, __VA_ARGS__)); \
+ } while (0)
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/multiqueue.h.generated.h"
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c
index b69612337c..ac9c4973ce 100644
--- a/src/nvim/event/process.c
+++ b/src/nvim/event/process.c
@@ -132,7 +132,7 @@ void process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL
Process *proc = (*current)->data;
if (proc->detach || proc->type == kProcessTypePty) {
// Close handles to process without killing it.
- CREATE_EVENT(loop->events, process_close_handles, 1, proc);
+ CREATE_EVENT(loop->events, process_close_handles, proc);
} else {
process_stop(proc);
}
@@ -300,7 +300,7 @@ static void decref(Process *proc)
}
assert(node);
kl_shift_at(WatcherPtr, loop->children, node);
- CREATE_EVENT(proc->events, process_close_event, 1, proc);
+ CREATE_EVENT(proc->events, process_close_event, proc);
}
static void process_close(Process *proc)
@@ -395,7 +395,7 @@ static void process_close_handles(void **argv)
static void exit_delay_cb(uv_timer_t *handle)
{
uv_timer_stop(&main_loop.exit_delay_timer);
- multiqueue_put(main_loop.fast_events, exit_event, 1, main_loop.exit_delay_timer.data);
+ multiqueue_put(main_loop.fast_events, exit_event, main_loop.exit_delay_timer.data);
}
static void exit_event(void **argv)
@@ -420,7 +420,7 @@ static void exit_event(void **argv)
void exit_from_channel(int status)
{
- multiqueue_put(main_loop.fast_events, exit_event, 1, status);
+ multiqueue_put(main_loop.fast_events, exit_event, (void *)(intptr_t)status);
}
static void on_process_exit(Process *proc)
@@ -438,7 +438,7 @@ static void on_process_exit(Process *proc)
// more data directly. Instead delay the reading after the libuv loop by
// queueing process_close_handles() as an event.
MultiQueue *queue = proc->events ? proc->events : loop->events;
- CREATE_EVENT(queue, process_close_handles, 1, proc);
+ CREATE_EVENT(queue, process_close_handles, proc);
}
static void on_process_stream_close(Stream *stream, void *data)
diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c
index 88363e86e9..130c080db5 100644
--- a/src/nvim/event/rstream.c
+++ b/src/nvim/event/rstream.c
@@ -200,10 +200,6 @@ static void invoke_read_cb(Stream *stream, size_t count, bool eof)
// Don't let the stream be closed before the event is processed.
stream->pending_reqs++;
- CREATE_EVENT(stream->events,
- read_event,
- 3,
- stream,
- (void *)(uintptr_t *)count,
- (void *)(uintptr_t)eof);
+ CREATE_EVENT(stream->events, read_event,
+ stream, (void *)(uintptr_t *)count, (void *)(uintptr_t)eof);
}
diff --git a/src/nvim/event/signal.c b/src/nvim/event/signal.c
index 07223be987..2d6cccf53a 100644
--- a/src/nvim/event/signal.c
+++ b/src/nvim/event/signal.c
@@ -47,7 +47,7 @@ static void signal_event(void **argv)
static void signal_watcher_cb(uv_signal_t *handle, int signum)
{
SignalWatcher *watcher = handle->data;
- CREATE_EVENT(watcher->events, signal_event, 1, watcher);
+ CREATE_EVENT(watcher->events, signal_event, watcher);
}
static void close_cb(uv_handle_t *handle)
diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c
index c90b177eb7..cde53a00e1 100644
--- a/src/nvim/event/socket.c
+++ b/src/nvim/event/socket.c
@@ -174,8 +174,7 @@ static void connection_event(void **argv)
static void connection_cb(uv_stream_t *handle, int status)
{
SocketWatcher *watcher = handle->data;
- CREATE_EVENT(watcher->events, connection_event, 2, watcher,
- (void *)(uintptr_t)status);
+ CREATE_EVENT(watcher->events, connection_event, watcher, (void *)(uintptr_t)status);
}
static void close_cb(uv_handle_t *handle)
diff --git a/src/nvim/event/time.c b/src/nvim/event/time.c
index 0b624d9547..7206d74176 100644
--- a/src/nvim/event/time.c
+++ b/src/nvim/event/time.c
@@ -52,7 +52,7 @@ static void time_watcher_cb(uv_timer_t *handle)
// the timer blocked and there already is an unprocessed event waiting
return;
}
- CREATE_EVENT(watcher->events, time_event, 1, watcher);
+ CREATE_EVENT(watcher->events, time_event, watcher);
}
static void close_event(void **argv)
@@ -66,6 +66,6 @@ static void close_cb(uv_handle_t *handle)
{
TimeWatcher *watcher = handle->data;
if (watcher->close_cb) {
- CREATE_EVENT(watcher->events, close_event, 1, watcher);
+ CREATE_EVENT(watcher->events, close_event, watcher);
}
}