net.server_epoll: Optimize concatenation of exactly 2 buffer chunks
authorKim Alvefur <zash@zash.se>
Fri, 16 Jul 2021 15:40:08 +0200
changeset 11702 9a2a98621c73
parent 11701 6c3d8aa3bbd9
child 11703 1275dad71afd
net.server_epoll: Optimize concatenation of exactly 2 buffer chunks Saves a function call. I forget if I measured this kind of thing but IIRC infix concatenation is faster than a function call up to some number of items, but let's stop at 2 here.
net/server_epoll.lua
--- a/net/server_epoll.lua	Fri Jul 16 15:38:38 2021 +0200
+++ b/net/server_epoll.lua	Fri Jul 16 15:40:08 2021 +0200
@@ -473,8 +473,10 @@
 	local buffer = self.writebuffer;
 	local data = buffer or "";
 	if type(buffer) == "table" then
-		if buffer[2] then
+		if buffer[3] then
 			data = t_concat(data);
+		elseif buffer[2] then
+			data = buffer[1] .. buffer[2];
 		else
 			data = buffer[1] or "";
 		end