[latex3-commits] [git/LaTeX3-latex3-latex3] master: Speed up \seq_get_right:NN and \seq_item:Nn slightly (7ebb35b)

Bruno Le Floch bruno at le-floch.fr
Sun Apr 29 17:19:36 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/7ebb35bd9c88060bc8f3ed744a2bb741b679110d

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

commit 7ebb35bd9c88060bc8f3ed744a2bb741b679110d
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Apr 29 11:19:36 2018 -0400

    Speed up \seq_get_right:NN and \seq_item:Nn slightly


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

7ebb35bd9c88060bc8f3ed744a2bb741b679110d
 l3kernel/l3seq.dtx                      |   51 +++++++++++++++----------------
 l3kernel/testfiles/m3expl001.luatex.tlg |    5 +--
 l3kernel/testfiles/m3expl001.ptex.tlg   |    5 +--
 l3kernel/testfiles/m3expl001.tlg        |    5 +--
 l3kernel/testfiles/m3expl001.uptex.tlg  |    5 +--
 l3kernel/testfiles/m3expl001.xetex.tlg  |    5 +--
 l3kernel/testfiles/m3expl003.luatex.tlg |    5 +--
 l3kernel/testfiles/m3expl003.ptex.tlg   |    5 +--
 l3kernel/testfiles/m3expl003.tlg        |    5 +--
 l3kernel/testfiles/m3expl003.uptex.tlg  |    5 +--
 l3kernel/testfiles/m3expl003.xetex.tlg  |    5 +--
 11 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/l3kernel/l3seq.dtx b/l3kernel/l3seq.dtx
index cd6ae0a..b5f6ba9 100644
--- a/l3kernel/l3seq.dtx
+++ b/l3kernel/l3seq.dtx
@@ -1538,30 +1538,29 @@
 %
 % \begin{macro}{\seq_get_right:NN, \seq_get_right:cN}
 % \UnitTested
-% \begin{macro}{\@@_get_right_loop:nn}
-%   First remove \cs{s_@@} and prepend \cs{q_no_value}, then take two
-%   arguments at a time.  Before the right-hand end of the sequence,
-%   this is a brace group followed by \cs{@@_item:n}, both removed by
-%   \cs{use_none:nn}.  At the end of the sequence, the two question
-%   marks are taken by \cs{use_none:nn}, and the assignment is placed
-%   before the right-most item.  In the next iteration,
-%   \cs{@@_get_right_loop:nn} receives two empty arguments, and
-%   \cs{use_none:nn} stops the loop.
+% \begin{macro}[EXP]{\@@_get_right_loop:nw, \@@_get_right_end:NnN}
+%   First remove \cs{s_@@} and prepend \cs{q_no_value}.  The first
+%   argument of \cs{@@_get_right_loop:nw} is the last item found, and
+%   the second argument is empty until the end of the loop, where it is
+%   code that applies \cs{exp_not:n} to the last item and ends the loop.
 %    \begin{macrocode}
 \cs_new_protected:Npn \seq_get_right:NN #1#2
   {
-    \exp_after:wN \use_i_ii:nnn
-    \exp_after:wN \@@_get_right_loop:nn
-    \exp_after:wN \q_no_value
-    #1
-    { ?? \tl_set:Nn #2 }
-    { } { }
+    \tl_set:Nx #2
+      {
+        \exp_after:wN \use_i_ii:nnn
+        \exp_after:wN \@@_get_right_loop:nw
+        \exp_after:wN \q_no_value
+        #1
+        \@@_get_right_end:NnN \@@_item:n
+      }
   }
-\cs_new_protected:Npn \@@_get_right_loop:nn #1#2
+\cs_new:Npn \@@_get_right_loop:nw #1#2 \@@_item:n
   {
-    \use_none:nn #2 {#1}
-    \@@_get_right_loop:nn
+    #2 \use_none:n {#1}
+    \@@_get_right_loop:nw
   }
+\cs_new:Npn \@@_get_right_end:NnN #1#2#3 { \exp_not:n {#2} }
 \cs_generate_variant:Nn \seq_get_right:NN { c }
 %    \end{macrocode}
 % \end{macro}
@@ -1669,20 +1668,20 @@
 % \end{macro}
 %
 % \begin{macro}{\seq_item:Nn, \seq_item:cn}
-% \begin{macro}{\@@_item:wNn, \@@_item:nN, \@@_item:nnn}
+% \begin{macro}{\@@_item:wNn, \@@_item:nN, \@@_item:nwn}
 %   The idea here is to find the offset of the item from the left, then use
 %   a loop to grab the correct item. If the resulting offset is too large,
-%   then the stop code |{ ? \prg_break: } { }| is used by the auxiliary,
-%   terminating the loop and returning nothing at all.
+%   then the argument delimited by \cs{@@_item:n} is \cs{prg_break:} instead
+%   of being empty, terminating the loop and returning nothing at all.
 %    \begin{macrocode}
 \cs_new:Npn \seq_item:Nn #1
   { \exp_after:wN \@@_item:wNn #1 \q_stop #1 }
 \cs_new:Npn \@@_item:wNn \s_@@ #1 \q_stop #2#3
   {
-    \exp_args:Nf \@@_item:nnn
+    \exp_args:Nf \@@_item:nwn
       { \exp_args:Nf \@@_item:nN { \int_eval:n {#3} } #2 }
     #1
-    { ? \prg_break: } { }
+    \prg_break: \@@_item:n { }
     \prg_break_point:
   }
 \cs_new:Npn \@@_item:nN #1#2
@@ -1691,12 +1690,12 @@
       { \int_eval:n { \seq_count:N #2 + 1 + #1 } }
       {#1}
   }
-\cs_new:Npn \@@_item:nnn #1#2#3
+\cs_new:Npn \@@_item:nwn #1#2 \@@_item:n #3
   {
-    \use_none:n #2
+    #2
     \int_compare:nNnTF {#1} = 1
       { \prg_break:n { \exp_not:n {#3} } }
-      { \exp_args:Nf \@@_item:nnn { \int_eval:n { #1 - 1 } } }
+      { \exp_args:Nf \@@_item:nwn { \int_eval:n { #1 - 1 } } }
   }
 \cs_generate_variant:Nn \seq_item:Nn { c }
 %    \end{macrocode}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index b7baf97..1977c47 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -1111,7 +1111,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1158,7 +1159,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 7defa58..6b7a3ca 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 3abbb76..034c0fe 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 51e3961..a976cec 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index be2ca19..71e818f 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index b7baf97..1977c47 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -1111,7 +1111,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1158,7 +1159,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 7defa58..6b7a3ca 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 3abbb76..034c0fe 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 51e3961..a976cec 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index be2ca19..71e818f 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -1109,7 +1109,8 @@ Defining \__seq_pop_left:wnwNNN on line ...
 Defining \seq_pop_left:cN on line ...
 Defining \seq_gpop_left:cN on line ...
 Defining \seq_get_right:NN on line ...
-Defining \__seq_get_right_loop:nn on line ...
+Defining \__seq_get_right_loop:nw on line ...
+Defining \__seq_get_right_end:NnN on line ...
 Defining \seq_get_right:cN on line ...
 Defining \seq_pop_right:NN on line ...
 Defining \seq_gpop_right:NN on line ...
@@ -1156,7 +1157,7 @@ Defining \seq_gpop_right:cNTF on line ...
 Defining \seq_item:Nn on line ...
 Defining \__seq_item:wNn on line ...
 Defining \__seq_item:nN on line ...
-Defining \__seq_item:nnn on line ...
+Defining \__seq_item:nwn on line ...
 Defining \seq_item:cn on line ...
 Defining \seq_map_break: on line ...
 Defining \seq_map_break:n on line ...





More information about the latex3-commits mailing list