[latex3-commits] [latex3/latex2e] gh1189: Retain one level of indirection in optimised ltcmd defs (7d3e79e6)

github at latex-project.org github at latex-project.org
Tue Nov 28 14:22:11 CET 2023


Repository : https://github.com/latex3/latex2e
On branch  : gh1189
Link       : https://github.com/latex3/latex2e/commit/7d3e79e6e092b68cf97787ca40baa77ed1b57665

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

commit 7d3e79e6e092b68cf97787ca40baa77ed1b57665
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Nov 28 13:19:47 2023 +0000

    Retain one level of indirection in optimised ltcmd defs


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

7d3e79e6e092b68cf97787ca40baa77ed1b57665
 base/ltcmd.dtx                           | 22 +++++++++---
 base/testfiles-ltcmd/github-1009.tlg     | 16 ++++-----
 base/testfiles-ltcmd/ltcmd001.tlg        | 59 ++++++++++++++++----------------
 base/testfiles-ltcmd/ltcmd002.luatex.tlg |  2 +-
 base/testfiles-ltcmd/ltcmd002.tlg        |  2 +-
 5 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx
index a611d688..1798230e 100644
--- a/base/ltcmd.dtx
+++ b/base/ltcmd.dtx
@@ -442,6 +442,11 @@
 %     \@@_declare_cmd_code_aux:Nnn,
 %     \@@_declare_cmd_code_expandable:Nnn
 %   }
+% \begin{macro}
+%   {
+%     \@@_declare_cmd_optimised:NNNn,
+%     \@@_declare_cmd_optimised:NcNn
+%   }
 % \changes{v1.2b}{2023/11/28}
 %   {Optimise cmd creation for all-\texttt{m} arguments}
 %   At this stage we can check for a short-cut possibility: if the signature
@@ -465,15 +470,23 @@
    }
 %    \end{macrocode}
 %   The optimised version of commands just has to worry about whether to make
-%   them protected.
+%   them protected. We retain one level of indirection so it is still clear
+%   these are \pkg{ltcmd}-derived.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_declare_cmd_optimised:Nnn #1#2#3
   {
     \bool_if:NTF \l_@@_expandable_bool
-      { \cs_generate_from_arg_count:NNnn #1 \cs_set_nopar:Npn }
-      { \cs_generate_from_arg_count:NNnn #1 \cs_set_protected_nopar:Npn }
-        \l_@@_current_arg_int {#3}
+      { \@@_declare_cmd_optimised:NcNn \cs_set_nopar:Npn }
+      { \@@_declare_cmd_optimised:NcNn \cs_set_protected_nopar:Npn }
+        { \l_@@_function_tl \c_space_tl code } #1 {#3}
   }
+\cs_new_protected:Npn \@@_declare_cmd_optimised:NNNn #1#2#3#4
+  {
+    #1 #3 {#2}
+    \cs_generate_from_arg_count:NNnn #2 #1
+      \l_@@_current_arg_int {#4}
+  }
+\cs_generate_variant:Nn \@@_declare_cmd_optimised:NNNn { Nc }
 %    \end{macrocode}
 %   Standard functions call \cs{@@_start:nNNnnn}, which receives the
 %   argument specification, an auxiliary used for
@@ -572,6 +585,7 @@
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+% \end{macro}
 %
 % \begin{macro}{\@@_declare_env:nnnn}
 % \begin{macro}{\@@_declare_env_internal:nnnn}
diff --git a/base/testfiles-ltcmd/github-1009.tlg b/base/testfiles-ltcmd/github-1009.tlg
index a586b9ef..7640ca94 100644
--- a/base/testfiles-ltcmd/github-1009.tlg
+++ b/base/testfiles-ltcmd/github-1009.tlg
@@ -4,19 +4,19 @@ Don't change this file in any respect.
 TEST 1: Non-expandable Document Commands with m-type arguments
 ============================================================
 > \foo=\protected macro:
-->.
+->\foo code .
 <argument> \foo 
 l. ...}
 > \baz=\protected macro:
-->.
+->\foo code .
 <argument> \baz 
 l. ...}
 > \foo=\protected macro:
-#1->.
+->\foo code .
 <argument> \foo 
 l. ...}
 > \baz=\protected macro:
-#1->.
+->\foo code .
 <argument> \baz 
 l. ...}
 > \foo=document command:
@@ -44,19 +44,19 @@ l. ...}
 TEST 2: Expandable Document Commands with m-type arguments
 ============================================================
 > \foo=macro:
-->.
+->\foo code .
 <argument> \foo 
 l. ...}
 > \baz=macro:
-->.
+->\foo code .
 <argument> \baz 
 l. ...}
 > \foo=macro:
-#1->.
+->\foo code .
 <argument> \foo 
 l. ...}
 > \baz=macro:
-#1->.
+->\foo code .
 <argument> \baz 
 l. ...}
 > \foo=expandable document command:
diff --git a/base/testfiles-ltcmd/ltcmd001.tlg b/base/testfiles-ltcmd/ltcmd001.tlg
index 824392d2..0b834e99 100644
--- a/base/testfiles-ltcmd/ltcmd001.tlg
+++ b/base/testfiles-ltcmd/ltcmd001.tlg
@@ -17,69 +17,70 @@ For immediate help type H <return>.
 l. ...}
 You have used \RenewDocumentCommand with a command that was never defined.
 LaTeX will ignore this entire definition.
-> \foo=\protected macro:->First definition.
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:->First definition.
 <recently read> }
 l. ...}
 ============================================================
 ============================================================
 TEST 2: Commands with simple mandatory arguments
 ============================================================
-> \foo=\protected macro:#1->(#1).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:#1->(#1).
 <recently read> }
 l. ...}
-> \foo=\protected macro:#1#2->(#1)(#2).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:#1#2->(#1)(#2).
 <recently read> }
 l. ...}
-> \foo=\protected macro:#1#2#3->(#1)(#2)(#3).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:#1#2#3->(#1)(#2)(#3).
 <recently read> }
 l. ...}
-> \foo=\protected macro:#1#2#3#4->(#1)(#2)(#3)(#4).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:#1#2#3#4->(#1)(#2)(#3)(#4).
 <recently read> }
 l. ...}
-> \foo=\protected macro:#1#2#3#4#5->(#1)(#2)(#3)(#4)(#5).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:#1#2#3#4#5->(#1)(#2)(#3)(#4)(#5).
 <recently read> }
 l. ...}
-> \foo=\protected macro:#1#2#3#4#5#6->(#1)(#2)(#3)(#4)(#5)(#6).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:#1#2#3#4#5#6->(#1)(#2)(#3)(#4)(#5)(#6).
 <recently read> }
 l. ...}
-> \foo=\protected macro:#1#2#3#4#5#6#7->(#1)(#2)(#3)(#4)(#5)(#6)(#7).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected macro:#1#2#3#4#5#6#7->(#1)(#2)(#3)(#4)(#5)(#6)(#7).
 <recently read> }
 l. ...}
-> \foo=\protected macro:#1#2#3#4#5#6#7#8->(#1)(#2)(#3)(#4)(#5)(#6)(#7)(#8).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected
+macro:#1#2#3#4#5#6#7#8->(#1)(#2)(#3)(#4)(#5)(#6)(#7)(#8).
 <recently read> }
 l. ...}
-> \foo=\protected
-macro:#1#2#3#4#5#6#7#8#9->(#1)(#2)(#3)(#4)(#5)(#6)(#7)(#8)(#9).
+> \foo=\protected macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=\protected
+macro:#1#2#3#4#5#6#7#8#9->(#1)(#2)(#3)(#4)(#5)(#6)(#7)(#8)(#9).
 <recently read> }
 l. ...}
 ============================================================
@@ -321,10 +322,10 @@ l. ...}
 ============================================================
 TEST 8: Some valid expandable functions
 ============================================================
-> \foo=macro:#1->(#1).
+> \foo=macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=macro:#1->(#1).
 <recently read> }
 l. ...}
 > \foo=macro:->\__cmd_start_expandable:nNNNNn {+m}\foo  \foo  \foo code
@@ -334,10 +335,10 @@ l. ...}
 > \foo code=\long macro:#1->(#1).
 <recently read> }
 l. ...}
-> \foo=macro:#1#2#3->(#1)(#2)(#3).
+> \foo=macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=\long macro:#1->(#1).
+> \foo code=macro:#1#2#3->(#1)(#2)(#3).
 <recently read> }
 l. ...}
 > \foo=macro:->\__cmd_start_expandable:nNNNNn {om}\foo  \foo  \foo code
@@ -437,10 +438,10 @@ l. ...}
 You have used \RenewDocumentEnvironment with an environment that was never
 defined.
 LaTeX will ignore this entire definition.
-> \environment foo=\protected macro:->First.
+> \environment foo=\protected macro:->\environment foo code .
 <recently read> }
 l. ...}
-> \environment foo code=undefined.
+> \environment foo code=\protected macro:->First.
 <recently read> }
 l. ...}
 ============================================================
@@ -695,10 +696,10 @@ l. ...}
 You have used \RenewExpandableDocumentCommand with a command that was never
 defined.
 LaTeX will ignore this entire definition.
-> \foo=macro:->First definition.
+> \foo=macro:->\foo code .
 <recently read> }
 l. ...}
-> \foo code=undefined.
+> \foo code=macro:->First definition.
 <recently read> }
 l. ...}
 ============================================================
diff --git a/base/testfiles-ltcmd/ltcmd002.luatex.tlg b/base/testfiles-ltcmd/ltcmd002.luatex.tlg
index 62d4d73c..39a66403 100644
--- a/base/testfiles-ltcmd/ltcmd002.luatex.tlg
+++ b/base/testfiles-ltcmd/ltcmd002.luatex.tlg
@@ -48,7 +48,7 @@ TEST 2: Nesting optional arguments
 TEST 3: Invalid arguments (types s, o m)
 ============================================================
 Runaway argument?
-! Paragraph ended before \foo was complete.
+! Paragraph ended before \foo code was complete.
 <to be read again> 
 \par 
 l. ...}
diff --git a/base/testfiles-ltcmd/ltcmd002.tlg b/base/testfiles-ltcmd/ltcmd002.tlg
index 3a5fbeb9..cad76a7b 100644
--- a/base/testfiles-ltcmd/ltcmd002.tlg
+++ b/base/testfiles-ltcmd/ltcmd002.tlg
@@ -48,7 +48,7 @@ TEST 2: Nesting optional arguments
 TEST 3: Invalid arguments (types s, o m)
 ============================================================
 Runaway argument?
-! Paragraph ended before \foo was complete.
+! Paragraph ended before \foo code was complete.
 <to be read again> 
                    \par 
 l. ...}





More information about the latex3-commits mailing list.