OSDN Git Service

compress .lua cache by gzip
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 3 Jul 2020 23:20:57 +0000 (08:20 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 3 Jul 2020 23:20:57 +0000 (08:20 +0900)
src/ltj-base.lua
src/ltj-rmlgbm.lua

index 1852a83..d8a758e 100644 (file)
@@ -231,6 +231,7 @@ end
 
 require('lualibs-lpeg') -- string.split
 require('lualibs-os')   -- os.type
+require('lualibs-gzip') -- gzip.*
 
 do
    local kpse_var_value = kpse.var_value
@@ -273,26 +274,26 @@ do
    end
 
    local function save_cache(filename, t)
-      local fullpath = savepath .. '/' ..  filename .. '.lua'
+      local fullpath = savepath .. '/' ..  filename .. '.lua.gz'
       local s = serialize(t, 'return', false, serial_spec)
       if s then
-        local f = io.open(fullpath, 'wb')
-        if f then 
-           f:write(s)
-           texio.write('(save cache: ' .. fullpath .. ')')
-           f:close()
-        end
-        save_cache_luc(filename, t, s)
+         gzip.save(fullpath, s, 1)
+         texio.write('(save cache: ' .. fullpath .. ')')
+         save_cache_luc(filename, t, s)
       end
    end
 
-   local function load_cache_a(filename, outdate)
+   local function load_cache_a(filename, outdate, compressed)
       local result
       for _,v in pairs(path) do
         local fn = join(v, cache_dir, filename)
         if isreadable(fn) then
            texio.write('(load cache: ' .. fn .. ')')
-           result = loadfile(fn)
+           if compressed then
+             result = loadstring(gzip.load(fn))
+           else
+             result = loadfile(fn)
+           end
            result = result and result()
            break
         end
@@ -305,11 +306,11 @@ do
    end
    
    local function load_cache(filename, outdate)
-      local r = load_cache_a(filename ..  luc_suffix, outdate)
+      local r = load_cache_a(filename ..  luc_suffix, outdate, false)
       if r then 
         return r
       else
-         local r = load_cache_a(filename .. '.lua', outdate)
+         local r = load_cache_a(filename .. '.lua.gz', outdate, true)
         if r then save_cache_luc(filename, r) end -- update the precompiled cache
         return r
       end
@@ -321,6 +322,7 @@ do
    local function remove_cache (filename)
       local fullpath_wo_ext = savepath .. '/' ..  filename .. '.lu'
       remove_file_if_exist(fullpath_wo_ext .. 'a')
+      remove_file_if_exist(fullpath_wo_ext .. 'a.gz')
       remove_file_if_exist(fullpath_wo_ext .. 'b')
       remove_file_if_exist(fullpath_wo_ext .. 'c')
    end
index bd3110f..7ccbf9f 100644 (file)
@@ -5,7 +5,7 @@ luatexja.load_module('base');      local ltjb = luatexja.base
 
 local cidfont_data = {}
 local cache_chars = {}
-local cache_ver = 9
+local cache_ver = 10
 local identifiers = fonts.hashes.identifiers
 
 local cid_reg, cid_order, cid_supp, cid_name
@@ -175,8 +175,6 @@ do
         sequences = seq_dummy_vert,
       }
       k.descriptions = {}
-      k.shared.rawdata.resources=k.resources
-      k.shared.rawdata.descriptions=k.descriptions
       cache_chars[cid_name]  = { [655360] = k.characters }
 
       -- 縦書用字形
@@ -218,6 +216,8 @@ do
                          version = cache_ver,
                          k,
                       })
+      k.shared.rawdata.resources=k.resources
+      k.shared.rawdata.descriptions=k.descriptions
    end
 end
 
@@ -253,6 +253,8 @@ local function read_cid_font()
    local dat = ltjb.load_cache("ltj-cid-auto-" .. string.lower(cid_name),
                               cid_cache_outdated )
    if dat then
+      dat[1].shared.rawdata.resources=dat[1].resources
+      dat[1].shared.rawdata.descriptions=dat[1].descriptions
       cidfont_data[cid_name] = dat[1]
       cache_chars[cid_name]  = { [655360] = cidfont_data[cid_name].characters }
    else