[latex3-commits] [latex3/latex3] main: Cache file seen status (405efec66)

github at latex-project.org github at latex-project.org
Thu May 11 10:41:56 CEST 2023


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/405efec66a8df3b4ff9ff5838ca2f58377561259

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

commit 405efec66a8df3b4ff9ff5838ca2f58377561259
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed May 10 22:48:30 2023 +0100

    Cache file seen status


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

405efec66a8df3b4ff9ff5838ca2f58377561259
 l3kernel/CHANGELOG.md |  2 ++
 l3kernel/l3file.dtx   | 43 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 88aa8f257..b22cea853 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -12,6 +12,8 @@ this project uses date-based 'snapshot' version identifiers.
 
 ### Changed
 - Moved `\seq_set_item:Nnn` to stable status
+- Track seen filenames to improve performance of
+  `\file_full_name:n` and dependent file operations
 
 ### Removed
 - Experimental function `\seq_pop_item:NnN` from `l3candidates`
diff --git a/l3kernel/l3file.dtx b/l3kernel/l3file.dtx
index 4d1b0660b..e660f9af9 100644
--- a/l3kernel/l3file.dtx
+++ b/l3kernel/l3file.dtx
@@ -2815,8 +2815,8 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[EXP]{\file_full_name:n, \@@_full_name:n}
-% \begin{macro}[EXP]{\@@_full_name_aux:nn}
+% \begin{macro}[EXP]{\file_full_name:n, \@@_full_name:n, \@@_full_name_aux:n}
+% \begin{macro}[EXP]{\@@_full_name_auxi:nn, \@@_full_name_auxii:nn}
 % \begin{macro}[EXP]{\@@_full_name_aux:Nnn}
 % \begin{macro}[EXP]{\@@_full_name_aux:nN}
 % \begin{macro}[EXP]{\@@_full_name_aux:nnN}
@@ -2849,9 +2849,40 @@
 \cs_new:Npn \@@_full_name:n #1
   {
     \tl_if_blank:nF {#1}
-      { \exp_args:Nne \@@_full_name_aux:nn {#1} { \@@_size:n {#1} } }
+      { \exp_args:Nne \@@_full_name_auxii:nn {#1} { \@@_full_name_aux:n {#1} } }
   }
-\cs_new:Npn \@@_full_name_aux:nn #1 #2
+%    \end{macrocode}
+%   To avoid repeated reading of files we need to cache the loading:
+%   this is important as the code here is used by \emph{all} file checks.
+%   The same marker is used in the \LaTeXe{} kernel, meaning that we get a
+%   double-saving with for example \cs{IfFileExists}. As this is all about
+%   performance, we use the low-level approach for the conditionals. For
+%   a file already seen, the size is reported as $-1$ so it's distinct from
+%   any non-cached ones.
+%    \begin{macrocode}
+\cs_new:Npn \@@_full_name_aux:n #1
+  {
+    \if_cs_exist:w @@_seen_ \tl_to_str:n {#1} : \cs_end:
+      -1
+    \else:
+      \exp_args:Ne \@@_full_name_auxi:nn { \@@_size:n {#1} } {#1}
+    \fi:
+  }
+%    \end{macrocode}
+%   We will need the size of files later, and we have to avoid the
+%   \cs{scan_stop:} causing issues if we are raising the flag. Thus there is
+%   a slightly odd gobble here.
+%    \begin{macrocode}
+\cs_new:Npn \@@_full_name_auxi:nn #1#2
+  {
+    \if:w \scan_stop: #1 \scan_stop:
+    \else:
+      \exp_after:wN \use_none:n
+        \cs:w @@_seen_ \tl_to_str:n {#2} : \cs_end:
+    \fi:
+    #1
+  }
+\cs_new:Npn \@@_full_name_auxii:nn #1 #2
   {
     \tl_if_blank:nTF {#2}
       {
@@ -2873,7 +2904,7 @@
 \cs_new:Npn \@@_full_name_aux:Nnn #1#2#3
   { \exp_args:Ne \@@_full_name_aux:nN { \tl_to_str:n {#3} / #2 } #1 }
 \cs_new:Npn \@@_full_name_aux:nN #1
-  { \exp_args:Nne \@@_full_name_aux:nnN {#1} { \@@_size:n {#1} } }
+  { \exp_args:Nne \@@_full_name_aux:nnN {#1} { \@@_full_name_aux:n {#1} } }
 \cs_new:Npn \@@_full_name_aux:nnN #1 #2 #3
   {
     \tl_if_blank:nF {#2}
@@ -2913,7 +2944,7 @@
       { #1 #3 }
   }
 \cs_new:Npn \@@_ext_check:nnn #1
-  { \exp_args:Nne \@@_ext_check:nnnn {#1} { \@@_size:n {#1} } }
+  { \exp_args:Nne \@@_ext_check:nnnn {#1} { \@@_full_name_aux:n {#1} } }
 \cs_new:Npn \@@_ext_check:nnnn #1#2#3#4
   {
     \tl_if_blank:nTF {#2}





More information about the latex3-commits mailing list.