aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-11-26 05:23:37 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-11-26 05:23:37 +0500
commit539b221189ad1bd611fd4e3d72bda98f8881f632 (patch)
treea5e7725ac2f2792d43f0b7eaf49ee7a8704ac020 /util
parentf55acdb2a9747045b39d3690f52a892d6440cc27 (diff)
downloadprosody-539b221189ad1bd611fd4e3d72bda98f8881f632.tar.gz
prosody-539b221189ad1bd611fd4e3d72bda98f8881f632.zip
util.stanza, util.xmppstream, core.xmlhandlers: Allow stanza.last_add to be nil, and set it nil by default. Saves a table allocation per-element. 20% faster stanza building.
Diffstat (limited to 'util')
-rw-r--r--util/stanza.lua25
-rw-r--r--util/xmppstream.lua3
2 files changed, 14 insertions, 14 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index 28e26e0a..307a858a 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -46,7 +46,7 @@ stanza_mt = { __type = "stanza" };
stanza_mt.__index = stanza_mt;
function stanza(name, attr)
- local stanza = { name = name, attr = attr or {}, tags = {}, last_add = {}};
+ local stanza = { name = name, attr = attr or {}, tags = {} };
return setmetatable(stanza, stanza_mt);
end
@@ -60,26 +60,27 @@ end
function stanza_mt:tag(name, attrs)
local s = stanza(name, attrs);
- (self.last_add[#self.last_add] or self):add_direct_child(s);
- t_insert(self.last_add, s);
+ local last_add = self.last_add;
+ if not last_add then last_add = {}; self.last_add = last_add; end
+ (last_add[#last_add] or self):add_direct_child(s);
+ t_insert(last_add, s);
return self;
end
function stanza_mt:text(text)
- (self.last_add[#self.last_add] or self):add_direct_child(text);
+ local last_add = self.last_add;
+ (last_add and last_add[#last_add] or self):add_direct_child(text);
return self;
end
function stanza_mt:up()
- t_remove(self.last_add);
+ local last_add = self.last_add;
+ if last_add then t_remove(last_add); end
return self;
end
function stanza_mt:reset()
- local last_add = self.last_add;
- for i = 1,#last_add do
- last_add[i] = nil;
- end
+ self.last_add = nil;
return self;
end
@@ -91,7 +92,8 @@ function stanza_mt:add_direct_child(child)
end
function stanza_mt:add_child(child)
- (self.last_add[#self.last_add] or self):add_direct_child(child);
+ local last_add = self.last_add;
+ (last_add and last_add[#last_add] or self):add_direct_child(child);
return self;
end
@@ -311,9 +313,6 @@ function deserialize(stanza)
end
end
stanza.tags = tags;
- if not stanza.last_add then
- stanza.last_add = {};
- end
end
end
diff --git a/util/xmppstream.lua b/util/xmppstream.lua
index 0a6d554b..29095e41 100644
--- a/util/xmppstream.lua
+++ b/util/xmppstream.lua
@@ -117,7 +117,8 @@ function new_sax_handlers(session, stream_callbacks)
chardata = {};
end
-- Complete stanza
- if #stanza.last_add == 0 then
+ local last_add = stanza.last_add;
+ if not last_add or #last_add == 0 then
if tagname ~= stream_error_tag then
cb_handlestanza(session, stanza);
else