[latex3-commits] [latex3/latex2e] gh1078: Avoid token-by-token processing when possible (5ef0799f)

github at latex-project.org github at latex-project.org
Fri Jun 2 05:24:21 CEST 2023


Repository : https://github.com/latex3/latex2e
On branch  : gh1078
Link       : https://github.com/latex3/latex2e/commit/5ef0799f1efc02d8a1913d8ddf7b7c09b9de633a

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

commit 5ef0799f1efc02d8a1913d8ddf7b7c09b9de633a
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Fri Jun 2 00:24:21 2023 -0300

    Avoid token-by-token processing when possible
    
    When a hook is declared and takes no argument, then roundtrip of
    doubling hashes is unnecessary, so skip it.
    
    Partially fixes #1078


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

5ef0799f1efc02d8a1913d8ddf7b7c09b9de633a
 base/lthooks.dtx                       | 26 +++++++++++++++++-
 base/testfiles-lthooks/github-1078.lvt | 50 ++++++++++++++++++++++++++++++++++
 base/testfiles-lthooks/github-1078.tlg |  3 ++
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index c0efe2c9..328830d3 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -4424,6 +4424,7 @@
 % \end{macro}
 %
 % \begin{macro}{\@@_cs_gput_right:nnn}
+% \begin{macro}{\@@_cs_gput_right_fast:nnn,\@@_cs_gput_right_slow:nnn}
 % \begin{macro}{\@@_code_gset_auxi:nnnn,\@@_code_gset_auxi:eeen}
 %   This macro is used to append code to the \verb|toplevel| and
 %   \verb|next| token lists, trating them correctly depending on their
@@ -4435,7 +4436,27 @@
 %    \begin{macrocode}
 %<latexrelease>\IncludeInRelease{2023/06/01}{\@@_cs_gput_right:nnn}
 %<latexrelease>                 {Hooks~with~args}
-\cs_new_protected:Npn \@@_cs_gput_right:nnn #1 #2 #3
+%    \end{macrocode}
+%
+%   Check if the current hook is declared and takes no arguments.  In
+%   this case, we short-circuit and use the simpler and much faster
+%   approach that doesn't require hash-doubling.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_cs_gput_right:nnn #1 #2
+  {
+    \if:w T
+        \@@_if_declared:nF {#2} { F }
+        \tl_if_empty:cF { c_@@_#2_parameter_tl } { F }
+          T
+      \exp_after:wN \@@_cs_gput_right_fast:nnn
+    \else:
+      \exp_after:wN \@@_cs_gput_right_slow:nnn
+    \fi:
+        {#1} {#2}
+  }
+\cs_new_protected:Npn \@@_cs_gput_right_fast:nnn #1 #2 #3
+  { \cs_gset:cpx { @@#1~#2 } { \exp_not:v { @@#1~#2 } \exp_not:n {#3} } }
+\cs_new_protected:Npn \@@_cs_gput_right_slow:nnn #1 #2 #3
   {
 %    \end{macrocode}
 %   The auxiliary \cs{@@_code_gset_auxi:eeen} just does the assignment
@@ -4498,11 +4519,14 @@
 %<latexrelease>\IncludeInRelease{2020/10/01}{\@@_cs_gput_right:nnn}
 %<latexrelease>                 {Hooks~with~args}
 %<latexrelease>\cs_undefine:N \@@_cs_gput_right:nnn
+%<latexrelease>\cs_undefine:N \@@_cs_gput_right_fast:nnn
+%<latexrelease>\cs_undefine:N \@@_cs_gput_right_slow:nnn
 %<latexrelease>\cs_undefine:N \@@_code_gset_auxi:nnnn
 %<latexrelease>\EndIncludeInRelease
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+% \end{macro}
 %
 % \begin{macro}{
 %     \@@_code_gset:nn,\@@_code_gset:ne,
diff --git a/base/testfiles-lthooks/github-1078.lvt b/base/testfiles-lthooks/github-1078.lvt
new file mode 100644
index 00000000..082de732
--- /dev/null
+++ b/base/testfiles-lthooks/github-1078.lvt
@@ -0,0 +1,50 @@
+
+\input{regression-test}
+
+\START
+
+\ExplSyntaxOn
+\tex_resettimer:D
+\int_step_inline:nn{15}
+  {
+    \AddToHook{begindocument}
+      {
+        \def\blub
+          {
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+          }
+      }
+  }
+% On my machine, with LaTeX 2022-11-01, this prints around 320
+% \typeout { Elapsed~time = \the \tex_elapsedtime:D }
+% With LaTeX 2023-06-01, it goes past 360000
+% So 10000 seems like a good theshold to make the test pass or fail,
+% regardless of which machine it's running on.  This can be tweaked
+% though:
+\int_compare:nNnTF { \tex_elapsedtime:D } > { 10000 }
+  { \iow_term:n { ERROR!~Too~slow. } }
+  { \iow_term:n { Looks~okay. } }
+
+\OMIT
+\makeatletter
+\typeout { Elapsed~time = \strip at pt \dimexpr \tex_elapsedtime:D sp ~ s }
+\TIMO
+
+\ExplSyntaxOff
+
+\END
diff --git a/base/testfiles-lthooks/github-1078.tlg b/base/testfiles-lthooks/github-1078.tlg
new file mode 100644
index 00000000..366f5e73
--- /dev/null
+++ b/base/testfiles-lthooks/github-1078.tlg
@@ -0,0 +1,3 @@
+This is a generated file for the l3build validation system.
+Don't change this file in any respect.
+Looks okay.





More information about the latex3-commits mailing list.