[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Remove redundant data from casemapping tables (82305f5)

Marcel Fabian Krüger tex at 2krueger.de
Fri Apr 29 17:44:03 CEST 2022


Repository : https://github.com/latex3/luaotfload
On branch  : dev
Link       : https://github.com/latex3/luaotfload/commit/82305f520f80dedfa368ec6952a8384851a1fe23

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

commit 82305f520f80dedfa368ec6952a8384851a1fe23
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Fri Apr 29 17:44:03 2022 +0200

    Remove redundant data from casemapping tables


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

82305f520f80dedfa368ec6952a8384851a1fe23
 src/luaotfload-unicode.lua | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/luaotfload-unicode.lua b/src/luaotfload-unicode.lua
index 4f3700e..0b3846d 100644
--- a/src/luaotfload-unicode.lua
+++ b/src/luaotfload-unicode.lua
@@ -232,6 +232,47 @@ do
   f:close()
 end
 
+do
+  local function eq(a, b)
+    if not a then return false end
+    if not b then return false end
+    if a == b then return true end
+    if #a ~= #b then return false end
+    for i=1,#a do if a[i] ~= b[i] then return false end end
+    return true
+  end
+  local function collapse(t, inherited)
+    inherited = t._ or inherited
+    local empty = true
+    for k,v in next, t do
+      if k ~= '_' then
+        if eq(inherited, collapse(v, inherited)) then
+          t[k] = nil
+        else
+          empty = false
+        end
+      end
+    end
+    return empty and inherited
+  end
+  local function cleanup(t)
+    for k,v in next, t do
+      if not tonumber(v) then
+        local collapsed = collapse(v)
+        if collapsed and #collapsed == 1 then
+          v = collapsed[1]
+          if k == v then
+            v = nil
+          end
+          t[k] = v
+        end
+      end
+    end
+  end
+  cleanup(uppercase)
+  cleanup(lowercase)
+end
+
 return {
   casefold = casefold,
   alphnum_only = alphnum_only,





More information about the latex3-commits mailing list.