diff options
author | Kim Alvefur <zash@zash.se> | 2019-03-17 20:40:01 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-03-17 20:40:01 +0100 |
commit | cffb6e6e7bf6c2178ab8dafd092f59c0b521d69b (patch) | |
tree | e72a94bcbc46c7b61bf6c80cd171fbf91c677dc1 /util/serialization.lua | |
parent | 62f33cd891e824a8d9c5a99c5d1a51af6c23835d (diff) | |
download | prosody-cffb6e6e7bf6c2178ab8dafd092f59c0b521d69b.tar.gz prosody-cffb6e6e7bf6c2178ab8dafd092f59c0b521d69b.zip |
util.serialization: Optimize handling of last table separator
Fewer next() calls and a step towards allowing use of a different iterator.
Diffstat (limited to 'util/serialization.lua')
-rw-r--r-- | util/serialization.lua | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/util/serialization.lua b/util/serialization.lua index 7ae77a3a..c64bfec1 100644 --- a/util/serialization.lua +++ b/util/serialization.lua @@ -163,7 +163,9 @@ local function new(opt) local indent = s_rep(indentwith, d); local numkey = 1; local ktyp, vtyp; + local had_items = false; for k,v in next,t do + had_items = true; o[l], l = itemstart, l + 1; o[l], l = indent, l + 1; ktyp, vtyp = type(k), type(v); @@ -194,14 +196,10 @@ local function new(opt) else o[l], l = ser(v), l + 1; end - -- last item? - if next(t, k) ~= nil then - o[l], l = itemsep, l + 1; - else - o[l], l = itemlast, l + 1; - end + o[l], l = itemsep, l + 1; end - if next(t) ~= nil then + if had_items then + o[l - 1] = itemlast; o[l], l = s_rep(indentwith, d-1), l + 1; end o[l], l = tend, l +1; |