# HG changeset patch # User Kim Alvefur # Date 1647617988 -3600 # Node ID a3ddf3f422121f265befe27571fffea3f565eecb # Parent 308ed64dc69b92e020142c8ed9a40bb8b052abfb util.stanza: Use table.move in clone Code reduction, potentially a performance gain. diff -r 308ed64dc69b -r a3ddf3f42212 util/stanza.lua --- a/util/stanza.lua Fri Mar 18 15:29:05 2022 +0000 +++ b/util/stanza.lua Fri Mar 18 16:39:48 2022 +0100 @@ -21,6 +21,7 @@ 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 @@ 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)