summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/data-con.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/data-con.lua')
-rw-r--r--tex/context/base/mkiv/data-con.lua55
1 files changed, 33 insertions, 22 deletions
diff --git a/tex/context/base/mkiv/data-con.lua b/tex/context/base/mkiv/data-con.lua
index c79fca7c5..ec2251b35 100644
--- a/tex/context/base/mkiv/data-con.lua
+++ b/tex/context/base/mkiv/data-con.lua
@@ -6,6 +6,7 @@ if not modules then modules = { } end modules ['data-con'] = {
license = "see context related readme files"
}
+local setmetatable = setmetatable
local format, lower, gsub = string.format, string.lower, string.gsub
local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
@@ -13,21 +14,28 @@ local trace_containers = false trackers.register("resolvers.containers", functi
local trace_storage = false trackers.register("resolvers.storage", function(v) trace_storage = v end)
--[[ldx--
-<p>Once we found ourselves defining similar cache constructs
-several times, containers were introduced. Containers are used
-to collect tables in memory and reuse them when possible based
-on (unique) hashes (to be provided by the calling function).</p>
+<p>Once we found ourselves defining similar cache constructs several times,
+containers were introduced. Containers are used to collect tables in memory and
+reuse them when possible based on (unique) hashes (to be provided by the calling
+function).</p>
-<p>Caching to disk is disabled by default. Version numbers are
-stored in the saved table which makes it possible to change the
-table structures without bothering about the disk cache.</p>
+<p>Caching to disk is disabled by default. Version numbers are stored in the
+saved table which makes it possible to change the table structures without
+bothering about the disk cache.</p>
-<p>Examples of usage can be found in the font related code.</p>
+<p>Examples of usage can be found in the font related code. This code is not
+ideal but we need it in generic too so we compromise.</p>
--ldx]]--
-containers = containers or { }
-local containers = containers
-containers.usecache = true
+containers = containers or { }
+local containers = containers
+containers.usecache = true
+
+local getwritablepath = caches.getwritablepath
+local getreadablepaths = caches.getreadablepaths
+local cacheiswritable = caches.is_writable
+local loaddatafromcache = caches.loaddata
+local savedataincache = caches.savedata
local report_containers = logs.reporter("resolvers","containers")
@@ -36,11 +44,11 @@ local allocated = { }
local mt = {
__index = function(t,k)
if k == "writable" then
- local writable = caches.getwritablepath(t.category,t.subcategory) or { "." }
+ local writable = getwritablepath(t.category,t.subcategory) or { "." }
t.writable = writable
return writable
elseif k == "readables" then
- local readables = caches.getreadablepaths(t.category,t.subcategory) or { "." }
+ local readables = getreadablepaths(t.category,t.subcategory) or { "." }
t.readables = readables
return readables
end
@@ -64,8 +72,8 @@ function containers.define(category, subcategory, version, enabled)
enabled = enabled,
version = version or math.pi, -- after all, this is TeX
trace = false,
- -- writable = caches.getwritablepath and caches.getwritablepath (category,subcategory) or { "." },
- -- readables = caches.getreadablepaths and caches.getreadablepaths(category,subcategory) or { "." },
+ -- writable = getwritablepath and getwritablepath (category,subcategory) or { "." },
+ -- readables = getreadablepaths and getreadablepaths(category,subcategory) or { "." },
}
setmetatable(s,mt)
c[subcategory] = s
@@ -75,7 +83,7 @@ function containers.define(category, subcategory, version, enabled)
end
function containers.is_usable(container,name)
- return container.enabled and caches and caches.is_writable(container.writable, name)
+ return container.enabled and caches and cacheiswritable(container.writable, name)
end
function containers.is_valid(container,name)
@@ -91,7 +99,7 @@ function containers.read(container,name)
local storage = container.storage
local stored = storage[name]
if not stored and container.enabled and caches and containers.usecache then
- stored = caches.loaddata(container.readables,name,container.writable)
+ stored = loaddatafromcache(container.readables,name,container.writable)
if stored and stored.cache_version == container.version then
if trace_cache or trace_containers then
report_containers("action %a, category %a, name %a","load",container.subcategory,name)
@@ -108,17 +116,20 @@ function containers.read(container,name)
return stored
end
-function containers.write(container, name, data)
+function containers.write(container, name, data, fast)
if data then
data.cache_version = container.version
if container.enabled and caches then
- local unique, shared = data.unique, data.shared
- data.unique, data.shared = nil, nil
- caches.savedata(container.writable, name, data)
+ local unique = data.unique
+ local shared = data.shared
+ data.unique = nil
+ data.shared = nil
+ savedataincache(container.writable, name, data, fast)
if trace_cache or trace_containers then
report_containers("action %a, category %a, name %a","save",container.subcategory,name)
end
- data.unique, data.shared = unique, shared
+ data.unique = unique
+ data.shared = shared
end
if trace_cache or trace_containers then
report_containers("action %a, category %a, name %a","store",container.subcategory,name)