[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Hash cache keys in harf mode (a77c552)

Marcel Fabian Krüger tex at 2krueger.de
Wed Oct 12 20:14:06 CEST 2022


Repository : https://github.com/latex3/luaotfload
On branch  : dev
Link       : https://github.com/latex3/luaotfload/commit/a77c552eda8ec627f74cf30f506e2cee71cede8f

>---------------------------------------------------------------

commit a77c552eda8ec627f74cf30f506e2cee71cede8f
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Wed Oct 12 20:14:06 2022 +0200

    Hash cache keys in harf mode


>---------------------------------------------------------------

a77c552eda8ec627f74cf30f506e2cee71cede8f
 src/luaotfload-harf-define.lua | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index 42606f1..e24d7ba 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -76,6 +76,20 @@ local get_designsize do
   end
 end
 
+local keyhash do
+  local formatstring = string.rep('%02x', 256/8)
+  local sha256 = sha2.digest256
+  local format = string.format
+  local byte = string.byte
+  keyhash = setmetatable({}, {__index = function(t, k)
+    print(t, k)
+    local h = format(formatstring, byte(sha256(k), 1, -1))
+    print(t, k, h)
+    t[k] = h
+    return h
+  end})
+end
+
 local containers = luaotfload.fontloader.containers
 local hbcacheversion = 1.4
 local fontcache = containers.define("fonts", "hb", hbcacheversion, true)
@@ -93,7 +107,7 @@ end
 local function loadfont(spec)
   local path, sub = spec.resolved, spec.sub or 1
 
-  local key = gsub(string.format("%s:%d:%s", path, sub, instance), "[/\\]", ":")
+  local key = string.format("%s:%d:%s", path, sub, instance)
 
   local attributes = lfs.attributes(path)
   if not attributes then return end
@@ -183,6 +197,10 @@ local function loadfont(spec)
     varkey = ''
   end
 
+  -- Paths get get rather long and contain many characters which can not appear in filenames.
+  -- Therefore we hash the key to get it into a more regular form
+  key = keyhash[key]
+
   local cached = containers.read(fontcache, key)
   local iscached = cached and cached.date == date and cached.size == size
 





More information about the latex3-commits mailing list.