Optimized encoding of arrays containing nil values

Optimized inline documentation
This commit is contained in:
Steven Barth 2008-08-29 13:44:33 +00:00
parent bda994c32e
commit b6e397e1a4

View file

@ -56,6 +56,7 @@ local next = next
local getmetatable = getmetatable local getmetatable = getmetatable
--- LuCI JSON-Library --- LuCI JSON-Library
-- @cstyle instance
module "luci.json" module "luci.json"
--- Null replacement function --- Null replacement function
@ -64,16 +65,15 @@ function null()
return null return null
end end
--- JSON-Encoder --- Create a new JSON-Encoder.
-- @class module -- @class function
-- @cstyle instance -- @name Encoder
-- @name luci.json.Encoder
Encoder = util.class()
--- Creates a new Encoder.
-- @param data Lua-Object to be encoded. -- @param data Lua-Object to be encoded.
-- @param buffersize Blocksize of returned data source. -- @param buffersize Blocksize of returned data source.
-- @param fastescape Use non-standard escaping (don't escape control chars) -- @param fastescape Use non-standard escaping (don't escape control chars)
-- @return JSON-Encoder
Encoder = util.class()
function Encoder.__init__(self, data, buffersize, fastescape) function Encoder.__init__(self, data, buffersize, fastescape)
self.data = data self.data = data
self.buffersize = buffersize or 512 self.buffersize = buffersize or 512
@ -184,10 +184,10 @@ function Encoder.parse_iter(self, obj)
local first = true local first = true
if type(obj) == "table" then if type(obj) == "table" then
for i, entry in pairs(obj) do for i=1, #obj do
first = first or self:put(",") first = first or self:put(",")
first = first and nil first = first and nil
self:dispatch(entry) self:dispatch(obj[i])
end end
else else
for entry in obj do for entry in obj do
@ -211,14 +211,13 @@ Encoder.parsers = {
} }
--- JSON-Decoder --- Create a new JSON-Decoder.
-- @class module -- @class function
-- @cstyle instance -- @name Decoder
-- @name luci.json.Decoder -- @param customnull Use luci.json.null instead of nil for decoding null
-- @return JSON-Decoder
Decoder = util.class() Decoder = util.class()
--- Create a new Decoder object.
-- @param customnull Use luci.json.null instead of nil
function Decoder.__init__(self, customnull) function Decoder.__init__(self, customnull)
self.cnull = customnull self.cnull = customnull
getmetatable(self).__call = Decoder.sink getmetatable(self).__call = Decoder.sink