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-registers.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'vis-registers.c') diff --git a/vis-registers.c b/vis-registers.c index 6e21a58..caecbd3 100644 --- a/vis-registers.c +++ b/vis-registers.c @@ -21,11 +21,6 @@ static Buffer *register_buffer(Register *reg, size_t slot) { return array_get(®->values, slot); } -static ssize_t read_buffer(void *context, char *data, size_t len) { - buffer_append(context, data, len); - return len; -} - bool register_init(Register *reg) { Buffer buf; buffer_init(&buf); @@ -83,7 +78,7 @@ const char *register_slot_get(Vis *vis, Register *reg, size_t slot, size_t *len) cmd[3] = "clipboard"; int status = vis_pipe(vis, vis->win->file, &(Filerange){ .start = 0, .end = 0 }, - cmd, buf, read_buffer, &buferr, read_buffer, false); + cmd, buf, read_into_buffer, &buferr, read_into_buffer, false); if (status != 0) vis_info_show(vis, "Command failed %s", buffer_content0(&buferr)); @@ -167,7 +162,7 @@ bool register_slot_put_range(Vis *vis, Register *reg, size_t slot, Text *txt, Fi cmd[3] = "clipboard"; int status = vis_pipe(vis, vis->win->file, range, - cmd, NULL, NULL, &buferr, read_buffer, false); + cmd, NULL, NULL, &buferr, read_into_buffer, false); if (status != 0) vis_info_show(vis, "Command failed %s", buffer_content0(&buferr)); -- cgit v1.2.3