aboutsummaryrefslogtreecommitdiffstats
path: root/util/stanza.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2011-02-20 19:16:56 +0500
committerWaqas Hussain <waqas20@gmail.com>2011-02-20 19:16:56 +0500
commit78b3e4e756687dac5b747f4a4e9cf83091b9f9de (patch)
tree5cf87ae56a59bdb5635c01df7c39df7c7f2b0ddb /util/stanza.lua
parent87b53fccc2608de5657663610186a6a78c7adcce (diff)
downloadprosody-78b3e4e756687dac5b747f4a4e9cf83091b9f9de.tar.gz
prosody-78b3e4e756687dac5b747f4a4e9cf83091b9f9de.zip
util.stanza: Rewrite clone() to be more optimized.
Diffstat (limited to 'util/stanza.lua')
-rw-r--r--util/stanza.lua27
1 files changed, 12 insertions, 15 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index ca79a728..de83977f 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -320,24 +320,21 @@ function deserialize(stanza)
return stanza;
end
-function clone(stanza)
- local lookup_table = {};
- local function _copy(object)
- if type(object) ~= "table" then
- return object;
- elseif lookup_table[object] then
- return lookup_table[object];
+local function _clone(stanza)
+ local attr, tags = {}, {};
+ for k,v in pairs(stanza.attr) do attr[k] = v; end
+ local new = { name = stanza.name, attr = attr, tags = tags };
+ for i=1,#stanza do
+ local child = stanza[i];
+ if child.name then
+ child = _clone(child);
+ t_insert(tags, child);
end
- local new_table = {};
- lookup_table[object] = new_table;
- for index, value in pairs(object) do
- new_table[_copy(index)] = _copy(value);
- end
- return setmetatable(new_table, getmetatable(object));
+ t_insert(new, child);
end
-
- return _copy(stanza)
+ return setmetatable(new, stanza_mt);
end
+clone = _clone;
function message(attr, body)
if not body then