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(-) 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