[latex3-commits] [git/LaTeX3-latex3-latex3] master: Speed up \prop_map_function:NN and \prop_map_tokens:Nn (bc91a4e)

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


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

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

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

    Speed up \prop_map_function:NN and \prop_map_tokens:Nn


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

bc91a4ee2c773990a84dfe3157d5caa0ddd115f5
 l3kernel/l3candidates.dtx |   22 ++++++++++------------
 l3kernel/l3prop.dtx       |   20 +++++++++-----------
 2 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 818965c..a6278e1 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -2204,25 +2204,23 @@
 %
 % \begin{macro}[rEXP]{\prop_map_tokens:Nn, \prop_map_tokens:cn}
 % \begin{macro}{\@@_map_tokens:nwwn}
-%   The mapping is very similar to \cs{prop_map_function:NN}.  It grabs
-%   one key--value pair at a time, and stops when reaching the marker
-%   key \cs{q_recursion_tail}, which cannot appear in normal keys since
-%   those are strings.  The odd construction |\use:n {#1}| allows |#1|
-%   to contain any token without interfering with \cs{prop_map_break:}.
-%   Argument |#2| of \cs{@@_map_tokens:nwwn} is \cs{s_@@} the first
-%   time, and is otherwise empty.
+%   The mapping is very similar to \cs{prop_map_function:NN}.  The
+%   \cs{use_i:nn} removes the leading \cs{s_@@}.  The odd construction
+%   |\use:n {#1}| allows |#1| to contain any token without interfering
+%   with \cs{prop_map_break:}.  The loop stops when the argument
+%   delimited by \cs{@@_pair:wn} is \cs{prg_break:} instead of being
+%   empty.
 %    \begin{macrocode}
 \cs_new:Npn \prop_map_tokens:Nn #1#2
   {
-    \exp_last_unbraced:Nno \@@_map_tokens:nwwn {#2} #1
-      \@@_pair:wn \q_recursion_tail \s_@@ { }
+    \exp_last_unbraced:Nno
+      \use_i:nn { \@@_map_tokens:nwwn {#2} } #1
+      \prg_break: \@@_pair:wn \s_@@ { } \prg_break_point:
     \prg_break_point:Nn \prop_map_break: { }
   }
 \cs_new:Npn \@@_map_tokens:nwwn #1#2 \@@_pair:wn #3 \s_@@ #4
   {
-    \if_meaning:w \q_recursion_tail #3
-      \exp_after:wN \prop_map_break:
-    \fi:
+    #2
     \use:n {#1} {#3} {#4}
     \@@_map_tokens:nwwn {#1}
   }
diff --git a/l3kernel/l3prop.dtx b/l3kernel/l3prop.dtx
index f8c953a..df0ee77 100644
--- a/l3kernel/l3prop.dtx
+++ b/l3kernel/l3prop.dtx
@@ -1110,24 +1110,22 @@
 %     \prop_map_function:cN, \prop_map_function:cc
 %   }
 % \begin{macro}{\@@_map_function:Nwwn}
-%   The fastest way to do a recursion here is to use an
-%   \cs{if_meaning:w} test: the keys are strings, and thus cannot match
-%   the marker \cs{q_recursion_tail}.  A special case to note is when
-%   the key~|#3| is empty: then \cs{q_recursion_tail} is compared to
-%   \cs{exp_after:wN}, also different.  Note that |#2|~is empty, except
-%   at the first iteration, where it is \cs{s_@@}.
+%   The argument delimited by \cs{@@_pair:wn} is empty except at the end
+%   of the loop where it is \cs{prg_break:}.  No need for any quark
+%   test.
 %    \begin{macrocode}
 \cs_new:Npn \prop_map_function:NN #1#2
   {
-    \exp_last_unbraced:NNo \@@_map_function:Nwwn #2 #1
-      \@@_pair:wn \q_recursion_tail \s_@@ { }
+    \exp_after:wN \use_i_ii:nnn
+    \exp_after:wN \@@_map_function:Nwwn
+    \exp_after:wN #2
+    #1
+    \prg_break: \@@_pair:wn \s_@@ { } \prg_break_point:
     \prg_break_point:Nn \prop_map_break: { }
   }
 \cs_new:Npn \@@_map_function:Nwwn #1#2 \@@_pair:wn #3 \s_@@ #4
   {
-    \if_meaning:w \q_recursion_tail #3
-      \exp_after:wN \prop_map_break:
-    \fi:
+    #2
     #1 {#3} {#4}
     \@@_map_function:Nwwn #1
   }





More information about the latex3-commits mailing list