[latex3-commits] [git/LaTeX3-latex3-latex3] master: faster __tl_act:NNNnn (21b192160)
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/21b1921600d1d5eba656fec464c0d9e11d13e119
>---------------------------------------------------------------
commit 21b1921600d1d5eba656fec464c0d9e11d13e119
Author: Jonathan Spratte <jspratte at yahoo.de>
Date: Fri Oct 2 20:40:50 2020 +0200
faster __tl_act:NNNnn
>---------------------------------------------------------------
21b1921600d1d5eba656fec464c0d9e11d13e119
l3kernel/l3tl.dtx | 110 ++++++++++++++++++++++++++++++++++++------------------
1 file changed, 73 insertions(+), 37 deletions(-)
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index 31abe912a..481b09121 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -2805,14 +2805,13 @@
%
% \subsection{Token by token changes}
%
-% \begin{variable}{\q_@@_act_mark, \q_@@_act_stop}
+% \begin{variable}{\q_@@_act_stop}
% The \cs[no-index]{@@_act_\ldots{}} functions may be applied to any token list.
-% Hence, we use two private quarks, to allow any token, even quarks,
+% Hence, we use a private quark, to allow any token, even quarks,
% in the token list.
-% Only \cs{q_@@_act_mark} and \cs{q_@@_act_stop} may not appear
-% in the token lists manipulated by \cs{@@_act:NNNnn} functions.
+% Only \cs{q_@@_act_stop} may not appear in the token lists manipulated by
+% \cs{@@_act:NNNnn} functions.
% \begin{macrocode}
-\quark_new:N \q_@@_act_mark
\quark_new:N \q_@@_act_stop
% \end{macrocode}
% \end{variable}
@@ -2824,67 +2823,102 @@
% \begin{macro}[EXP]{\@@_act_group:nwnNNN}
% \begin{macro}[EXP]{\@@_act_space:wwnNNN}
% \begin{macro}[EXP]{\@@_act_end:w}
+% \begin{macro}[EXP]
+% {
+% \@@_act_if_head_is_space:nTF,
+% \@@_act_if_head_is_space:w,
+% \@@_act_if_head_is_space_true:w
+% }
+% \begin{macro}[EXP]{\@@_use_none_delimit_by_q_act_stop:w}
% To help control the expansion, \cs{@@_act:NNNnn} should always
% be proceeded by \cs{exp:w} and ends by producing \cs{exp_end:}
% once the result has been obtained. Then loop over tokens,
-% groups, and spaces in |#5|. The marker \cs{q_@@_act_mark}
-% is used both to avoid losing outer braces and to detect the
-% end of the token list more easily. The result is stored
-% as an argument for the dummy function \cs{@@_act_result:n}.
+% groups, and spaces in |#5|. |{\q_@@_act_stop}| serves as the end of token
+% list marker, the |?| after it avoids losing outer braces. The result is
+% stored as an argument for the dummy function \cs{@@_act_result:n}.
% \begin{macrocode}
-\cs_new:Npn \@@_act:NNNnn #1#2#3#4#5
+\exp_args:Nno \use:n { \cs_new:Npn \@@_act:NNNnn #1#2#3#4#5 }
{
\group_align_safe_begin:
- \@@_act_loop:w #5 \q_@@_act_mark \q_@@_act_stop
- {#4} #1 #2 #3
+ \@@_act_loop:w #5 {\q_@@_act_stop} ? \q_@@_act_stop
+ {#4} #1 #3 #2
\@@_act_result:n { }
}
% \end{macrocode}
+% Because \cs{q_@@_act_stop} can't appear without braces around it in the
+% argument~|#1| of \cs{@@_act_loop:w}, we can use this marker to set up a fast
+% test for leading spaces.
+% \begin{macrocode}
+\group_begin:
+ \cs_set:Npn \@@_tmp:n #1
+ {
+ \cs_new:Npn \@@_act_if_head_is_space:nTF ##1
+ {
+ \@@_act_if_head_is_space:w
+ \q_@@_act_stop ##1 \q_@@_act_stop \@@_act_if_head_is_space_true:w
+ \q_@@_act_stop #1 \q_@@_act_stop \use_ii:nn
+ }
+ \cs_new:Npn \@@_act_if_head_is_space:w
+ ##1 \q_@@_act_stop #1 ##2 \q_@@_act_stop
+ {}
+ \cs_new:Npn \@@_act_if_head_is_space_true:w
+ \q_@@_act_stop #1 \q_@@_act_stop \use_ii:nn ##1 ##2
+ {##1}
+ }
+ \@@_tmp:n { ~ }
+\group_end:
+% \end{macrocode}
% In the loop, we check how the token list begins and act
-% accordingly. In the \enquote{normal} case, we may have
-% reached \cs{q_@@_act_mark}, the end of the list. Then
+% accordingly. In the \enquote{group} case, we may have
+% reached \cs{q_@@_act_stop}, the end of the list. Then
% leave \cs{exp_end:} and the result in the input stream,
% to terminate the expansion of \cs{exp:w}.
% Otherwise, apply the relevant function to the
% \enquote{arguments}, |#3|
% and to the head of the token list. Then repeat the loop.
-% The scheme is the same if the token list starts with a
-% group or with a space. Some extra work is needed to
+% The scheme is the same if the token list starts with an |N|-type
+% or with a space. Some extra work is needed to
% make \cs{@@_act_space:wwnNNN} gobble the space.
% \begin{macrocode}
-\cs_new:Npn \@@_act_loop:w #1 \q_@@_act_stop
- {
- \tl_if_head_is_N_type:nTF {#1}
- { \@@_act_normal:NwnNNN }
- {
- \tl_if_head_is_group:nTF {#1}
- { \@@_act_group:nwnNNN }
- { \@@_act_space:wwnNNN }
- }
- #1 \q_@@_act_stop
- }
+\group_begin:
+ \cs_set_nopar:Npx \@@_tmp:
+ {
+ \__kernel_exp_not:w \exp_after:wN { \@@_act_if_head_is_space:nTF {#1} }
+ { \exp_not:N \@@_act_space:wwnNNN }
+ {
+ \__kernel_exp_not:w \exp_after:wN { \tl_if_head_is_group:nTF {#1} }
+ { \exp_not:N \@@_act_group:nwnNNN }
+ { \exp_not:N \@@_act_normal:NwnNNN }
+ }
+ }
+ \exp_args:Nno \use:n { \cs_new:Npn \@@_act_loop:w #1 \q_@@_act_stop }
+ {
+ \@@_tmp:
+ #1 \q_@@_act_stop
+ }
+\group_end:
\cs_new:Npn \@@_act_normal:NwnNNN #1 #2 \q_@@_act_stop #3#4
{
- \@@_use_none_delimit_by_q_act_mark:w #1 \@@_act_end:wn \q_@@_act_mark
#4 {#3} #1
\@@_act_loop:w #2 \q_@@_act_stop
{#3} #4
}
-\cs_new:Npn \@@_use_none_delimit_by_q_act_mark:w #1 \q_@@_act_mark { }
-\cs_new:Npn \@@_act_end:wn #1 \@@_act_result:n #2
+\cs_new:Npn \@@_use_none_delimit_by_q_act_stop:w #1 \q_@@_act_stop { }
+\exp_args:Nno \use:n { \cs_new:Npn \@@_act_end:wn #1 \__tl_act_result:n #2 }
{ \group_align_safe_end: \exp_end: #2 }
-\cs_new:Npn \@@_act_group:nwnNNN #1 #2 \q_@@_act_stop #3#4#5
+\cs_new:Npn \@@_act_group:nwnNNN #1 #2 \q_@@_act_stop #3#4#5#6
{
- #5 {#3} {#1}
+ \@@_use_none_delimit_by_q_act_stop:w #1 \@@_act_end:wn \q_@@_act_stop
+ #6 {#3} {#1}
\@@_act_loop:w #2 \q_@@_act_stop
- {#3} #4 #5
+ {#3} #4 #5 #6
}
\exp_last_unbraced:NNo
- \cs_new:Npn \@@_act_space:wwnNNN \c_space_tl #1 \q_@@_act_stop #2#3#4#5
+ \cs_new:Npn \@@_act_space:wwnNNN \c_space_tl #1 \q_@@_act_stop #2#3#4
{
- #5 {#2}
+ #4 {#2}
\@@_act_loop:w #1 \q_@@_act_stop
- {#2} #3 #4 #5
+ {#2} #3 #4
}
% \end{macrocode}
% Typically, the output is done to the right of what was already output,
@@ -2903,6 +2937,8 @@
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
+% \end{macro}
%
% \begin{macro}[EXP]{\tl_reverse:n, \tl_reverse:o, \tl_reverse:V}
% \begin{macro}[EXP]{\@@_reverse_normal:nN}
@@ -3222,7 +3258,7 @@
\prg_return_false:
\fi:
}
-\cs_new:Npn \@@_if_head_is_N_type_auxi:w #1 ~
+\exp_args:Nno \use:n { \cs_new:Npn \@@_if_head_is_N_type_auxi:w #1 ~ }
{
\tl_if_empty:oTF { #1 }
{ f \exp_after:wN \use_none:nn }
More information about the latex3-commits
mailing list.