[latex3-commits] [git/LaTeX3-latex3-luaotfload] bidi-dev: Optimize and less globals (4d0c734)

Marcel Fabian Krüger tex at 2krueger.de
Fri Sep 13 14:56:11 CEST 2019


Repository : https://github.com/latex3/luaotfload
On branch  : bidi-dev
Link       : https://github.com/latex3/luaotfload/commit/4d0c7340a5208021e583e5b772c1e616f9578255

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

commit 4d0c7340a5208021e583e5b772c1e616f9578255
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Aug 31 15:03:11 2019 +0200

    Optimize and less globals


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

4d0c7340a5208021e583e5b772c1e616f9578255
 src/luaotfload-bidi.lua                                 | 17 ++++++-----------
 src/luaotfload-init.lua                                 | 10 +++++++---
 src/luaotfload-main.lua                                 |  7 +++++--
 src/luaotfload-multiscript.lua                          |  2 +-
 texmf/tex/latex-dev/luaotfload/luaotfload-bidi.lua      | 17 ++++++-----------
 texmf/tex/latex-dev/luaotfload/luaotfload-init.lua      | 10 +++++++---
 texmf/tex/latex-dev/luaotfload/luaotfload-main.lua      |  7 +++++--
 .../tex/latex-dev/luaotfload/luaotfload-multiscript.lua |  2 +-
 8 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/src/luaotfload-bidi.lua b/src/luaotfload-bidi.lua
index 2f4ec05..e29f747 100644
--- a/src/luaotfload-bidi.lua
+++ b/src/luaotfload-bidi.lua
@@ -107,7 +107,9 @@ local bidi_fonts = setmetatable({}, {
   end,
 })
 
+local any_bidi = false
 local function makebidifont(tfmdata)
+  any_bidi = true
   tfmdata.bidi = true
 end
 
@@ -371,7 +373,8 @@ end
 node_class, node_origclass, node_level = {}, {}, {} -- Making these local was significantly
 -- slower necause they are sparse arrays with medium sized integer
 -- keys, requiring relativly big allocations
-function dobidi(head, a, b, c, par_direction)
+function luaotfload.apply_bidi(head, a, b, c, par_direction)
+  if not any_bidi then return head end -- Optimization: Skip if no font is bidi
   head = node.direct.todirect(head)
   local node_class, node_origclass, node_level = node_class, node_origclass, node_level
   local dir_matches = {}
@@ -544,7 +547,6 @@ function dobidi(head, a, b, c, par_direction)
     local dirnode = nodenew(dir_id)
     setdirection(dirnode, newlevel % 2, 0)
     stack[#stack + 1] = {level, dirnode}
-    -- tableinsert(stack, 
     level = newlevel
     return insert_before(head, n, dirnode)
   end
@@ -593,17 +595,10 @@ function dobidi(head, a, b, c, par_direction)
 end
 
 otffeatures.register {
-  name        = "bidi",
-  description = "Apply Unicode bidi algorithm",
-  default = 1,
+  name         = "bidi",
+  description  = "Apply Unicode bidi algorithm",
   manipulators = {
     node = makebidifont,
   },
-  --                -- We have to see how processors interact with
-  --                -- multiscript fonts
-  -- processors = {
-  --   node = donotdef,
-  -- }
 }
-
 --- vim:sw=2:ts=2:expandtab:tw=71
diff --git a/src/luaotfload-init.lua b/src/luaotfload-init.lua
index e793eb3..5cb8f71 100644
--- a/src/luaotfload-init.lua
+++ b/src/luaotfload-init.lua
@@ -647,12 +647,14 @@ local init_post_install_callbacks = function ()
 
   -- MK Pass current text direction to simple_font_handler
   local handler = nodes.simple_font_handler
+  local apply_bidi = luaotfload.apply_bidi
+  local apply_multiscript = luaotfload.apply_multiscript
   local callback = function(head, groupcode, _, _, direction)
     if not direction then
       direction = head.dir or tex.textdir
     end
-    head = dobidi(head, nil, nil, nil, direction)
-    domultiscript(head, nil, nil, nil, direction)
+    head = apply_bidi(head, nil, nil, nil, direction)
+    apply_multiscript(head, nil, nil, nil, direction)
     return handler(head, groupcode, nil, nil, direction)
   end
   luatexbase.add_to_callback("pre_linebreak_filter",
@@ -777,9 +779,11 @@ return {
     logreport ("both", 1, "init",
                "fontloader loaded in %0.3f seconds",
                os.gettimeofday() - starttime)
+    return true
+  end,
+  late = function()
     local n = init_post ()
     logreport ("both", 5, "init", "post hook terminated, %d actions performed", n)
-    return true
   end
 }
 
diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua
index 560f53e..18b5459 100644
--- a/src/luaotfload-main.lua
+++ b/src/luaotfload-main.lua
@@ -285,6 +285,11 @@ luaotfload.main = function ()
         logreport ("log", 0, "load", "Main fontloader initialization failed.")
     end
 
+    loadmodule "bidi"         --- ...
+    loadmodule "multiscript"  --- ...
+
+    init.late()
+
     initialize "loaders"         --- Font loading; callbacks
     initialize "database"        --- Font management.
     initialize "colors"          --- Per-font colors.
@@ -302,8 +307,6 @@ luaotfload.main = function ()
     loadmodule "notdef"       --- missing glyph handling
     loadmodule "mirror"       --- mirroring for r2l text
     initialize "auxiliary"    --- additional high-level functionality
-    loadmodule "bidi"         --- ...
-    loadmodule "multiscript"  --- ...
 
     luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec
 
diff --git a/src/luaotfload-multiscript.lua b/src/luaotfload-multiscript.lua
index 4cc49ce..406f6e1 100644
--- a/src/luaotfload-multiscript.lua
+++ b/src/luaotfload-multiscript.lua
@@ -147,7 +147,7 @@ end
 
 local glyph_id = node.id'glyph'
 -- TODO: unset last_script, matching parentheses etc
-function domultiscript(head, _, _, _, direction)
+function luaotfload.apply_multiscript(head, _, _, _, direction)
   head = node.direct.todirect(head)
   local last_fid, last_fonts, last_script
   for cur, cid, fid in traverse_char(head) do
diff --git a/texmf/tex/latex-dev/luaotfload/luaotfload-bidi.lua b/texmf/tex/latex-dev/luaotfload/luaotfload-bidi.lua
index 2f4ec05..e29f747 100644
--- a/texmf/tex/latex-dev/luaotfload/luaotfload-bidi.lua
+++ b/texmf/tex/latex-dev/luaotfload/luaotfload-bidi.lua
@@ -107,7 +107,9 @@ local bidi_fonts = setmetatable({}, {
   end,
 })
 
+local any_bidi = false
 local function makebidifont(tfmdata)
+  any_bidi = true
   tfmdata.bidi = true
 end
 
@@ -371,7 +373,8 @@ end
 node_class, node_origclass, node_level = {}, {}, {} -- Making these local was significantly
 -- slower necause they are sparse arrays with medium sized integer
 -- keys, requiring relativly big allocations
-function dobidi(head, a, b, c, par_direction)
+function luaotfload.apply_bidi(head, a, b, c, par_direction)
+  if not any_bidi then return head end -- Optimization: Skip if no font is bidi
   head = node.direct.todirect(head)
   local node_class, node_origclass, node_level = node_class, node_origclass, node_level
   local dir_matches = {}
@@ -544,7 +547,6 @@ function dobidi(head, a, b, c, par_direction)
     local dirnode = nodenew(dir_id)
     setdirection(dirnode, newlevel % 2, 0)
     stack[#stack + 1] = {level, dirnode}
-    -- tableinsert(stack, 
     level = newlevel
     return insert_before(head, n, dirnode)
   end
@@ -593,17 +595,10 @@ function dobidi(head, a, b, c, par_direction)
 end
 
 otffeatures.register {
-  name        = "bidi",
-  description = "Apply Unicode bidi algorithm",
-  default = 1,
+  name         = "bidi",
+  description  = "Apply Unicode bidi algorithm",
   manipulators = {
     node = makebidifont,
   },
-  --                -- We have to see how processors interact with
-  --                -- multiscript fonts
-  -- processors = {
-  --   node = donotdef,
-  -- }
 }
-
 --- vim:sw=2:ts=2:expandtab:tw=71
diff --git a/texmf/tex/latex-dev/luaotfload/luaotfload-init.lua b/texmf/tex/latex-dev/luaotfload/luaotfload-init.lua
index e793eb3..5cb8f71 100644
--- a/texmf/tex/latex-dev/luaotfload/luaotfload-init.lua
+++ b/texmf/tex/latex-dev/luaotfload/luaotfload-init.lua
@@ -647,12 +647,14 @@ local init_post_install_callbacks = function ()
 
   -- MK Pass current text direction to simple_font_handler
   local handler = nodes.simple_font_handler
+  local apply_bidi = luaotfload.apply_bidi
+  local apply_multiscript = luaotfload.apply_multiscript
   local callback = function(head, groupcode, _, _, direction)
     if not direction then
       direction = head.dir or tex.textdir
     end
-    head = dobidi(head, nil, nil, nil, direction)
-    domultiscript(head, nil, nil, nil, direction)
+    head = apply_bidi(head, nil, nil, nil, direction)
+    apply_multiscript(head, nil, nil, nil, direction)
     return handler(head, groupcode, nil, nil, direction)
   end
   luatexbase.add_to_callback("pre_linebreak_filter",
@@ -777,9 +779,11 @@ return {
     logreport ("both", 1, "init",
                "fontloader loaded in %0.3f seconds",
                os.gettimeofday() - starttime)
+    return true
+  end,
+  late = function()
     local n = init_post ()
     logreport ("both", 5, "init", "post hook terminated, %d actions performed", n)
-    return true
   end
 }
 
diff --git a/texmf/tex/latex-dev/luaotfload/luaotfload-main.lua b/texmf/tex/latex-dev/luaotfload/luaotfload-main.lua
index 560f53e..18b5459 100644
--- a/texmf/tex/latex-dev/luaotfload/luaotfload-main.lua
+++ b/texmf/tex/latex-dev/luaotfload/luaotfload-main.lua
@@ -285,6 +285,11 @@ luaotfload.main = function ()
         logreport ("log", 0, "load", "Main fontloader initialization failed.")
     end
 
+    loadmodule "bidi"         --- ...
+    loadmodule "multiscript"  --- ...
+
+    init.late()
+
     initialize "loaders"         --- Font loading; callbacks
     initialize "database"        --- Font management.
     initialize "colors"          --- Per-font colors.
@@ -302,8 +307,6 @@ luaotfload.main = function ()
     loadmodule "notdef"       --- missing glyph handling
     loadmodule "mirror"       --- mirroring for r2l text
     initialize "auxiliary"    --- additional high-level functionality
-    loadmodule "bidi"         --- ...
-    loadmodule "multiscript"  --- ...
 
     luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec
 
diff --git a/texmf/tex/latex-dev/luaotfload/luaotfload-multiscript.lua b/texmf/tex/latex-dev/luaotfload/luaotfload-multiscript.lua
index 4cc49ce..406f6e1 100644
--- a/texmf/tex/latex-dev/luaotfload/luaotfload-multiscript.lua
+++ b/texmf/tex/latex-dev/luaotfload/luaotfload-multiscript.lua
@@ -147,7 +147,7 @@ end
 
 local glyph_id = node.id'glyph'
 -- TODO: unset last_script, matching parentheses etc
-function domultiscript(head, _, _, _, direction)
+function luaotfload.apply_multiscript(head, _, _, _, direction)
   head = node.direct.todirect(head)
   local last_fid, last_fonts, last_script
   for cur, cid, fid in traverse_char(head) do





More information about the latex3-commits mailing list