aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2022-03-18 16:39:48 +0100
committerKim Alvefur <zash@zash.se>2022-03-18 16:39:48 +0100
commitceea9b1788ea9f06314c6aeb493c3b63c7ca6c5e (patch)
treee4446e8c6dabe03feedac24d877d337df120b19e /util
parentca3d1e1958ed89da5147eee42096baae35c744da (diff)
downloadprosody-ceea9b1788ea9f06314c6aeb493c3b63c7ca6c5e.tar.gz
prosody-ceea9b1788ea9f06314c6aeb493c3b63c7ca6c5e.zip
util.stanza: Use table.move in clone
Code reduction, potentially a performance gain.
Diffstat (limited to 'util')
-rw-r--r--util/stanza.lua15
1 files changed, 6 insertions, 9 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index a38f80b3..9e249059 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -21,6 +21,7 @@ local type = type;
local s_gsub = string.gsub;
local s_sub = string.sub;
local s_find = string.find;
+local t_move = table.move or require "util.table".move;
local valid_utf8 = require "util.encodings".utf8.valid;
@@ -283,17 +284,13 @@ local function _clone(stanza, only_top)
for k,v in pairs(old_namespaces) do namespaces[k] = v; end
end
local new = { name = stanza.name, attr = attr, namespaces = namespaces, tags = tags };
+ setmetatable(new, stanza_mt);
if not only_top then
- for i=1,#stanza do
- local child = stanza[i];
- if child.name then
- child = _clone(child);
- t_insert(tags, child);
- end
- t_insert(new, child);
- end
+ t_move(stanza, 1, #stanza, 1, new);
+ t_move(stanza.tags, 1, #stanza.tags, 1, tags);
+ new:maptags(_clone);
end
- return setmetatable(new, stanza_mt);
+ return new;
end
local function clone(stanza, only_top)