[latex3-commits] [git/LaTeX3-latex3-latex3] exp_args_generate: Speed up \exp_args by using the general form for many more signatures (4abfee1)

Bruno Le Floch bruno at le-floch.fr
Sun Feb 10 17:55:07 CET 2019


Repository : https://github.com/latex3/latex3
On branch  : exp_args_generate
Link       : https://github.com/latex3/latex3/commit/4abfee1996a3db04568172133bd1f852ff5539f4

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

commit 4abfee1996a3db04568172133bd1f852ff5539f4
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Feb 10 17:55:07 2019 +0100

    Speed up \exp_args by using the general form for many more signatures


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

4abfee1996a3db04568172133bd1f852ff5539f4
 l3kernel/l3expan.dtx                    |  203 ++++++++++++++++---------------
 l3kernel/testfiles/m3expl001.luatex.tlg |   84 ++++++-------
 l3kernel/testfiles/m3expl003.luatex.tlg |   84 ++++++-------
 3 files changed, 188 insertions(+), 183 deletions(-)

diff --git a/l3kernel/l3expan.dtx b/l3kernel/l3expan.dtx
index 23e9e5c..068dc1e 100644
--- a/l3kernel/l3expan.dtx
+++ b/l3kernel/l3expan.dtx
@@ -1399,98 +1399,13 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \subsection{Definitions with the automated technique}
-% \label{sec:l3expan:gendef}
-%
-% Some of these could be done more efficiently, but the complexity of
-% coding then becomes an issue. Notice that the auto-generated functions
-% actually take no arguments themselves.
-%
 % \begin{macro}{\exp_args:Nx}
 %    \begin{macrocode}
-\cs_new_protected:Npn \exp_args:Nx { \::x \::: }
+\cs_new_protected:Npn \exp_args:Nx #1#2
+  { \use:x { \exp_not:N #1 {#2} } }
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[EXP]
-%   {
-%     \exp_args:Nnc, \exp_args:Nno, \exp_args:NnV, \exp_args:Nnv, \exp_args:Nne, \exp_args:Nnf,
-%     \exp_args:Noc, \exp_args:Noo, \exp_args:Nof,
-%     \exp_args:NVo, \exp_args:Nfo, \exp_args:Nff,
-%   }
-% \begin{macro}
-%   {
-%     \exp_args:NNx, \exp_args:Ncx, \exp_args:Nnx,
-%     \exp_args:Nox, \exp_args:Nxo, \exp_args:Nxx,
-%   }
-%   Here are the actual function definitions, using the helper functions
-%   above.
-%    \begin{macrocode}
-\cs_new:Npn \exp_args:Nnc { \::n \::c \::: }
-\cs_new:Npn \exp_args:Nno { \::n \::o \::: }
-\cs_new:Npn \exp_args:NnV { \::n \::V \::: }
-\cs_new:Npn \exp_args:Nnv { \::n \::v \::: }
-\cs_new:Npn \exp_args:Nne { \::n \::e \::: }
-\cs_new:Npn \exp_args:Nnf { \::n \::f \::: }
-\cs_new:Npn \exp_args:Noc { \::o \::c \::: }
-\cs_new:Npn \exp_args:Noo { \::o \::o \::: }
-\cs_new:Npn \exp_args:Nof { \::o \::f \::: }
-\cs_new:Npn \exp_args:NVo { \::V \::o \::: }
-\cs_new:Npn \exp_args:Nfo { \::f \::o \::: }
-\cs_new:Npn \exp_args:Nff { \::f \::f \::: }
-\cs_new_protected:Npn \exp_args:NNx { \::N \::x \::: }
-\cs_new_protected:Npn \exp_args:Ncx { \::c \::x \::: }
-\cs_new_protected:Npn \exp_args:Nnx { \::n \::x \::: }
-\cs_new_protected:Npn \exp_args:Nox { \::o \::x \::: }
-\cs_new_protected:Npn \exp_args:Nxo { \::x \::o \::: }
-\cs_new_protected:Npn \exp_args:Nxx { \::x \::x \::: }
-%    \end{macrocode}
-% \end{macro}
-% \end{macro}
-%
-% \begin{macro}[EXP]
-%   {
-%     \exp_args:NNcf,
-%     \exp_args:NNno, \exp_args:NNnV, \exp_args:NNoo, \exp_args:NNVV,
-%     \exp_args:Ncno, \exp_args:NcnV, \exp_args:Ncoo, \exp_args:NcVV,
-%     \exp_args:Nnnc, \exp_args:Nnno, \exp_args:Nnnf, \exp_args:Nnff,
-%     \exp_args:Nooo, \exp_args:Noof, \exp_args:Nffo,
-%   }
-% \begin{macro}
-%   {
-%     \exp_args:NNNx, \exp_args:NNnx, \exp_args:NNox,
-%     \exp_args:Nccx, \exp_args:Ncnx,
-%     \exp_args:Nnnx, \exp_args:Nnox, \exp_args:Noox,
-%   }
-%    \begin{macrocode}
-\cs_new:Npn \exp_args:NNcf { \::N \::c \::f \::: }
-\cs_new:Npn \exp_args:NNno { \::N \::n \::o \::: }
-\cs_new:Npn \exp_args:NNnV { \::N \::n \::V \::: }
-\cs_new:Npn \exp_args:NNoo { \::N \::o \::o \::: }
-\cs_new:Npn \exp_args:NNVV { \::N \::V \::V \::: }
-\cs_new:Npn \exp_args:Ncno { \::c \::n \::o \::: }
-\cs_new:Npn \exp_args:NcnV { \::c \::n \::V \::: }
-\cs_new:Npn \exp_args:Ncoo { \::c \::o \::o \::: }
-\cs_new:Npn \exp_args:NcVV { \::c \::V \::V \::: }
-\cs_new:Npn \exp_args:Nnnc { \::n \::n \::c \::: }
-\cs_new:Npn \exp_args:Nnno { \::n \::n \::o \::: }
-\cs_new:Npn \exp_args:Nnnf { \::n \::n \::f \::: }
-\cs_new:Npn \exp_args:Nnff { \::n \::f \::f \::: }
-\cs_new:Npn \exp_args:Nooo { \::o \::o \::o \::: }
-\cs_new:Npn \exp_args:Noof { \::o \::o \::f \::: }
-\cs_new:Npn \exp_args:Nffo { \::f \::f \::o \::: }
-\cs_new_protected:Npn \exp_args:NNNx { \::N \::N \::x \::: }
-\cs_new_protected:Npn \exp_args:NNnx { \::N \::n \::x \::: }
-\cs_new_protected:Npn \exp_args:NNox { \::N \::o \::x \::: }
-\cs_new_protected:Npn \exp_args:Nnnx { \::n \::n \::x \::: }
-\cs_new_protected:Npn \exp_args:Nnox { \::n \::o \::x \::: }
-\cs_new_protected:Npn \exp_args:Nccx { \::c \::c \::x \::: }
-\cs_new_protected:Npn \exp_args:Ncnx { \::c \::n \::x \::: }
-\cs_new_protected:Npn \exp_args:Noox { \::o \::o \::x \::: }
-%    \end{macrocode}
-% \end{macro}
-% \end{macro}
-%
 % \subsection{Last-unbraced versions}
 %
 % \begin{macro}[EXP]{\@@_arg_last_unbraced:nn}
@@ -2643,16 +2558,14 @@
   {
     \use_none:n #5
     \use_none:n #7
-    \if_case:w
-      \if:w N #5 1 ~ \fi:
-      \if:w c #5 2 ~ \fi:
-      \if:w x #5 3 ~ \fi:
-      4 ~
-    \or: \exp_after:wN \use_i:nnnn
-    \or: \exp_after:wN \use_ii:nnnn
-    \or: \exp_after:wN \use_iii:nnnn
-    \or: \exp_after:wN \use_iv:nnnn
-    \fi:
+    \cs:w
+      use_
+      \if:w N #5 i \else:
+      \if:w c #5 ii \else:
+      \if:w x #5 iii \else:
+      iv \fi: \fi: \fi:
+      :nnnn
+    \cs_end:
     { \@@_generate_internal_loop:nwnnw { \exp_not:N ## #7 } }
     { \@@_generate_internal_loop:nwnnw { \exp_not:c { ## #7 } } }
     { \@@_generate_internal_loop:nwnnw { { ## #7 } } }
@@ -2754,8 +2667,7 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\exp_args_generate:n, \@@_args_generate:Nn}
-% \begin{macro}[EXP]{\@@_args_generate:n}
+% \begin{macro}{\exp_args_generate:n}
 %   This function is not used in the kernel hence we can use functions
 %   that are defined in later modules.  It also does not need to be fast
 %   so use inline mappings.  For each requested variant we check that
@@ -2780,6 +2692,99 @@
   }
 %    \end{macrocode}
 % \end{macro}
+%
+% \subsection{Definitions with the automated technique}
+% \label{sec:l3expan:gendef}
+%
+% Some of these could be done more efficiently, but the complexity of
+% coding then becomes an issue. Notice that the auto-generated functions
+% actually take no arguments themselves.
+%
+% \begin{macro}[EXP]
+%   {
+%     \exp_args:Nnc, \exp_args:Nno, \exp_args:NnV, \exp_args:Nnv, \exp_args:Nne, \exp_args:Nnf,
+%     \exp_args:Noc, \exp_args:Noo, \exp_args:Nof,
+%     \exp_args:NVo, \exp_args:Nfo, \exp_args:Nff,
+%   }
+% \begin{macro}
+%   {
+%     \exp_args:NNx, \exp_args:Ncx, \exp_args:Nnx,
+%     \exp_args:Nox, \exp_args:Nxo, \exp_args:Nxx,
+%   }
+%   Here are the actual function definitions, using the helper
+%   functions above.  The group is used because
+%   \cs{@@_generate_internal_variant:n} redefines \cs{@@_tmp:w} locally.
+%    \begin{macrocode}
+\cs_set_protected:Npn \@@_tmp:w #1
+  {
+    \group_begin:
+      \exp_args:No \@@_generate_internal_variant:n
+        { \tl_to_str:n {#1} }
+    \group_end:
+  }
+\@@_tmp:w { nc }
+\@@_tmp:w { no }
+\@@_tmp:w { nV }
+\@@_tmp:w { nv }
+\@@_tmp:w { ne }
+\@@_tmp:w { nf }
+\@@_tmp:w { oc }
+\@@_tmp:w { oo }
+\@@_tmp:w { of }
+\@@_tmp:w { Vo }
+\@@_tmp:w { fo }
+\@@_tmp:w { ff }
+\@@_tmp:w { Nx }
+\@@_tmp:w { cx }
+\@@_tmp:w { nx }
+\@@_tmp:w { ox }
+\@@_tmp:w { xo }
+\@@_tmp:w { xx }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[EXP]
+%   {
+%     \exp_args:NNcf,
+%     \exp_args:NNno, \exp_args:NNnV, \exp_args:NNoo, \exp_args:NNVV,
+%     \exp_args:Ncno, \exp_args:NcnV, \exp_args:Ncoo, \exp_args:NcVV,
+%     \exp_args:Nnnc, \exp_args:Nnno, \exp_args:Nnnf, \exp_args:Nnff,
+%     \exp_args:Nooo, \exp_args:Noof, \exp_args:Nffo,
+%   }
+% \begin{macro}
+%   {
+%     \exp_args:NNNx, \exp_args:NNnx, \exp_args:NNox,
+%     \exp_args:Nccx, \exp_args:Ncnx,
+%     \exp_args:Nnnx, \exp_args:Nnox, \exp_args:Noox,
+%   }
+%    \begin{macrocode}
+\@@_tmp:w { Ncf }
+\@@_tmp:w { Nno }
+\@@_tmp:w { NnV }
+\@@_tmp:w { Noo }
+\@@_tmp:w { NVV }
+\@@_tmp:w { cno }
+\@@_tmp:w { cnV }
+\@@_tmp:w { coo }
+\@@_tmp:w { cVV }
+\@@_tmp:w { nnc }
+\@@_tmp:w { nno }
+\@@_tmp:w { nnf }
+\@@_tmp:w { nff }
+\@@_tmp:w { ooo }
+\@@_tmp:w { oof }
+\@@_tmp:w { ffo }
+\@@_tmp:w { NNx }
+\@@_tmp:w { Nnx }
+\@@_tmp:w { Nox }
+\@@_tmp:w { nnx }
+\@@_tmp:w { nox }
+\@@_tmp:w { ccx }
+\@@_tmp:w { cnx }
+\@@_tmp:w { oox }
+%    \end{macrocode}
+% \end{macro}
 % \end{macro}
 %
 %    \begin{macrocode}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 051789e..817eb0b 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -176,48 +176,6 @@ Defining \exp_args:NcNc on line ...
 Defining \exp_args:NcNo on line ...
 Defining \exp_args:Ncco on line ...
 Defining \exp_args:Nx on line ...
-Defining \exp_args:Nnc on line ...
-Defining \exp_args:Nno on line ...
-Defining \exp_args:NnV on line ...
-Defining \exp_args:Nnv on line ...
-Defining \exp_args:Nne on line ...
-Defining \exp_args:Nnf on line ...
-Defining \exp_args:Noc on line ...
-Defining \exp_args:Noo on line ...
-Defining \exp_args:Nof on line ...
-Defining \exp_args:NVo on line ...
-Defining \exp_args:Nfo on line ...
-Defining \exp_args:Nff on line ...
-Defining \exp_args:NNx on line ...
-Defining \exp_args:Ncx on line ...
-Defining \exp_args:Nnx on line ...
-Defining \exp_args:Nox on line ...
-Defining \exp_args:Nxo on line ...
-Defining \exp_args:Nxx on line ...
-Defining \exp_args:NNcf on line ...
-Defining \exp_args:NNno on line ...
-Defining \exp_args:NNnV on line ...
-Defining \exp_args:NNoo on line ...
-Defining \exp_args:NNVV on line ...
-Defining \exp_args:Ncno on line ...
-Defining \exp_args:NcnV on line ...
-Defining \exp_args:Ncoo on line ...
-Defining \exp_args:NcVV on line ...
-Defining \exp_args:Nnnc on line ...
-Defining \exp_args:Nnno on line ...
-Defining \exp_args:Nnnf on line ...
-Defining \exp_args:Nnff on line ...
-Defining \exp_args:Nooo on line ...
-Defining \exp_args:Noof on line ...
-Defining \exp_args:Nffo on line ...
-Defining \exp_args:NNNx on line ...
-Defining \exp_args:NNnx on line ...
-Defining \exp_args:NNox on line ...
-Defining \exp_args:Nnnx on line ...
-Defining \exp_args:Nnox on line ...
-Defining \exp_args:Nccx on line ...
-Defining \exp_args:Ncnx on line ...
-Defining \exp_args:Noox on line ...
 Defining \__exp_arg_last_unbraced:nn on line ...
 Defining \::o_unbraced on line ...
 Defining \::V_unbraced on line ...
@@ -292,6 +250,48 @@ Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
 Defining \exp_args_generate:n on line ...
+Defining \exp_args:Nnc on line ...
+Defining \exp_args:Nno on line ...
+Defining \exp_args:NnV on line ...
+Defining \exp_args:Nnv on line ...
+Defining \exp_args:Nne on line ...
+Defining \exp_args:Nnf on line ...
+Defining \exp_args:Noc on line ...
+Defining \exp_args:Noo on line ...
+Defining \exp_args:Nof on line ...
+Defining \exp_args:NVo on line ...
+Defining \exp_args:Nfo on line ...
+Defining \exp_args:Nff on line ...
+Defining \exp_args:NNx on line ...
+Defining \exp_args:Ncx on line ...
+Defining \exp_args:Nnx on line ...
+Defining \exp_args:Nox on line ...
+Defining \exp_args:Nxo on line ...
+Defining \exp_args:Nxx on line ...
+Defining \exp_args:NNcf on line ...
+Defining \exp_args:NNno on line ...
+Defining \exp_args:NNnV on line ...
+Defining \exp_args:NNoo on line ...
+Defining \exp_args:NNVV on line ...
+Defining \exp_args:Ncno on line ...
+Defining \exp_args:NcnV on line ...
+Defining \exp_args:Ncoo on line ...
+Defining \exp_args:NcVV on line ...
+Defining \exp_args:Nnnc on line ...
+Defining \exp_args:Nnno on line ...
+Defining \exp_args:Nnnf on line ...
+Defining \exp_args:Nnff on line ...
+Defining \exp_args:Nooo on line ...
+Defining \exp_args:Noof on line ...
+Defining \exp_args:Nffo on line ...
+Defining \exp_args:NNNx on line ...
+Defining \exp_args:NNnx on line ...
+Defining \exp_args:NNox on line ...
+Defining \exp_args:Nnnx on line ...
+Defining \exp_args:Nnox on line ...
+Defining \exp_args:Nccx on line ...
+Defining \exp_args:Ncnx on line ...
+Defining \exp_args:Noox on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 051789e..817eb0b 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -176,48 +176,6 @@ Defining \exp_args:NcNc on line ...
 Defining \exp_args:NcNo on line ...
 Defining \exp_args:Ncco on line ...
 Defining \exp_args:Nx on line ...
-Defining \exp_args:Nnc on line ...
-Defining \exp_args:Nno on line ...
-Defining \exp_args:NnV on line ...
-Defining \exp_args:Nnv on line ...
-Defining \exp_args:Nne on line ...
-Defining \exp_args:Nnf on line ...
-Defining \exp_args:Noc on line ...
-Defining \exp_args:Noo on line ...
-Defining \exp_args:Nof on line ...
-Defining \exp_args:NVo on line ...
-Defining \exp_args:Nfo on line ...
-Defining \exp_args:Nff on line ...
-Defining \exp_args:NNx on line ...
-Defining \exp_args:Ncx on line ...
-Defining \exp_args:Nnx on line ...
-Defining \exp_args:Nox on line ...
-Defining \exp_args:Nxo on line ...
-Defining \exp_args:Nxx on line ...
-Defining \exp_args:NNcf on line ...
-Defining \exp_args:NNno on line ...
-Defining \exp_args:NNnV on line ...
-Defining \exp_args:NNoo on line ...
-Defining \exp_args:NNVV on line ...
-Defining \exp_args:Ncno on line ...
-Defining \exp_args:NcnV on line ...
-Defining \exp_args:Ncoo on line ...
-Defining \exp_args:NcVV on line ...
-Defining \exp_args:Nnnc on line ...
-Defining \exp_args:Nnno on line ...
-Defining \exp_args:Nnnf on line ...
-Defining \exp_args:Nnff on line ...
-Defining \exp_args:Nooo on line ...
-Defining \exp_args:Noof on line ...
-Defining \exp_args:Nffo on line ...
-Defining \exp_args:NNNx on line ...
-Defining \exp_args:NNnx on line ...
-Defining \exp_args:NNox on line ...
-Defining \exp_args:Nnnx on line ...
-Defining \exp_args:Nnox on line ...
-Defining \exp_args:Nccx on line ...
-Defining \exp_args:Ncnx on line ...
-Defining \exp_args:Noox on line ...
 Defining \__exp_arg_last_unbraced:nn on line ...
 Defining \::o_unbraced on line ...
 Defining \::V_unbraced on line ...
@@ -292,6 +250,48 @@ Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
 Defining \exp_args_generate:n on line ...
+Defining \exp_args:Nnc on line ...
+Defining \exp_args:Nno on line ...
+Defining \exp_args:NnV on line ...
+Defining \exp_args:Nnv on line ...
+Defining \exp_args:Nne on line ...
+Defining \exp_args:Nnf on line ...
+Defining \exp_args:Noc on line ...
+Defining \exp_args:Noo on line ...
+Defining \exp_args:Nof on line ...
+Defining \exp_args:NVo on line ...
+Defining \exp_args:Nfo on line ...
+Defining \exp_args:Nff on line ...
+Defining \exp_args:NNx on line ...
+Defining \exp_args:Ncx on line ...
+Defining \exp_args:Nnx on line ...
+Defining \exp_args:Nox on line ...
+Defining \exp_args:Nxo on line ...
+Defining \exp_args:Nxx on line ...
+Defining \exp_args:NNcf on line ...
+Defining \exp_args:NNno on line ...
+Defining \exp_args:NNnV on line ...
+Defining \exp_args:NNoo on line ...
+Defining \exp_args:NNVV on line ...
+Defining \exp_args:Ncno on line ...
+Defining \exp_args:NcnV on line ...
+Defining \exp_args:Ncoo on line ...
+Defining \exp_args:NcVV on line ...
+Defining \exp_args:Nnnc on line ...
+Defining \exp_args:Nnno on line ...
+Defining \exp_args:Nnnf on line ...
+Defining \exp_args:Nnff on line ...
+Defining \exp_args:Nooo on line ...
+Defining \exp_args:Noof on line ...
+Defining \exp_args:Nffo on line ...
+Defining \exp_args:NNNx on line ...
+Defining \exp_args:NNnx on line ...
+Defining \exp_args:NNox on line ...
+Defining \exp_args:Nnnx on line ...
+Defining \exp_args:Nnox on line ...
+Defining \exp_args:Nccx on line ...
+Defining \exp_args:Ncnx on line ...
+Defining \exp_args:Noox on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...





More information about the latex3-commits mailing list