OSDN Git Service

Speed up: reduced set_attr(..., attr_jchar_class) call
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 12 Jan 2014 23:29:14 +0000 (08:29 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 12 Jan 2014 23:29:14 +0000 (08:29 +0900)
src/ltj-jfmglue.lua
src/ltj-pretreat.lua
src/luatexja-core.sty

index a0df4e7..218fa5c 100644 (file)
@@ -3,11 +3,11 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.jfmglue',
-  date = '2013/12/05',
+  date = '2014/1/12',
   description = 'Insertion process of JFM glues and kanjiskip',
 })
 module('luatexja.jfmglue', package.seeall)
-local err, warn, info, log = luatexbase.errwarinf(_NAME)
+local err, warn, info, log = luatexbase .errwarinf(_NAME)
 
 luatexja.load_module('stack');     local ltjs = luatexja.stack
 luatexja.load_module('jfont');     local ltjf = luatexja.jfont
@@ -23,9 +23,6 @@ local ltjf_find_char_class = ltjf.find_char_class
 local node_new = node.new
 local node_copy = node.copy
 
-local ligature_head = 1
-local ligature_tail = 2
-
 local id_glyph = node.id('glyph')
 local id_hlist = node.id('hlist')
 local id_vlist = node.id('vlist')
@@ -225,7 +222,7 @@ function check_box_high(Nx, box_ptr, box_end)
            if first_char.font == (has_attr(first_char, attr_curjfnt) or -1) then 
               set_np_xspc_jachar(Nx, first_char)
            else
-              set_np_xspc_alchar(Nx, first_char.char,first_char, ligature_head)
+              set_np_xspc_alchar(Nx, first_char.char,first_char, 1)
            end
         else -- math_node
            set_np_xspc_alchar(Nx, -1,first_char)
@@ -382,8 +379,8 @@ function calc_np(lp, last)
    -- We clear `predefined' entries of Np before pairs() loop,
    -- because using only pairs() loop is slower.
    Np.post, Np.pre, Np.xspc = nil, nil, nil
-   Np.first, Np.id, Np.last, Np.met = nil, nil, nil
-   Np.auto_kspc, Np.auto_xspc, Np.char, Np.class, Np.nuc = nil, nil, nil, nil, nil
+   Np.first, Np.id, Np.last, Np.met, Np.class= nil, nil, nil, nil
+   Np.auto_kspc, Np.auto_xspc, Np.char, Np.nuc = nil, nil, nil, nil
    for k in pairs(Np) do Np[k] = nil end
 
    for k = 1,#Bp do Bp[k] = nil end
@@ -425,8 +422,8 @@ do
    function set_np_xspc_jachar(Nx, x)
       local m = ltjf_font_metric_table[x.font]
       local cls, c = slow_find_char_class(has_attr(x, attr_orig_char), m, x.char)
-      Nx.class = cls; set_attr(x, attr_jchar_class, cls)
-      Nx.met, Nx.char = m, c
+      Nx.met, Nx.char = m, c; Nx.class = cls; 
+      if cls~=0 then set_attr(x, attr_jchar_class, cls) end
       Nx.pre  = table_current_stack[PRE + c]  or 0
       Nx.post = table_current_stack[POST + c] or 0
       Nx.xspc = table_current_stack[XSP  + c] or 3
@@ -468,7 +465,7 @@ do
    function extract_np()
       local x, i = Np.nuc, Np.id;
       if i ==  id_jglyph then return set_np_xspc_jachar(Np, x)
-      elseif i == id_glyph then return set_np_xspc_alchar(Np, x.char, x, ligature_head)
+      elseif i == id_glyph then return set_np_xspc_alchar(Np, x.char, x, 1)
       elseif i == id_hlist then Np.last_char = check_box_high(Np, x.head, nil)
       elseif i == id_pbox then Np.last_char = check_box_high(Np, Np.first, node_next(Np.last))
       elseif i == id_disc then Np.last_char = check_box_high(Np, x.replace, nil)
@@ -485,7 +482,7 @@ do
            if s.font == (has_attr(s, attr_curjfnt) or -1) then 
               set_np_xspc_jachar(Nx, s)
            else
-              set_np_xspc_alchar(Nx, s.char, s, ligature_tail)
+              set_np_xspc_alchar(Nx, s.char, s, 2)
            end
         else
            set_np_xspc_alchar(Nx, -1, s)
@@ -497,7 +494,7 @@ do
    
    function after_alchar(Nx)
       local x = Nx.nuc
-      return set_np_xspc_alchar(Nx, x.char,x, ligature_tail)
+      return set_np_xspc_alchar(Nx, x.char,x, 2)
    end
 
 end
index f8eed90..0c7ac3d 100644 (file)
@@ -33,30 +33,49 @@ local STCK = luatexja.userid_table.STCK
 -- MAIN PROCESS STEP 1: replace fonts
 ------------------------------------------------------------------------
 local wt
-
-local function suppress_hyphenate_ja(head)
-   local non_math, p = true, head
-   wt = {}
-   while p do
-      local pid = p.id
-      if pid == id_glyph then
-        if (has_attr(p, attr_icflag) or 0)<=0 and ltjc_is_ucs_in_japanese_char(p) then
-           local pc = p.char
-           local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or p.font, pc)
-           p.font = pf;  set_attr(p, attr_curjfnt, pf)
-           p.subtype = floor(p.subtype*0.5)*2
-           set_attr(p, attr_orig_char, pc)
-        end
-      elseif pid == id_math then 
-        p = node_next(p) -- skip math on
+do
+   local head
+   local end_math = node.end_of_math or 
+      function(p)
         while p and p.id~=id_math do p = node_next(p) end
-      elseif pid == id_whatsit and p.subtype==sid_user and p.user_id==STCK then
+        return p
+      end
+
+   local suppress_hyphenate_ja_aux = {}
+   suppress_hyphenate_ja_aux[id_glyph] = function(p)
+      if (has_attr(p, attr_icflag) or 0)<=0 and ltjc_is_ucs_in_japanese_char(p) then
+        local pc = p.char
+        local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or p.font, pc)
+        p.font = pf;  set_attr(p, attr_curjfnt, pf)
+        p.subtype = floor(p.subtype*0.5)*2
+        set_attr(p, attr_orig_char, pc)
+      end
+      return p
+   end
+   suppress_hyphenate_ja_aux[id_math] = function(p) return end_math(node_next(p)) end
+   suppress_hyphenate_ja_aux[id_whatsit] = function(p)
+      if p.subtype==sid_user and p.user_id==STCK then
         wt[#wt+1] = p; head = node_remove(head, p)
       end
-      p = node_next(p)
+      return p
    end
-   lang.hyphenate(head)
-   return head
+
+   local function suppress_hyphenate_ja (h)
+      local p = h
+      wt, head = {}, h
+      while p do
+        local pfunc = suppress_hyphenate_ja_aux[p.id]
+        if pfunc then p = pfunc(p) end
+        p = node_next(p)
+      end
+      lang.hyphenate(head)
+      return head
+   end
+   
+   luatexbase.add_to_callback('hyphenate', 
+                             function (head,tail)
+                                return suppress_hyphenate_ja(head)
+                             end,'ltj.hyphenate')
 end
 
 -- mode: true iff this function is called from hpack_filter
@@ -78,10 +97,6 @@ luatexbase.add_to_callback('pre_linebreak_filter',
   function (head)
      return set_box_stack_level(head, false)
   end,'ltj.pre_linebreak_filter_pre',1)
-luatexbase.add_to_callback('hyphenate', 
- function (head,tail)
-    return suppress_hyphenate_ja(head)
- end,'ltj.hyphenate')
 
 luatexja.pretreat = {
    set_box_stack_level = set_box_stack_level,
index 0995eb4..706eabb 100644 (file)
@@ -65,7 +65,7 @@
   \expandafter\let\csname ifltj@in@latex\expandafter\endcsname
     \csname iftrue\endcsname
   \NeedsTeXFormat{LaTeX2e}
-  \ProvidesPackage{luatexja-core}[2013/05/14 Core of LuaTeX-ja]
+  \ProvidesPackage{luatexja-core}[2014/01/13 Core of LuaTeX-ja]
 \fi                             %</LaTeX>
 
 %% Load prerequisite packages.
 \newluatexattribute\ltj@yablshift % attribute for \yabaselineshift
 \newluatexattribute\ltj@ykblshift % attribute for \ykbaselineshift
 \newluatexattribute\jfam          % index for current jfam
-\ltj@icflag=0\ltj@origchar=0
+\ltj@icflag=0\ltj@origchar=0\ltj@charclass=0
 
 %%%%%%%% Attributes for character ranges
 \newcount\ltj@tempcnta