[latex3-commits] [git/LaTeX3-latex3-latex3] master: faster tl_head:n (edc55f386)

Bruno Le Floch blflatex at gmail.com
Tue Oct 27 09:11:58 CET 2020


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

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

commit edc55f38690cb088d1a651dbddaebc8291370f35
Author: Jonathan Spratte <jspratte at yahoo.de>
Date:   Tue Aug 18 21:33:04 2020 +0200

    faster tl_head:n


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

edc55f38690cb088d1a651dbddaebc8291370f35
 l3kernel/l3tl.dtx | 58 ++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 20 deletions(-)

diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index f6d82e4f5..644743c79 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -2953,31 +2953,49 @@
 %   empty result. The result is returned within the \tn{unexpanded} primitive.
 %   The approach here is to use \cs{if_false:} to allow us to use |}| as
 %   the closing delimiter: this is the only safe choice, as any other token
-%   would not be able to parse it's own code. Using a marker, we can see if
-%   what we are grabbing is exactly the marker, or there is anything else to
-%   deal with. Is there is, there is a loop. If not, tidy up and leave the
-%   item in the output stream. More detail in
+%   would not be able to parse it's own code. If the \tn{expanded} primitive
+%   is available it is used to get a fast and safe code variant in which we
+%   don't have to ensure that the left-most token is an internal to not break
+%   in an |f|-type expansion. If \tn{expanded} isn't available, using a marker,
+%   we can see if what we are grabbing is exactly the marker, or there is
+%   anything else to deal with. Is there is, there is a loop. If not, tidy up
+%   and leave the item in the output stream. More detail in
 %   \url{http://tex.stackexchange.com/a/70168}.
 %    \begin{macrocode}
-\cs_new:Npn \tl_head:n #1
+\cs_if_exist:NTF \tex_expanded:D
   {
-    \__kernel_exp_not:w
-      \if_false: { \fi: \@@_head_auxi:nw #1 { } \s_@@_stop }
-  }
-\cs_new:Npn \@@_head_auxi:nw #1#2 \s_@@_stop
-  {
-    \exp_after:wN \@@_head_auxii:n \exp_after:wN {
-      \if_false: } \fi: {#1}
+    \cs_new:Npn \tl_head:n #1
+      {
+        \__kernel_exp_not:w \tex_expanded:D
+          { { \if_false: { \fi: \@@_head_aux:n #1 { } } } }
+      }
+    \cs_new:Npn \@@_head_aux:n #1
+      {
+        \__kernel_exp_not:w {#1}
+        \exp_after:wN \use_none:n \exp_after:wN { \if_false: } \fi:
+      }
   }
-\exp_args:Nno \use:n
-  { \cs_new:Npn \@@_head_auxii:n #1 }
   {
-    \@@_if_empty_if:o { \use_none:n #1 }
-      \exp_after:wN \use_ii:nnn
-    \fi:
-    \use_ii:nn
-      {#1}
-      { \if_false: { \fi: \@@_head_auxi:nw #1 } }
+    \cs_new:Npn \tl_head:n #1
+      {
+        \__kernel_exp_not:w
+          \if_false: { \fi: \@@_head_auxi:nw #1 { } \s_@@_stop }
+      }
+    \cs_new:Npn \@@_head_auxi:nw #1#2 \s_@@_stop
+      {
+        \exp_after:wN \@@_head_auxii:n \exp_after:wN {
+          \if_false: } \fi: {#1}
+      }
+    \exp_args:Nno \use:n
+      { \cs_new:Npn \@@_head_auxii:n #1 }
+      {
+        \@@_if_empty_if:o { \use_none:n #1 }
+          \exp_after:wN \use_ii:nnn
+        \fi:
+        \use_ii:nn
+          {#1}
+          { \if_false: { \fi: \@@_head_auxi:nw #1 } }
+      }
   }
 \cs_generate_variant:Nn \tl_head:n { V , v , f }
 \cs_new:Npn \tl_head:w #1#2 \q_stop {#1}





More information about the latex3-commits mailing list.