From 115343e46ba6276d10db59b2994499c5d2edc8ca Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 26 Jul 2013 12:01:05 +0200 Subject: avoid recursing into font dirs retrieved by kpse minor speedup (some 16% with standard sized TL texmf), especially if the directories are uncached. as we take care of duplicate results from the file scanner elsewhere this will not affect the list of fonts found. --- luaotfload-database.lua | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 1b75458..b1d4877 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1438,7 +1438,9 @@ process_dir_tree = function (acc, dirs) then dirs[#dirs+1] = fullpath elseif lfsisfile (fullpath) then - if lpegmatch (p_font_extensions, stringlower(ent)) then + if lpegmatch (p_font_extensions, + stringlower (ent)) + then newfiles[#newfiles+1] = fullpath end end @@ -1450,10 +1452,38 @@ process_dir_tree = function (acc, dirs) return process_dir_tree (acc, dirs) end ---- string -> string list -local find_font_files = function (root) +local process_dir = function (dir) + local pwd = lfscurrentdir () + if lfschdir (dir) then + lfschdir (pwd) + + local files = { } + local blacklist = names.blacklist + for ent in lfsdir (dir) do + if ent ~= "." and ent ~= ".." and not blacklist[ent] then + local fullpath = dir .. "/" .. ent + if lfsisfile (fullpath) then + if lpegmatch (p_font_extensions, + stringlower (ent)) + then + files[#files+1] = fullpath + end + end + end + end + return files + end + return { } +end + +--- string -> bool -> string list +local find_font_files = function (root, recurse) if lfsisdir (root) then - return process_dir_tree ({}, { root }) + if recurse == true then + return process_dir_tree ({}, { root }) + else --- kpathsea already delivered the necessary subdirs + return process_dir (root) + end end end @@ -1478,7 +1508,7 @@ local scan_dir = function (dirname, fontnames, newfontnames, --- ignore return 0, 0 end - local found = find_font_files (dirname) + local found = find_font_files (dirname, texmf ~= true) if not found then report ("both", 3, "db", "No such directory: %q; skipping.", dirname) -- cgit v1.2.3 From 7d4e2eecc690c3e44f64c16b212ecf13b030f731 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 26 Jul 2013 17:32:18 +0200 Subject: stript trailing slashes before joining paths --- luaotfload-database.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index b1d4877..8cf49ec 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -117,6 +117,10 @@ end local report = logs.names_report +local trailingslashes = P"/"^1 * P(-1) +local stripslashes = C((1 - trailingslashes)^0) +names.patterns = { stripslashes = stripslashes } + --[[doc-- We use the functions in the cache.* namespace that come with the fontloader (see luat-basics-gen). it’s safe to use for the most part @@ -139,6 +143,7 @@ if caches then luaotfload.error ("Impossible to find a suitable writeable cache...") else + prefix = lpegmatch (stripslashes, prefix) report ("log", 0, "db", "root cache directory is " .. prefix) end -- cgit v1.2.3 From d551b4e78beef9413b818b9eb1688fc743261986 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 26 Jul 2013 18:05:11 +0200 Subject: filter pwd from texmf directories --- luaotfload-database.lua | 58 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 13 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 8cf49ec..a49e575 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -1546,23 +1546,55 @@ local scan_dir = function (dirname, fontnames, newfontnames, return n_found, n_new end +--- string list -> string list +local filter_out_pwd = function (dirs) + local result = { } + local pwd = path_normalize (lpegmatch (stripslashes, + lfscurrentdir ())) + for i = 1, #dirs do + --- better safe than sorry + local dir = path_normalize (lpegmatch (stripslashes, dirs[i])) + if not (dir == "." or dir == pwd) then + result[#result+1] = dir + end + end + return result +end + +--[[doc-- + scan_texmf_fonts() scans all fonts in the texmf tree through the + kpathsea variables OPENTYPEFONTS and TTFONTS of texmf.cnf. + The current working directory comes as “.” (texlive) or absolute + path (miktex) and will always be filtered out. +--doc]]-- + --- dbobj -> dbobj -> bool? -> (int * int) local scan_texmf_fonts = function (fontnames, newfontnames, dry_run) - local n_scanned, n_new = 0, 0 - --[[ - This function scans all fonts in the texmf tree, through kpathsea - variables OPENTYPEFONTS and TTFONTS of texmf.cnf - ]] - if stringis_empty(kpseexpand_path("$OSFONTDIR")) then - report("info", 2, "db", "Scanning TEXMF fonts...") + local n_scanned, n_new, fontdirs = 0, 0 + local osfontdir = kpseexpand_path "$OSFONTDIR" + if stringis_empty (osfontdir) then + report ("info", 2, "db", "Scanning TEXMF fonts...") else - report("info", 2, "db", "Scanning TEXMF and OS fonts...") + report ("info", 2, "db", "Scanning TEXMF and OS fonts...") + if logs.get_loglevel () > 3 then + local osdirs = filesplitpath (osfontdir) + report ("info", 0, "db", + "$OSFONTDIR has %d entries:", #osdirs) + for i = 1, #osdirs do + report ("info", 0, "db", "[%d] %s", i, osdirs[i]) + end + end end - local fontdirs = stringgsub(kpseexpand_path("$OPENTYPEFONTS"), "^%.", "") - fontdirs = fontdirs .. stringgsub(kpseexpand_path("$TTFONTS"), "^%.", "") - if not stringis_empty(fontdirs) then - for _,d in next, filesplitpath(fontdirs) do - local found, new = scan_dir(d, fontnames, newfontnames, dry_run, true) + fontdirs = kpseexpand_path "$OPENTYPEFONTS" + fontdirs = fontdirs .. (ostype == "windows" and ";" or ":") + .. kpseexpand_path "$TTFONTS" + if not stringis_empty (fontdirs) then + local tasks = filter_out_pwd (filesplitpath (fontdirs)) + report ("info", 3, "db", + "Initiating scan of %d directories.", #tasks) + for _, d in next, tasks do + local found, new = scan_dir (d, fontnames, newfontnames, + dry_run, true) n_scanned = n_scanned + found n_new = n_new + new end -- cgit v1.2.3