OSDN Git Service

Revert "Another optimization in jfmglue.lua."
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 23 Sep 2011 12:34:26 +0000 (21:34 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 23 Sep 2011 12:34:26 +0000 (21:34 +0900)
This reverts commit be09b3a288136136238db7e465815954167d958c,
since that commit made a new bug.

src/luatexja/jfmglue.lua
test/test05-speed.tex

index 9844cc1..902d81c 100644 (file)
@@ -141,8 +141,8 @@ local head -- the head of current list
 local last -- the last node of current list
 local lp   -- 外側での list 走査時のカーソル
 
-local Np, Nq, Bp, Bpn
-local widow_Bp, widow_Bpn, widow_Np -- \jcharwidowpenalty 挿入位置管理用
+local Np, Nq, Bp
+local widow_Bp, widow_Np -- \jcharwidowpenalty 挿入位置管理用
 
 local ihb_flag -- JFM グルー挿入抑止用 flag
                -- on: \inhibitglue 指定時,hlist の周囲
@@ -233,9 +233,7 @@ end
 local function calc_np()
    -- We assume lp = node_next(Np.last)
    local pBp = Bp; local lpi, lpa
-   Nq = Np; ihb_flag = false 
-   for k in pairs(Np) do Np[k]=nil end
-   for k in pairs(Bp) do Bp[k]=nil end; Bpn = 0
+   Nq = Np; Bp = {}; Bp[0] = 0; Np = {}; ihb_flag = false 
    while true do
       lpi = lp.id; lpa = has_attr(lp, attr_icflag) or 0
       if lp==last then Np = nil; return
@@ -247,7 +245,7 @@ local function calc_np()
       elseif lpi == id_ins or lpi == id_mark or lpi == id_adjust then
         set_attr_icflag_processed(lp); lp = node_next(lp)
       elseif lpi == id_penalty then
-        table.insert(Bp, lp); Bpn = Bpn + 1
+        table.insert(Bp, lp); Bp[0] = Bp[0] + 1
         set_attr_icflag_processed(lp); lp = node_next(lp)
       elseif lpi == id_whatsit then
         if lp.subtype==sid_user and lp.user_id==30111 then
@@ -431,13 +429,13 @@ end
 -- change penalties (or create a new penalty, if needed)
 local function handle_penalty_normal(post, pre, g)
    local a = (pre or 0) + (post or 0)
-   if Bpn == 0 then
+   if Bp[0] == 0 then
       if (a~=0 and not(g and g.id==id_kern)) or (Nq.lend and Nq.lend~=0) then
         local p = node_new(id_penalty)
         if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
         p.penalty = a
         head = node_insert_before(head, Np.first, p)
-        Bp[1] = p; Bpn = 1; set_attr(p, attr_icflag, KINSOKU)
+        Bp[1] = p; Bp[0] = 1; set_attr(p, attr_icflag, KINSOKU)
       end
    else for i, v in ipairs(Bp) do add_penalty(v,a) end
    end
@@ -445,13 +443,13 @@ end
 
 local function handle_penalty_always(post, pre, g)
    local a = (pre or 0) + (post or 0)
-   if Bpn == 0 then
+   if Bp[0] == 0 then
       if not (g and g.id==id_glue) or (Nq.lend and Nq.lend~=0) then
         local p = node_new(id_penalty)
         if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
         p.penalty = a
         head = node_insert_before(head, Np.first, p)
-        Bp[1] = p; Bpn = 1; set_attr(p, attr_icflag, KINSOKU)
+        Bp[1] = p; Bp[0] = 1; set_attr(p, attr_icflag, KINSOKU)
       end
    else for i, v in ipairs(Bp) do add_penalty(v,a) end
    end
@@ -459,11 +457,11 @@ end
 
 local function handle_penalty_suppress(post, pre, g)
    local a = (pre or 0) + (post or 0)
-   if Bpn == 0 then
+   if Bp[0] == 0 then
       if g and g.id==id_glue then
         local p = node_new(id_penalty)
         p.penalty = 10000; head = node_insert_before(head, Np.first, p)
-        Bp[1] = p; Bpn = 1; set_attr(p, attr_icflag, KINSOKU)
+        Bp[1] = p; Bp[0] = 1; set_attr(p, attr_icflag, KINSOKU)
       end
    else for i, v in ipairs(Bp) do add_penalty(v,a) end
    end
@@ -668,7 +666,7 @@ local function handle_np_jachar()
    end
    -- \jcharwidowpenalty 挿入予定箇所更新
    if ltjs.get_penalty_table('kcat', Np.char, 0, ltjp.box_stack_level)%2~=1 then
-      widow_Np = Np; widow_Bp = Bp; widow_Bpn = Bpn
+      widow_Np = Np; widow_Bp = Bp
    end
 end
 
@@ -729,7 +727,7 @@ local function handle_list_tail()
         end
       end
       -- Insert \jcharwidowpenalty
-      Bp = widow_Bp; Np = widow_Np; Bpn = widow_Bpn
+      Bp = widow_Bp; Np = widow_Np
       if Np then
         handle_penalty_normal(0,
                               ltjs.get_penalty_table('jwp', 0, 0, ltjp.box_stack_level))
@@ -753,7 +751,7 @@ local function handle_list_head()
       local g = new_jfm_glue(Np, find_char_class('boxbdd',Np.met), Np.class)
       if g then
         set_attr(g, attr_icflag, BOXBDD)
-        if g.id==id_glue and Bpn==0 then
+        if g.id==id_glue and Bp[0]==0 then
            local h = node_new(id_penalty)
            h.penalty = 10000; set_attr(h, attr_icflag, BOXBDD)
         end
@@ -764,7 +762,7 @@ end
 
 -- initialize
 local function init_var()
-   lp = head; widow_Bp = nil; widow_Np = nil; Np = {}; Bp = {}
+   lp = head; widow_Bp = nil; widow_Np = nil
    kanji_skip=skip_table_to_spec('kanjiskip')
    xkanji_skip=skip_table_to_spec('xkanjiskip')
    if mode then 
index 9d24f55..9456ae5 100644 (file)
@@ -1,4 +1,4 @@
-%#! time luatex  "\count300=60\input test05-speed.tex"
+%#! time luatex  "\count300=10\input test05-speed.tex"
 \input luatexja-core.sty
 
 \newcount\cnt\newcount\cnta
 \end
 
 %     real time:
-% 60:               19.765
-% 50:               16.378
-% 40: 17.453 14.234 12.996
-% 30: 13.254 10.624  9.795
-% 20:  8.771  7.097  6.735
-% 10:  4.927  4.145  3.857
+% 40: 17.453 14.234s
+% 30: 13.254 10.624
+% 20:  8.771  7.097
+% 10:  4.927  4.145
 % env: C2D E7300, Mem 4GB, LuaTeX 0.71.0pre, Gentoo amd64 unstable
\ No newline at end of file