[latex3-commits] [git/l3build] master: avoid iterating multiple times when maindir==sourcefiledir, etc (dce9590)
Will Robertson
wspr81 at gmail.com
Tue Jan 2 04:27:48 CET 2018
Repository : https://github.com/latex3/l3build
On branch : master
Link : https://github.com/latex3/l3build/commit/dce959087d47cf1f878cfb1fe0badc9955505296
>---------------------------------------------------------------
commit dce959087d47cf1f878cfb1fe0badc9955505296
Author: Will Robertson <wspr81 at gmail.com>
Date: Tue Jan 2 11:25:51 2018 +0800
avoid iterating multiple times when maindir==sourcefiledir, etc
>---------------------------------------------------------------
dce959087d47cf1f878cfb1fe0badc9955505296
l3build.lua | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/l3build.lua b/l3build.lua
index cf45bc4..2416bde 100644
--- a/l3build.lua
+++ b/l3build.lua
@@ -739,6 +739,22 @@ function tree(path, glob)
return dirs
end
+function remove_duplicates(a)
+ -- Return array with duplicate entries removed from input array `a`.
+
+ local uniq = {}
+ local hash = {}
+
+ for _,v in ipairs(a) do
+ if (not hash[v]) then
+ hash[v] = true
+ uniq[#uniq+1] = v
+ end
+ end
+
+ return uniq
+end
+
function mkdir(dir)
if os_type == "windows" then
-- Windows (with the extensions) will automatically make directory trees
@@ -1959,7 +1975,7 @@ function clean()
cleandir(typesetdir) +
cleandir(unpackdir)
for _,i in ipairs(cleanfiles) do
- for _,dir in pairs({maindir, sourcefiledir, docfiledir}) do
+ for _,dir in pairs(remove_duplicates({maindir, sourcefiledir, docfiledir})) do
errorlevel = rm(dir, i) + errorlevel
end
end
@@ -2332,7 +2348,7 @@ function setversion()
end
local date = options["date"] or os_date("%Y-%m-%d")
local version = options["version"] or -1
- for _,dir in pairs({currentdir, sourcefiledir, docfiledir}) do
+ for _,dir in pairs(remove_duplicates({currentdir, sourcefiledir, docfiledir})) do
for _,i in pairs(versionfiles) do
for file,_ in pairs(tree(dir, i)) do
rewrite(dir, file, date, version)
More information about the latex3-commits
mailing list