summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/util-tab.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/util-tab.lua')
-rw-r--r--tex/context/base/mkiv/util-tab.lua141
1 files changed, 55 insertions, 86 deletions
diff --git a/tex/context/base/mkiv/util-tab.lua b/tex/context/base/mkiv/util-tab.lua
index 0521a2a4f..fb2702228 100644
--- a/tex/context/base/mkiv/util-tab.lua
+++ b/tex/context/base/mkiv/util-tab.lua
@@ -564,99 +564,68 @@ local original_serialize = table.serialize -- the extensive one, the one we star
-- latest lua for the value of #n (with holes) .. anyway for tracing purposes we want
-- indices / keys being sorted, so it will never be real fast
-local function serialize(root,name,specification)
-
- if type(specification) == "table" then
- return original_serialize(root,name,specification) -- the original one
- end
-
- local t -- = { }
- local n = 1
- local unknown = false
-
--- local function simple_table(t)
--- local ts = #t
--- if ts > 0 then
--- local n = 0
--- for _, v in next, t do
--- n = n + 1
--- if type(v) == "table" then
+local is_simple_table = table.is_simple_table
+
+-- local function is_simple_table(t)
+-- local nt = #t
+-- if nt > 0 then
+-- local n = 0
+-- for _, v in next, t do
+-- n = n + 1
+-- if type(v) == "table" then
+-- return nil
+-- end
+-- end
+-- -- local haszero = t[0]
+-- local haszero = rawget(t,0) -- don't trigger meta
+-- if n == nt then
+-- local tt = { }
+-- for i=1,nt do
+-- local v = t[i]
+-- local tv = type(v)
+-- if tv == "number" then
+-- tt[i] = v -- not needed tostring(v)
+-- elseif tv == "string" then
+-- tt[i] = format("%q",v) -- f_string(v)
+-- elseif tv == "boolean" then
+-- tt[i] = v and "true" or "false"
+-- else
-- return nil
-- end
-- end
--- if n == ts then
--- local tt = { }
--- local nt = 0
--- for i=1,ts do
--- local v = t[i]
--- local tv = type(v)
--- nt = nt + 1
--- if tv == "number" then
--- tt[nt] = v
--- elseif tv == "string" then
--- tt[nt] = format("%q",v) -- f_string(v)
--- elseif tv == "boolean" then
--- tt[nt] = v and "true" or "false"
--- else
--- return nil
--- end
+-- return tt
+-- elseif haszero and (n == nt + 1) then
+-- local tt = { }
+-- for i=0,nt do
+-- local v = t[i]
+-- local tv = type(v)
+-- if tv == "number" then
+-- tt[i+1] = v -- not needed tostring(v)
+-- elseif tv == "string" then
+-- tt[i+1] = format("%q",v) -- f_string(v)
+-- elseif tv == "boolean" then
+-- tt[i+1] = v and "true" or "false"
+-- else
+-- return nil
-- end
--- return tt
-- end
+-- tt[1] = "[0] = " .. tt[1]
+-- return tt
-- end
--- return nil
-- end
+-- return nil
+-- end
- local function simple_table(t)
- local nt = #t
- if nt > 0 then
- local n = 0
- for _, v in next, t do
- n = n + 1
- if type(v) == "table" then
- return nil
- end
- end
- -- local haszero = t[0]
- local haszero = rawget(t,0) -- don't trigger meta
- if n == nt then
- local tt = { }
- for i=1,nt do
- local v = t[i]
- local tv = type(v)
- if tv == "number" then
- tt[i] = v -- not needed tostring(v)
- elseif tv == "string" then
- tt[i] = format("%q",v) -- f_string(v)
- elseif tv == "boolean" then
- tt[i] = v and "true" or "false"
- else
- return nil
- end
- end
- return tt
- elseif haszero and (n == nt + 1) then
- local tt = { }
- for i=0,nt do
- local v = t[i]
- local tv = type(v)
- if tv == "number" then
- tt[i+1] = v -- not needed tostring(v)
- elseif tv == "string" then
- tt[i+1] = format("%q",v) -- f_string(v)
- elseif tv == "boolean" then
- tt[i+1] = v and "true" or "false"
- else
- return nil
- end
- end
- tt[1] = "[0] = " .. tt[1]
- return tt
- end
- end
- return nil
+local function serialize(root,name,specification)
+
+ if type(specification) == "table" then
+ return original_serialize(root,name,specification) -- the original one
end
+ local t -- = { }
+ local n = 1
+ local unknown = false
+
local function do_serialize(root,name,depth,level,indexed)
if level > 0 then
n = n + 1
@@ -706,7 +675,7 @@ local function serialize(root,name,specification)
if next(v) == nil then -- tricky as next is unpredictable in a hash
n = n + 1 t[n] = f_val_not(depth)
else
- local st = simple_table(v)
+ local st = is_simple_table(v)
if st then
n = n + 1 t[n] = f_val_seq(depth,st)
else
@@ -750,7 +719,7 @@ local function serialize(root,name,specification)
n = n + 1 t[n] = f_key_str_value_not(depth,tostring(k))
end
else
- local st = simple_table(v)
+ local st = is_simple_table(v)
if not st then
do_serialize(v,k,depth,level+1)
elseif tk == "number" then
@@ -821,7 +790,7 @@ local function serialize(root,name,specification)
end
-- Let's forget about empty tables.
if next(root) ~= nil then
- local st = simple_table(root)
+ local st = is_simple_table(root)
if st then
return t[1] .. f_fin_seq(st) -- todo: move up and in one go
else