OSDN Git Service

ltj-stack.lua: use array instead of hashed table for glue
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Thu, 18 Aug 2022 21:28:30 +0000 (06:28 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Thu, 18 Aug 2022 21:28:30 +0000 (06:28 +0900)
src/ltj-jfmglue.lua
src/ltj-jfont.lua
src/ltj-kinsoku.tex
src/ltj-stack.lua
src/luatexja-core.sty
src/luatexja.lua

index 3018470..c74e2c3 100644 (file)
@@ -113,11 +113,12 @@ local function fast_find_char_class(c,m)
 end
 
 -- 文字クラスの決定
-local slow_find_char_class
+local slow_find_char_class, skip_table_to_glue
 do
    local start_time_measure = ltjb.start_time_measure
    local stop_time_measure = ltjb.stop_time_measure
-   slow_find_char_class = function (c, m, oc)
+   local fast_get_stack_skip = ltjs.fast_get_stack_skip
+   function slow_find_char_class (c, m, oc)
       local cls = ltjf_find_char_class(oc, m)
       if oc~=c and c and cls==0 then
          return ltjf_find_char_class(c, m)
@@ -125,12 +126,11 @@ do
          return cls
       end
    end
-end
-
-local function skip_table_to_glue(n)
-   local g, st = node_new(id_glue), ltjs.fast_get_stack_skip(n)
-   setglue(g, st.width, st.stretch, st.shrink, st.stretch_order, st.shrink_order)
-   return g, (st.width==1073741823)
+   function skip_table_to_glue(n)
+      local g, st = node_new(id_glue), fast_get_stack_skip(n)
+      setglue(g, st[1], st[2], st[3], st[4], st[5])
+      return g, (st[1]==1073741823)
+   end
 end
 
 
@@ -759,7 +759,7 @@ local function new_jfm_glue(mc, bc, ac)
        else
           local f = node_new(id_glue)
           set_attr(f, attr_icflag, g.priority)
-          setglue(f, g.width, g.stretch, g.shrink)
+          setglue(f, g[2], g[3], g[4])
           return f, g.ratio, g.kanjiskip_natural, g.kanjiskip_stretch, g.kanjiskip_shrink
       end
    end
@@ -1392,6 +1392,7 @@ do
            return tex_getattr((get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt)
        end
    end
+   local get_stack_skip = ltjs.get_stack_skip
    -- \insertxkanjiskip
    -- SPECIAL_JAGLUE のノード:
    -- * (X)KANJI_SKIP(_JFM): その場で値が決まっている
@@ -1401,15 +1402,15 @@ do
        local g = node_new(id_glue); set_attr(g, attr_icflag, SPECIAL_JAGLUE)
        local is_late = scan_keyword("late")
        if not is_late then
-           local st = ltjs.get_stack_skip(ind, getcount('ltj@@stack'))
-           if st.width==1073741823 then
+           local st = get_stack_skip(ind, getcount('ltj@@stack'))
+           if st[1]==1073741823 then
                local bk = ltjf_font_metric_table[get_current_jfont()][name]
                if bk then
                    setglue(g, bk[1] or 0, bk[2] or 0, bk[3] or 0, 0, 0)
                end
                set_attr(g, attr_yablshift, icb); node_write(g); return
            end
-           setglue(g, st.width, st.stretch, st.shrink, st.stretch_order, st.shrink_order)
+           setglue(g, st[1], st[2], st[3], st[4], st[5])
            set_attr(g, attr_yablshift, ica)
        else
            set_attr(g, attr_yablshift, PROCESSED_BEGIN_FLAG + ica)
index 29a0413..25a3122 100644 (file)
@@ -219,10 +219,9 @@ do
          if type(i) == 'number' then -- char_type
             for k,w in pairs(v.glue) do
                v[k] = {
-                  nil,
+                  nil, w[1], w[2], w[3],
                   ratio=w.ratio,
                   priority=FROM_JFM + w.priority,
-                  width = w[1], stretch = w[2], shrink = w[3],
                   kanjiskip_natural = w.kanjiskip_natural,
                   kanjiskip_stretch = w.kanjiskip_stretch,
                   kanjiskip_shrink =  w.kanjiskip_shrink,
index 179e621..e420750 100644 (file)
 
 \directlua{%
  local s = table.copy(luatexja.stack.charprop_stack_table[0])
- luatexja.base.save_cache('ltj-kinsoku_default', {s, version=3})
+ luatexja.base.save_cache('ltj-kinsoku_default', {s, version=4})
 }
index c9458ec..5b15f26 100644 (file)
@@ -23,8 +23,7 @@ local scan_int, scan_keyword = token.scan_int, token.scan_keyword
 local tex_nest = tex.nest
 ltjs.hmode = 0 -- dummy
 
-local charprop_stack_table={};
-
+local charprop_stack_table={}
 ltjs.charprop_stack_table = charprop_stack_table
 charprop_stack_table[0]={}
 
@@ -94,17 +93,18 @@ local getglue = node.getglue
 function ltjs.set_stack_skip(m,sp)
   local i = get_stack_level()
   if not sp then return end
-  if not charprop_stack_table[i][m] then
-     charprop_stack_table[i][m] = {}
-  end
   local w,st,sh,sto,sho = getglue(sp)
-  local c = charprop_stack_table[i][m]
-  c.width, c.stretch, c.shrink, c.stretch_order, c.shrink_order = w, st, sh, sto, sho
+  if charprop_stack_table[i][m] then
+     local c = charprop_stack_table[i][m]
+     c[1], c[2], c[3], c[4], c[5] = w, st, sh, sto, sho
+  else
+     charprop_stack_table[i][m] = { w,st,sh,sto,sho }
+  end
   if luatexja.isglobal=='global' then
      for j,v in pairs(charprop_stack_table) do
-        if not v[m] then v[m] = {} end
+        if not v[m] then v[m] = { true,true,true,true,true } end
         local c = v[m]
-        c.width, c.stretch, c.shrink, c.stretch_order, c.shrink_order = w, st, sh, sto, sho
+        c[1], c[2], c[3], c[4], c[5] = w, st, sh, sto, sho
      end
   end
 end
@@ -115,7 +115,7 @@ local orig_char_table = {}
 ltjs.orig_char_table = orig_char_table
 ltjs.list_dir = nil -- dummy
 ltjs.table_current_stack = nil -- dummy
-local dummy_skip_table = { width = 0, stretch = 0, shrink = 0, stretch_order = 0, shrink_order = 0 }
+local dummy_skip_table = { 0,0,0,0,0 }
 function ltjs.report_stack_level(bsl)
    ltjs.table_current_stack = charprop_stack_table[bsl]
    return bsl
index 7509f1e..5a78839 100644 (file)
 \define@key[ltj]{japaram}{postbreakpenalty}{\ltj@@set@stack{POST}{-10000}{10000}#1\relax}
 \def\ltj@@set@stack#1#2#3{%
   \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#1,#2,#3)}}
-%\def\ltj@@set@stack#1,#2:#3#4#5{%
-%  \directlua{luatexja.stack.set_stack_perchar(luatexja.stack_table_index.#3,
-%    \ltj@safe@num@or{nil}{#1},\ltj@safe@num@or{nil}{#2},#4,#5)}}
 
 % jatextfont = {<char_code>, <font_cs>}
 % only horizontal font is supported
index cb74a99..1b21654 100644 (file)
@@ -186,12 +186,12 @@ local function print_glue(d,order)
 end
 
 local function print_spec(p)
-   local out=print_scaled(p.width)..'pt'
-   if p.stretch~=0 then
-      out=out..' plus '..print_glue(p.stretch,p.stretch_order)
+   local out=print_scaled(p.width or p[1])..'pt'
+   if p.stretch or p[2]~=0 then
+      out=out..' plus '..print_glue(p.stretch or p[2], p.stretch_order or p[4])
    end
-   if p.shrink~=0 then
-      out=out..' minus '..print_glue(p.shrink,p.shrink_order)
+   if p.shrink or p[3]~=0 then
+      out=out..' minus '..print_glue(p.shrink or p[3], p.shrink_order or p[5])
    end
 return out
 end
@@ -395,7 +395,7 @@ do
 end
 
 do
-    local cache_ver = 3 -- must be same as ltj-kinsoku.tex
+    local cache_ver = 4 -- must be same as ltj-kinsoku.tex
     local cache_outdate_fn = function (t) return t.version~=cache_ver end
     local t = ltjs.charprop_stack_table
     function luatexja.load_kinsoku()
@@ -406,7 +406,7 @@ do
         else
             t[0] = {}; tex.print(cat_lp, '\\input ltj-kinsoku.tex\\relax')
         end
-        luatexja.load_kinsoku=nil; ltjs.charprop_stack_table = nil
+        luatexja.load_kinsoku=nil
     end
 end