[latex3-commits] [latex3/latex2e] file-if-exist: Use expl3 file-exists test (5d1dabb4)
github at latex-project.org
github at latex-project.org
Mon May 15 23:53:43 CEST 2023
Repository : https://github.com/latex3/latex2e
On branch : file-if-exist
Link : https://github.com/latex3/latex2e/commit/5d1dabb4b1ea37e02e3551adbec5ebc4175c9e2a
>---------------------------------------------------------------
commit 5d1dabb4b1ea37e02e3551adbec5ebc4175c9e2a
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon May 15 13:10:26 2023 +0100
Use expl3 file-exists test
I have not made changes to \@iffileonpath,
but it could be dropped from current release.
>---------------------------------------------------------------
5d1dabb4b1ea37e02e3551adbec5ebc4175c9e2a
base/changes.txt | 4 ++
base/doc/ltnews37.tex | 8 +++
base/ltfiles.dtx | 65 ++++++++++++++++++----
base/testfiles-lthooks/lthooks-rollback-args.tlg | 6 +-
base/testfiles/github-0479-often.tlg | 6 +-
.../tlb-latexrelease-rollback-003-often.tlg | 14 +++--
.../tlb-latexrelease-rollback-2020-10-01.tlg | 6 +-
.../tlb-latexrelease-rollback-2021-06-01.tlg | 4 +-
.../tlb-latexrelease-rollback-2021-11-15.tlg | 4 +-
.../tlb-latexrelease-rollback-2022-06-01.tlg | 4 +-
.../tlb-latexrelease-rollback-2022-11-01.tlg | 4 +-
base/testfiles/tlb-rollback-004-often.tlg | 6 +-
base/testfiles/tlb-rollback-005.tlg | 6 +-
13 files changed, 107 insertions(+), 30 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index 186c1fb9..27a8acde 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -6,6 +6,10 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
================================================================================
+2023-05-15 Joseph Wright <Joseph.Wright at latex-project.org>
+
+ * lffiles.dtx:
+ Use expl3-based file-existence test
2023-05-13 David Carlisle <David.Carlisle at latex-project.org>
diff --git a/base/doc/ltnews37.tex b/base/doc/ltnews37.tex
index 70d1cbde..8c9ae41e 100644
--- a/base/doc/ltnews37.tex
+++ b/base/doc/ltnews37.tex
@@ -361,6 +361,14 @@ not use grouping.
\section{Code improvements}
+\subsection{Performance in checking file existence}
+
+The additon of hooks, etc., to file operations had a side-effect in that
+multiple checks were made that the file existed. In larger documents using
+lots of files, these filesystem operations caused non-trivial performance
+impact. We now cache the existence of files, such that these repeated filesystem
+calls are avoided.
+
\subsection{\pkg{doc}: Handle \texttt{\textbackslash\textvisiblespace} correctly in the index}
Due to some problems in the code it wasn't possible to prevent
diff --git a/base/ltfiles.dtx b/base/ltfiles.dtx
index 04256529..dcbc7e94 100644
--- a/base/ltfiles.dtx
+++ b/base/ltfiles.dtx
@@ -32,7 +32,7 @@
%<*driver>
% \fi
\ProvidesFile{ltfiles.dtx}
- [2023/01/05 v1.2s LaTeX Kernel (File Handling)]
+ [2023/05/15 v1.2t LaTeX Kernel (File Handling)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfiles.dtx}
@@ -1202,6 +1202,9 @@
% \changes{v1.0t}{1995/05/25}{(CAR) added \cs{long}}
% \changes{v1.2d}{2019/10/26}{quote on openin}
% \changes{v1.2k}{2021/03/12}{Allow unbalanced conditionals (gh/530)}
+% \changes{v1.2t}{2023/05/15}{Use \pkg{expl3} file existence test}
+% \begin{macro}{\IfFileExists@}
+% \changes{v1.2t}{2023/05/15}{Macro added}
% Argument |#1| is |\@curr at file| so catcode 12 string with no quotes.
%
% The original definition picked up arguments |#2| and |#3| in a
@@ -1211,23 +1214,35 @@
% \cs{secondoftwo}. However, that changes how |#| is interpreted
% and so we can't do that nowaways without invalidating a lot of
% code. Therefore the somewhat curious construction near the end.
+%
+% Earlier versions used |\openin| here, but this led to two
+% code paths, one in \pkg{expl3} and one here. To avoid that,
+% and as the \pkg{expl3} approach works by expansion, we use
+% that here. As we need the file name to include the path,
+% the actual \pkg{expl3} function used is not the file existence
+% test!
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
-%<latexrelease>\IncludeInRelease{2021/06/01}%
-%<latexrelease> {\IfFileExists@}{manage unbalanced conditionals}
+%<latexrelease>\IncludeInRelease{2023/05/01}%
+%<latexrelease> {\IfFileExists@}{Cache file status}
\long\def \IfFileExists@#1#2#3{%
- \openin\@inputcheck"#1" %
- \ifeof\@inputcheck
- \ifx\input at path\@undefined
- \let\reserved at a\@secondoftwo
+ \edef\@filef at und{\IfFileExists@@{#1}}%
+% \end{macrocode}
+% The \pkg{expl3} function regards an empty argument as nothing at all,
+% but the \LaTeXe{} convention is that this is equal to the special
+% \texttt{.tex} file.
+% \begin{macrocode}
+ \ifx\@filef at und\@empty
+ \if\relax\detokenize{#1}\relax
+ \let\reserved at a\@firstoftwo
+ \def\@filef at und{".tex" }%
\else
- \def\reserved at a{\@iffileonpath{#1}}%
+ \let\reserved at a\@secondoftwo
\fi
\else
- \closein\@inputcheck
- \edef\@filef at und{"#1" }%
\let\reserved at a\@firstoftwo
+ \edef\@filef at und{"\@filef at und" }%
\fi
% \end{macrocode}
% This is just there so that any |#| inside |#2| or |#3| needs
@@ -1236,8 +1251,36 @@
\expandafter\def\expandafter\reserved at a
\expandafter{\reserved at a{#2}{#3}}%
\reserved at a}
+\ExplSyntaxOn
+\cs_new_eq:NN \IfFileExists@@ \file_full_name:n
+\ExplSyntaxOff
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{2021/06/01}%
+%<latexrelease> {\IfFileExists@}{Cache file status}
+%<latexrelease>
+%<latexrelease>\long\def \IfFileExists@#1#2#3{%
+%<latexrelease> \openin\@inputcheck"#1" %
+%<latexrelease> \ifeof\@inputcheck
+%<latexrelease> \ifx\input at path\@undefined
+%<latexrelease> \let\reserved at a\@secondoftwo
+%<latexrelease> \else
+%<latexrelease> \def\reserved at a{\@iffileonpath{#1}}%
+%<latexrelease> \fi
+%<latexrelease> \else
+%<latexrelease> \closein\@inputcheck
+%<latexrelease> \edef\@filef at und{"#1" }%
+%<latexrelease> \let\reserved at a\@firstoftwo
+%<latexrelease> \fi
+%<latexrelease> \expandafter\def\expandafter\reserved at a
+%<latexrelease> \expandafter{\reserved at a{#2}{#3}}%
+%<latexrelease>\reserved at a}
+%<latexrelease>\let\IfFileExists@@\@undefined
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{0000/00/00}%
+%<latexrelease> {\IfFileExists@}{Cache file status}
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease> {\IfFileExists@}{manage unbalanced conditionals}
%<latexrelease>
@@ -1266,7 +1309,7 @@
%<*2ekernel>
% \end{macrocode}
% \end{macro}
-%
+% \end{macro}
%
%
%
diff --git a/base/testfiles-lthooks/lthooks-rollback-args.tlg b/base/testfiles-lthooks/lthooks-rollback-args.tlg
index 0a9a63db..43930234 100644
--- a/base/testfiles-lthooks/lthooks-rollback-args.tlg
+++ b/base/testfiles-lthooks/lthooks-rollback-args.tlg
@@ -292,8 +292,10 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
Already applied: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/github-0479-often.tlg b/base/testfiles/github-0479-often.tlg
index 88cc8f43..bdb44b0e 100644
--- a/base/testfiles/github-0479-often.tlg
+++ b/base/testfiles/github-0479-often.tlg
@@ -292,8 +292,10 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
Already applied: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-003-often.tlg b/base/testfiles/tlb-latexrelease-rollback-003-often.tlg
index 6c29fbaf..2f75652d 100644
--- a/base/testfiles/tlb-latexrelease-rollback-003-often.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-003-often.tlg
@@ -272,9 +272,11 @@ Skipping: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Spaces in file names and hooks on input line ....
Skipping: [....-..-..] Quote file names on input line ....
Applying: [....-..-..] Quote file names on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Skipping: [....-..-..] Quote file names on input line ....
Already applied: [....-..-..] Quote file names on input line ....
Skipping: [....-..-..] Don't lose the file name on input line ....
@@ -999,8 +1001,10 @@ Applying: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
Already applied: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-2020-10-01.tlg b/base/testfiles/tlb-latexrelease-rollback-2020-10-01.tlg
index a10978b1..86c11033 100644
--- a/base/testfiles/tlb-latexrelease-rollback-2020-10-01.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-2020-10-01.tlg
@@ -292,8 +292,10 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
Already applied: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-2021-06-01.tlg b/base/testfiles/tlb-latexrelease-rollback-2021-06-01.tlg
index 9d324368..ad4fc81a 100644
--- a/base/testfiles/tlb-latexrelease-rollback-2021-06-01.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-2021-06-01.tlg
@@ -292,7 +292,9 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] Cache file status on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-2021-11-15.tlg b/base/testfiles/tlb-latexrelease-rollback-2021-11-15.tlg
index 28c71105..114bfdd8 100644
--- a/base/testfiles/tlb-latexrelease-rollback-2021-11-15.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-2021-11-15.tlg
@@ -292,7 +292,9 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] Cache file status on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-2022-06-01.tlg b/base/testfiles/tlb-latexrelease-rollback-2022-06-01.tlg
index de6d1bf8..8bdfd4c7 100644
--- a/base/testfiles/tlb-latexrelease-rollback-2022-06-01.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-2022-06-01.tlg
@@ -293,7 +293,9 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] Cache file status on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-2022-11-01.tlg b/base/testfiles/tlb-latexrelease-rollback-2022-11-01.tlg
index 6a99a3bf..fb7a01b6 100644
--- a/base/testfiles/tlb-latexrelease-rollback-2022-11-01.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-2022-11-01.tlg
@@ -293,7 +293,9 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] Cache file status on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-rollback-004-often.tlg b/base/testfiles/tlb-rollback-004-often.tlg
index 8ac21136..295cffd3 100644
--- a/base/testfiles/tlb-rollback-004-often.tlg
+++ b/base/testfiles/tlb-rollback-004-often.tlg
@@ -292,8 +292,10 @@ Applying: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
Already applied: [....-..-..] Quote file names on input line ....
diff --git a/base/testfiles/tlb-rollback-005.tlg b/base/testfiles/tlb-rollback-005.tlg
index b9348a14..cebbaa58 100644
--- a/base/testfiles/tlb-rollback-005.tlg
+++ b/base/testfiles/tlb-rollback-005.tlg
@@ -296,8 +296,10 @@ Already applied: [....-..-..] Spaces in file names and hooks on input line ....
Applying: [....-..-..] Quote file names on input line ....
LaTeX Info: Redefining \IfFileExists on input line ....
Already applied: [....-..-..] Quote file names on input line ....
-Skipping: [....-..-..] manage unbalanced conditionals on input line ....
-Applying: [....-..-..] manage unbalanced conditionals on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Skipping: [....-..-..] Cache file status on input line ....
+Applying: [....-..-..] Cache file status on input line ....
+Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Already applied: [....-..-..] manage unbalanced conditionals on input line ....
Applying: [....-..-..] Quote file names on input line ....
Already applied: [....-..-..] Quote file names on input line ....
More information about the latex3-commits
mailing list.