From 1e52d33a3696016a7338d08c1c2bf6ef8f324e75 Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Sat, 4 Jan 2025 21:04:22 -0700 Subject: remove duplicated read_buffer functions When you take a pointer to a function in C that function is going to appear in full in the final binary. This means that there were 3 sections of the final binary with the exact same code. You could argue that in very high performance programs having that function closer to the current instruction when it is needed will give a performance boost but there are so many other places to gain more significant speed ups in vis before that would be remotely relevant. In fact, removing these allows the buffer_append call to inlined so that buffer_insert can be hopped to directly instead of including a useless hop in the middle. --- vis.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'vis.c') diff --git a/vis.c b/vis.c index d1c0dab..c059a48 100644 --- a/vis.c +++ b/vis.c @@ -1854,18 +1854,13 @@ int vis_pipe_buf(Vis *vis, const char* buf, const char *argv[], return _vis_pipe(vis, NULL, NULL, buf, argv, stdout_context, read_stdout, stderr_context, read_stderr, fullscreen); } -static ssize_t read_buffer(void *context, char *data, size_t len) { - buffer_append(context, data, len); - return len; -} - static int _vis_pipe_collect(Vis *vis, File *file, Filerange *range, const char* buf, const char *argv[], char **out, char **err, bool fullscreen) { Buffer bufout, buferr; buffer_init(&bufout); buffer_init(&buferr); int status = _vis_pipe(vis, file, range, buf, argv, - &bufout, out ? read_buffer : NULL, - &buferr, err ? read_buffer : NULL, + &bufout, out ? read_into_buffer : NULL, + &buferr, err ? read_into_buffer : NULL, fullscreen); buffer_terminate(&bufout); buffer_terminate(&buferr); -- cgit v1.2.3