[latex3-commits] [git/LaTeX3-latex3-latex3] l3text: Re-order 'expander' code for performance (903f4681c)

Joseph Wright joseph.wright at morningstar2.co.uk
Sun Dec 8 01:04:17 CET 2019


Repository : https://github.com/latex3/latex3
On branch  : l3text
Link       : https://github.com/latex3/latex3/commit/903f4681c63ef4eabc847e7077a9c8ebd6ee4192

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

commit 903f4681c63ef4eabc847e7077a9c8ebd6ee4192
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sun Dec 8 00:04:17 2019 +0000

    Re-order 'expander' code for performance
    
    The most common case will be character tokens, so bias for that.


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

903f4681c63ef4eabc847e7077a9c8ebd6ee4192
 l3kernel/l3text.dtx | 58 +++++++++++++++++++++++++++--------------------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index 37b660e10..8bff981dd 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -521,7 +521,12 @@
 % \begin{macro}[EXP]{\@@_expand_math_N_type:NN}
 % \begin{macro}[EXP]{\@@_expand_math_group:Nn}
 % \begin{macro}[EXP]{\@@_expand_math_space:Nw}
-% \begin{macro}[EXP]{\@@_expand_exclude:N}
+% \begin{macro}[EXP]
+%   {
+%     \@@_expand_implicit:N ,
+%     \@@_expand_explicit:N ,
+%     \@@_expand_exclude:N
+%   }
 % \begin{macro}[EXP]{\@@_expand_exclude:nN}
 % \begin{macro}[EXP]{\@@_expand_exclude:NN}
 % \begin{macro}[EXP]{\@@_expand_exclude:Nn}
@@ -529,8 +534,6 @@
 % \begin{macro}[EXP]{\@@_expand_letterlike:NN}
 % \begin{macro}[EXP]
 %   {
-%     \@@_expand_implicit:N ,
-%     \@@_expand_explicit:N ,
 %     \@@_expand_cs:N       ,
 %     \@@_expand_protect:N
 %   }
@@ -697,7 +700,7 @@
 \cs_new:Npn \@@_expand_math_search:NNN #1#2#3
   {
     \quark_if_recursion_tail_stop_do:Nn #2
-      { \@@_expand_exclude:N #1 }
+      { \@@_expand_implicit:N #1 }
     \token_if_eq_meaning:NNTF #1 #2
       {
         \use_i_delimit_by_q_recursion_stop:nw
@@ -740,6 +743,28 @@
     \@@_expand_math_loop:Nw #1
   }
 %    \end{macrocode}
+%   Conversion of implicit to explicit tokens does not have to account for
+%   spaces or brace groups: they are already fixed above. So we can assume that
+%   the result of this conversion is still an \texttt{N}-type token.
+%    \begin{macrocode}
+\cs_new:Npn \@@_expand_implicit:N #1
+  {
+    \exp_args:NNe \use:nn \@@_expand_explicit:N
+      { \@@_token_to_explicit:N #1 }
+  }
+%    \end{macrocode}
+%   At this stage, either we have a control sequence or a simple character:
+%   split and handle.
+%    \begin{macrocode}
+\cs_new:Npn \@@_expand_explicit:N #1
+  {
+    \token_if_cs:NTF #1
+      { \@@_expand_exclude:N #1 }
+      {
+        \@@_expand_store:n {#1}
+        \@@_expand_loop:w 
+      }
+  }
 %   Next we exclude any commands with one argument that are explicitly
 %   listed. This is mainly as there \emph{might} be an \cs{ensuremath},
 %   but one never knows about for example accents in labels too. We also deal
@@ -789,7 +814,7 @@
 \cs_new:Npn \@@_expand_letterlike:NN #1#2
   {
     \quark_if_recursion_tail_stop_do:Nn #2
-      { \@@_expand_implicit:N #1 }
+      { \@@_expand_cs:N #1 }
     \cs_if_eq:NNTF #2 #1
       {
         \use_i_delimit_by_q_recursion_stop:nw
@@ -801,29 +826,6 @@
       { \@@_expand_letterlike:NN #1 }
   }
 %    \end{macrocode}
-%   Conversion of implicit to explicit tokens does not have to account for
-%   spaces or brace groups: they are already fixed above. So we can assume that
-%   the result of this conversion is still an \texttt{N}-type token.
-%    \begin{macrocode}
-\cs_new:Npn \@@_expand_implicit:N #1
-  {
-    \exp_args:NNe \use:nn \@@_expand_explicit:N
-      { \@@_token_to_explicit:N #1 }
-  }
-%    \end{macrocode}
-%   At this stage, either we have a control sequence or a simple character:
-%   split and handle.
-%    \begin{macrocode}
-\cs_new:Npn \@@_expand_explicit:N #1
-  {
-    \token_if_cs:NTF #1
-      { \@@_expand_cs:N #1 }
-      {
-        \@@_expand_store:n {#1}
-        \@@_expand_loop:w 
-      }
-  }
-%    \end{macrocode}
 %   \LaTeXe{}'s \cs{protect} makes life interesting. Where possible, we
 %   simply remove it and replace with the \enquote{parent} command; of course,
 %   the \cs{protect} might be explicit, in which case we need to leave it alone





More information about the latex3-commits mailing list