[latex3-commits] [git/LaTeX3-latex3-latex3] master: faster tl_if_head_is_N_type:n (2e3ddea40)

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/2e3ddea40d755497b3c585ba3f976367c7d92ff1

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

commit 2e3ddea40d755497b3c585ba3f976367c7d92ff1
Author: Jonathan Spratte <jspratte at yahoo.de>
Date:   Sun Aug 9 18:23:38 2020 +0200

    faster tl_if_head_is_N_type:n


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

2e3ddea40d755497b3c585ba3f976367c7d92ff1
 l3kernel/l3tl.dtx | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index 68eaf5989..d4a1987e8 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -3088,36 +3088,50 @@
 % \end{macro}
 %
 % \begin{macro}[pTF]{\tl_if_head_is_N_type:n}
-% \begin{macro}[EXP]{\@@_if_head_is_N_type:w}
+% \begin{macro}[EXP]
+%   {
+%     \@@_if_head_is_N_type_auxi:w   ,
+%     \@@_if_head_is_N_type_auxii:nn ,
+%     \@@_if_head_is_N_type_auxiii:n
+%   }
 %   A token list can be empty, can start with an explicit space
 %   character (catcode 10 and charcode 32), can start with a begin-group
 %   token (catcode 1), or start with an \texttt{N}-type argument.  In
-%   the first two cases, the line involving \cs{@@_if_head_is_N_type:w}
-%   produces~|^| (and otherwise nothing).  In the third case
-%   (begin-group token), the lines involving \cs{exp_after:wN} produce a
+%   the first two cases, the line involving \cs{@@_if_head_is_N_type_auxi:w}
+%   produces~|f| (and otherwise nothing).  In the third case
+%   (begin-group token), the lines involving \cs{token_to_str:N} produce a
 %   single closing brace.  The category code test is thus true exactly
 %   in the fourth case, which is what we want.  One cannot optimize by
-%   moving one of the |*| to the beginning: if |#1| contains primitive
+%   moving one of the |\scan_stop:| to the beginning: if |#1| contains primitive
 %   conditionals, all of its occurrences must be dealt with before the
 %   \cs{if_catcode:w} tries to skip the \texttt{true} branch of the
 %   conditional.
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \tl_if_head_is_N_type:n #1 { p , T , F , TF }
   {
-    \if_catcode:w
-        \if_false: { \fi: \@@_if_head_is_N_type:w ? #1 ~ }
-        \exp_after:wN \use_none:n
-          \exp_after:wN { \exp_after:wN { \token_to_str:N #1 ? } }
-        * *
+    \if:w
+        \if_false: { \fi: \@@_if_head_is_N_type_auxi:w \prg_do_nothing: #1 ~ }
+        { \exp_after:wN { \token_to_str:N #1 } }
+        \scan_stop: \scan_stop:
       \prg_return_true:
     \else:
       \prg_return_false:
     \fi:
   }
-\cs_new:Npn \@@_if_head_is_N_type:w #1 ~
+\cs_new:Npn \@@_if_head_is_N_type_auxi:w #1 ~
   {
-    \tl_if_empty:oTF { \use_none:n #1 } { ^ } { }
-    \exp_after:wN \use_none:n \exp_after:wN { \if_false: } \fi:
+    \tl_if_empty:oTF { #1 }
+      { \exp_after:wN \@@_if_head_is_N_type_auxii:nn }
+      { \exp_after:wN \@@_if_head_is_N_type_auxiii:n }
+    \exp_after:wN { \if_false: } \fi: 
+  }
+\cs_new:Npn \@@_if_head_is_N_type_auxii:nn #1 #2
+  {
+    f
+  }
+\cs_new:Npn \@@_if_head_is_N_type_auxiii:n #1
+  {
+    \exp_after:wN \use_none:n \exp_after:wN 
   }
 %    \end{macrocode}
 % \end{macro}





More information about the latex3-commits mailing list.