aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-12-28 06:18:58 +0100
committerKim Alvefur <zash@zash.se>2019-12-28 06:18:58 +0100
commitd20b12c208ec42372f5cd24ac1334e347762085a (patch)
treebb561987b123cc8e7b6681b02ac0ebc29fcb9b3c
parentf34d9adabdad785332aa1ace067ad9d384718769 (diff)
downloadprosody-d20b12c208ec42372f5cd24ac1334e347762085a.tar.gz
prosody-d20b12c208ec42372f5cd24ac1334e347762085a.zip
net.server_epoll: Avoid concatenating buffer with single item
Saves creating a string that'll be identical to buffer[1] anyways, as well as a C function call. Depending on Lua version and length of the string, this could be reusing an interned string, but a longer one would probably be duplicated for no reason. Having exactly one item in the buffer seems like it would be fairly common, but I have not done an extensive study. If opportunistic writes are enabled then it will be even more likely. This special case could be optimized like this in table.concat but it does not look like it is.
-rw-r--r--net/server_epoll.lua2
1 files changed, 1 insertions, 1 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index e2c5f977..4ad142ce 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -408,7 +408,7 @@ function interface:onwritable()
self:onconnect();
if not self.conn then return; end -- could have been closed in onconnect
local buffer = self.writebuffer;
- local data = t_concat(buffer);
+ local data = #buffer == 1 and buffer[1] or t_concat(buffer);
local ok, err, partial = self.conn:send(data);
if ok then
self:set(nil, false);