From da8162d4e816cf49d9790a1c81556b499f442bed Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 22 Jun 2018 16:42:14 +0200 Subject: 2018-06-22 16:02:00 --- tex/context/base/mkiv/strc-doc.lua | 60 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'tex/context/base/mkiv/strc-doc.lua') diff --git a/tex/context/base/mkiv/strc-doc.lua b/tex/context/base/mkiv/strc-doc.lua index 80e41451e..f2674ea5a 100644 --- a/tex/context/base/mkiv/strc-doc.lua +++ b/tex/context/base/mkiv/strc-doc.lua @@ -124,12 +124,16 @@ local tobesaved = allocate() sections.collected = collected sections.tobesaved = tobesaved --- local function initializer() --- collected = sections.collected --- tobesaved = sections.tobesaved --- end --- --- job.register('structures.sections.collected', tobesaved, initializer) +-- We have to save this mostly redundant list because we can have (rare) +-- cases with own numbers that don't end up in the list so we get out of +-- sync when we use (*). + +local function initializer() + collected = sections.collected + tobesaved = sections.tobesaved +end + +job.register('structures.sections.collected', tobesaved, initializer) local registered = sections.registered or allocate() sections.registered = registered @@ -160,7 +164,7 @@ end local lastsaved = 0 function sections.save(sectiondata) --- local sectionnumber = helpers.simplify(section.sectiondata) -- maybe done earlier +local sectiondata = helpers.simplify(sectiondata) -- maybe done earlier local numberdata = sectiondata.numberdata local ntobesaved = #tobesaved if not numberdata or sectiondata.metadata.nolist then @@ -180,28 +184,28 @@ function sections.currentsectionindex() return lastsaved -- only for special controlled situations end -function sections.load() - setmetatableindex(collected,nil) - local lists = lists.collected - for i=1,#lists do - local list = lists[i] - local metadata = list.metadata - if metadata and metadata.kind == "section" and not metadata.nolist then - local numberdata = list.numberdata - if numberdata then - collected[#collected+1] = numberdata - end - end - end - sections.load = functions.dummy -end - -table.setmetatableindex(collected, function(t,i) - sections.load() - return collected[i] or { } -end) - +-- See comment above (*). We cannot use the following space optimization: +-- +-- function sections.load() +-- setmetatableindex(collected,nil) +-- local lists = lists.collected +-- for i=1,#lists do +-- local list = lists[i] +-- local metadata = list.metadata +-- if metadata and metadata.kind == "section" and not metadata.nolist then +-- local numberdata = list.numberdata +-- if numberdata then +-- collected[#collected+1] = numberdata +-- end +-- end +-- end +-- sections.load = functions.dummy +-- end -- +-- table.setmetatableindex(collected, function(t,i) +-- sections.load() +-- return collected[i] or { } +-- end) sections.verbose = true -- cgit v1.2.3