Skip to content

Commit

Permalink
Avoid \__tl_trim_spaces:nn
Browse files Browse the repository at this point in the history
This requires a new public function, and is slightly slower.
  • Loading branch information
josephwright committed Mar 29, 2018
1 parent dbda656 commit ffb5def
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 47 deletions.
14 changes: 6 additions & 8 deletions l3kernel/l3clist.dtx
Expand Up @@ -922,16 +922,15 @@
% containing the \meta{item}, with leading and trailing spaces
% removed. The calling function is responsible for inserting
% \cs{q_mark} in front of the \meta{item}, as well as testing for the
% end of the list. We reuse a \pkg{l3tl} internal function, whose
% first argument must start with \cs{q_mark}. That trims the item
% end of the list. That trims the item
% |#2|, then feeds the result (after having to do an \texttt{o}-type
% expansion) to \cs{@@_trim_spaces_generic:nn} which places the
% \meta{code} in front of the \meta{trimmed item}.
% \begin{macrocode}
\cs_new:Npn \@@_trim_spaces_generic:nw #1#2 ,
{
\__tl_trim_spaces:nn {#2}
{ \exp_args:No \@@_trim_spaces_generic:nn } {#1}
\tl_trim_spaces:oN { \use_none:n #2 }
{ \@@_trim_spaces_generic:nn } {#1}
}
\cs_new:Npn \@@_trim_spaces_generic:nn #1#2 { #2 {#1} }
% \end{macrocode}
Expand Down Expand Up @@ -1769,6 +1768,7 @@
% \@@_item_n:nw,
% \@@_item_n_loop:nw,
% \@@_item_n_end:n,
% \@@_item_n_strip:n,
% \@@_item_n_strip:w}
% This starts in the same way as \cs{clist_item:Nn} by counting the items
% of the comma list. The final item should be space-trimmed before being
Expand Down Expand Up @@ -1800,10 +1800,8 @@
}
}
\cs_new:Npn \@@_item_n_end:n #1 #2 \q_stop
{
\__tl_trim_spaces:nn { \q_mark #1 }
{ \exp_last_unbraced:No \@@_item_n_strip:w } ,
}
{ \tl_trim_spaces:nN {#1} { \@@_item_n_strip:n } }
\cs_new:Npn \@@_item_n_strip:n #1 { \@@_item_n_strip:w #1 , }
\cs_new:Npn \@@_item_n_strip:w #1 , { \exp_not:n {#1} }
% \end{macrocode}
% \end{macro}
Expand Down
14 changes: 5 additions & 9 deletions l3kernel/l3keys.dtx
Expand Up @@ -913,9 +913,7 @@
% The main function starts off by normalising category codes in package mode.
% That's relatively \enquote{expensive} so is skipped (hopefully) in format
% mode. We then hand off to the parser. The use of \cs{q_mark} here prevents
% loss of braces from the key argument. This particular quark is chosen as
% it fits in with \cs{__tl_trim_spaces:nn} and allows a performance enhancement
% as the token can be carried through. Notice that by passing the two
% loss of braces from the key argument. Notice that by passing the two
% processor commands along the input stack we avoid the need to track these
% at all.
% \begin{macrocode}
Expand Down Expand Up @@ -1088,15 +1086,13 @@
% \begin{macro}{\@@_def:Nn}
% \begin{macro}[EXP]{\@@_def_aux:n}
% \begin{macro}[EXP]{\@@_def_aux:w}
% First trim spaces off, then potentially remove a set of braces. By using
% the internal interface |\__tl_trim_spaces:nn| we can take advantage of the
% fact it needs a leading |\q_mark| in this process. The |\exp_after:wN|
% removes the quark, the delimited argument deals with any braces.
% First remove the leading quark, then trim spaces off, and finally remove
% a set of braces.
% \begin{macrocode}
\cs_new_protected:Npn \@@_def:Nn #1#2
{ \tl_set:Nx #1 { \__tl_trim_spaces:nn {#2} \@@_def_aux:n } }
{ \tl_set:Nx #1 { \tl_trim_spaces:oN { \use_none:n #2 } \@@_def_aux:n } }
\cs_new:Npn \@@_def_aux:n #1
{ \exp_after:wN \@@_def_aux:w #1 \q_stop }
{ \@@_def_aux:w #1 \q_stop }
\cs_new:Npn \@@_def_aux:w #1 \q_stop { \exp_not:n {#1} }
% \end{macrocode}
% \end{macro}
Expand Down
17 changes: 11 additions & 6 deletions l3kernel/l3prop.dtx
Expand Up @@ -634,14 +634,15 @@
% \@@_from_keyval:n,
% \@@_from_keyval_loop:w,
% \@@_from_keyval_split:Nw,
% \@@_from_keyval_key:n,
% \@@_from_keyval_key:w,
% \@@_from_keyval_value:n,
% \@@_from_keyval_value:w
% }
% Loop through items separated by commas, with \cs{q_mark} to avoid
% losing braces. After checking for termination, split the item at
% the first then at the second |=| (which ought to be the first of the
% trailing~|=|). At both splits, trim spaces (the internal
% \cs{__tl_trim_spaces:nn} expects the \cs{q_mark} we give it) and
% trailing~|=|). At both splits, trim spaces and
% call \cs{@@_from_keyval_key:w}, then \cs{@@_from_keyval_value:w},
% followed by the trimmed material, \cs{q_nil}, the subsequent part of
% the item, and the trailing |=|'s and \cs{q_stop}. After finding the
Expand Down Expand Up @@ -670,20 +671,24 @@
\cs_new:Npn \@@_from_keyval_loop:w #1 ,
{
\quark_if_recursion_tail_stop:o { \use_none:n #1 }
\@@_from_keyval_split:Nw \@@_from_keyval_key:w
\@@_from_keyval_split:Nw \@@_from_keyval_key:n
#1 = = \q_stop { \use_none:n #1 }
\@@_from_keyval_loop:w \q_mark
}
\cs_new:Npn \@@_from_keyval_split:Nw #1#2 =
{
\__tl_trim_spaces:nn {#2}
{ \exp_last_unbraced:No #1 } \q_nil
\tl_trim_spaces:oN { \use_none:n #2 } #1
\q_nil
}
\cs_new:Npn \@@_from_keyval_key:n #1
{ \@@_from_keyval_key:w #1 }
\cs_new:Npn \@@_from_keyval_key:w #1 \q_nil #2 \q_stop
{
\@@_from_keyval_split:Nw \@@_from_keyval_value:w
\@@_from_keyval_split:Nw \@@_from_keyval_value:n
\q_mark #2 \q_stop {#1}
}
\cs_new:Npn \@@_from_keyval_value:n #1
{ \@@_from_keyval_value:w #1 }
\cs_new:Npn \@@_from_keyval_value:w #1 \q_nil #2 \q_stop #3#4
{
\tl_if_empty:nF { #3 #1 #2 }
Expand Down
33 changes: 16 additions & 17 deletions l3kernel/l3tl.dtx
Expand Up @@ -754,7 +754,7 @@
% \end{function}
%
% \begin{function}[added = 2011-07-09, updated = 2012-06-25, EXP]
% {\tl_trim_spaces:n}
% {\tl_trim_spaces:n, \tl_trim_spaces:o}
% \begin{syntax}
% \cs{tl_trim_spaces:n} \Arg{token list}
% \end{syntax}
Expand All @@ -769,6 +769,16 @@
% \end{texnote}
% \end{function}
%
% \begin{function}[added = 2018-03-29, EXP]
% {\tl_trim_spaces:nN, \tl_trim_spaces:oN}
% \begin{syntax}
% \cs{tl_trim_spaces:nN} \Arg{token list} \meta{function}
% \end{syntax}
% Removes any leading and trailing explicit space characters
% (explicit tokens with character code~$32$ and category code~$10$)
% from the \meta{token list} and passes the result to the \meta{function}.
% \end{function}
%
% \begin{function}[added = 2011-07-09]
% {
% \tl_trim_spaces:N, \tl_trim_spaces:c,
Expand Down Expand Up @@ -1079,22 +1089,6 @@
% code and so should only be used for short-term storage.
% \end{variable}
%
% \section{Internal functions}
%
% \begin{function}{\__tl_trim_spaces:nn}
% \begin{syntax}
% \cs{__tl_trim_spaces:nn} |{ \q_mark| \meta{token list} |}| \Arg{continuation}
% \end{syntax}
% This function removes all leading and trailing explicit space
% characters from the \meta{token list}, and expands to the
% \meta{continuation}, followed by a brace group containing
% \cs{use_none:n} \cs{q_mark} \meta{trimmed token list}. For
% instance, \cs{tl_trim_spaces:n} is implemented by taking the
% \meta{continuation} to be \cs{exp_not:o}, and the \texttt{o}-type
% expansion removes the \cs{q_mark}. This function is also used in
% \pkg{l3clist} and \pkg{l3candidates}.
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
Expand Down Expand Up @@ -2378,6 +2372,7 @@
% \end{macro}
%
% \begin{macro}{\tl_trim_spaces:n, \tl_trim_spaces:o}
% \begin{macro}{\tl_trim_spaces:nN, \tl_trim_spaces:oN}
% \begin{macro}
% {
% \tl_trim_spaces:N, \tl_trim_spaces:c,
Expand All @@ -2394,6 +2389,9 @@
\cs_new:Npn \tl_trim_spaces:n #1
{ \@@_trim_spaces:nn { \q_mark #1 } \exp_not:o }
\cs_generate_variant:Nn \tl_trim_spaces:n { o }
\cs_new:Npn \tl_trim_spaces:nN #1#2
{ \@@_trim_spaces:nn { \q_mark #1 } { \exp_args:No #2 } }
\cs_generate_variant:Nn \tl_trim_spaces:nN { o }
\cs_new_protected:Npn \tl_trim_spaces:N #1
{ \tl_set:Nx #1 { \exp_args:No \tl_trim_spaces:n {#1} } }
\cs_new_protected:Npn \tl_gtrim_spaces:N #1
Expand Down Expand Up @@ -2466,6 +2464,7 @@
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {\tl_sort:Nn, \tl_sort:cn, \tl_gsort:Nn, \tl_gsort:cn, \tl_sort:nN}
Expand Down
5 changes: 5 additions & 0 deletions l3kernel/testfiles/m3expl001.luatex.tlg
Expand Up @@ -530,6 +530,8 @@ Defining \__tl_reverse_items:nwNwn on line ...
Defining \__tl_reverse_items:wn on line ...
Defining \tl_trim_spaces:n on line ...
Defining \tl_trim_spaces:o on line ...
Defining \tl_trim_spaces:nN on line ...
Defining \tl_trim_spaces:oN on line ...
Defining \tl_trim_spaces:N on line ...
Defining \tl_gtrim_spaces:N on line ...
Defining \tl_trim_spaces:c on line ...
Expand Down Expand Up @@ -2337,6 +2339,7 @@ Defining \clist_item:nn on line ...
Defining \__clist_item_n:nw on line ...
Defining \__clist_item_n_loop:nw on line ...
Defining \__clist_item_n_end:n on line ...
Defining \__clist_item_n_strip:n on line ...
Defining \__clist_item_n_strip:w on line ...
Defining \clist_show:N on line ...
Defining \clist_show:c on line ...
Expand Down Expand Up @@ -2653,7 +2656,9 @@ Defining \prop_const_from_keyval:cn on line ...
Defining \__prop_from_keyval:n on line ...
Defining \__prop_from_keyval_loop:w on line ...
Defining \__prop_from_keyval_split:Nw on line ...
Defining \__prop_from_keyval_key:n on line ...
Defining \__prop_from_keyval_key:w on line ...
Defining \__prop_from_keyval_value:n on line ...
Defining \__prop_from_keyval_value:w on line ...
Defining \__prop_split:NnTF on line ...
Defining \__prop_split_aux:NnTF on line ...
Expand Down
5 changes: 5 additions & 0 deletions l3kernel/testfiles/m3expl001.ptex.tlg
Expand Up @@ -529,6 +529,8 @@ Defining \__tl_reverse_items:nwNwn on line ...
Defining \__tl_reverse_items:wn on line ...
Defining \tl_trim_spaces:n on line ...
Defining \tl_trim_spaces:o on line ...
Defining \tl_trim_spaces:nN on line ...
Defining \tl_trim_spaces:oN on line ...
Defining \tl_trim_spaces:N on line ...
Defining \tl_gtrim_spaces:N on line ...
Defining \tl_trim_spaces:c on line ...
Expand Down Expand Up @@ -2018,6 +2020,7 @@ Defining \clist_item:nn on line ...
Defining \__clist_item_n:nw on line ...
Defining \__clist_item_n_loop:nw on line ...
Defining \__clist_item_n_end:n on line ...
Defining \__clist_item_n_strip:n on line ...
Defining \__clist_item_n_strip:w on line ...
Defining \clist_show:N on line ...
Defining \clist_show:c on line ...
Expand Down Expand Up @@ -2590,7 +2593,9 @@ Defining \prop_const_from_keyval:cn on line ...
Defining \__prop_from_keyval:n on line ...
Defining \__prop_from_keyval_loop:w on line ...
Defining \__prop_from_keyval_split:Nw on line ...
Defining \__prop_from_keyval_key:n on line ...
Defining \__prop_from_keyval_key:w on line ...
Defining \__prop_from_keyval_value:n on line ...
Defining \__prop_from_keyval_value:w on line ...
Defining \__prop_split:NnTF on line ...
Defining \__prop_split_aux:NnTF on line ...
Expand Down
5 changes: 5 additions & 0 deletions l3kernel/testfiles/m3expl001.tlg
Expand Up @@ -529,6 +529,8 @@ Defining \__tl_reverse_items:nwNwn on line ...
Defining \__tl_reverse_items:wn on line ...
Defining \tl_trim_spaces:n on line ...
Defining \tl_trim_spaces:o on line ...
Defining \tl_trim_spaces:nN on line ...
Defining \tl_trim_spaces:oN on line ...
Defining \tl_trim_spaces:N on line ...
Defining \tl_gtrim_spaces:N on line ...
Defining \tl_trim_spaces:c on line ...
Expand Down Expand Up @@ -2018,6 +2020,7 @@ Defining \clist_item:nn on line ...
Defining \__clist_item_n:nw on line ...
Defining \__clist_item_n_loop:nw on line ...
Defining \__clist_item_n_end:n on line ...
Defining \__clist_item_n_strip:n on line ...
Defining \__clist_item_n_strip:w on line ...
Defining \clist_show:N on line ...
Defining \clist_show:c on line ...
Expand Down Expand Up @@ -2590,7 +2593,9 @@ Defining \prop_const_from_keyval:cn on line ...
Defining \__prop_from_keyval:n on line ...
Defining \__prop_from_keyval_loop:w on line ...
Defining \__prop_from_keyval_split:Nw on line ...
Defining \__prop_from_keyval_key:n on line ...
Defining \__prop_from_keyval_key:w on line ...
Defining \__prop_from_keyval_value:n on line ...
Defining \__prop_from_keyval_value:w on line ...
Defining \__prop_split:NnTF on line ...
Defining \__prop_split_aux:NnTF on line ...
Expand Down
5 changes: 5 additions & 0 deletions l3kernel/testfiles/m3expl001.uptex.tlg
Expand Up @@ -529,6 +529,8 @@ Defining \__tl_reverse_items:nwNwn on line ...
Defining \__tl_reverse_items:wn on line ...
Defining \tl_trim_spaces:n on line ...
Defining \tl_trim_spaces:o on line ...
Defining \tl_trim_spaces:nN on line ...
Defining \tl_trim_spaces:oN on line ...
Defining \tl_trim_spaces:N on line ...
Defining \tl_gtrim_spaces:N on line ...
Defining \tl_trim_spaces:c on line ...
Expand Down Expand Up @@ -2018,6 +2020,7 @@ Defining \clist_item:nn on line ...
Defining \__clist_item_n:nw on line ...
Defining \__clist_item_n_loop:nw on line ...
Defining \__clist_item_n_end:n on line ...
Defining \__clist_item_n_strip:n on line ...
Defining \__clist_item_n_strip:w on line ...
Defining \clist_show:N on line ...
Defining \clist_show:c on line ...
Expand Down Expand Up @@ -2590,7 +2593,9 @@ Defining \prop_const_from_keyval:cn on line ...
Defining \__prop_from_keyval:n on line ...
Defining \__prop_from_keyval_loop:w on line ...
Defining \__prop_from_keyval_split:Nw on line ...
Defining \__prop_from_keyval_key:n on line ...
Defining \__prop_from_keyval_key:w on line ...
Defining \__prop_from_keyval_value:n on line ...
Defining \__prop_from_keyval_value:w on line ...
Defining \__prop_split:NnTF on line ...
Defining \__prop_split_aux:NnTF on line ...
Expand Down
5 changes: 5 additions & 0 deletions l3kernel/testfiles/m3expl001.xetex.tlg
Expand Up @@ -529,6 +529,8 @@ Defining \__tl_reverse_items:nwNwn on line ...
Defining \__tl_reverse_items:wn on line ...
Defining \tl_trim_spaces:n on line ...
Defining \tl_trim_spaces:o on line ...
Defining \tl_trim_spaces:nN on line ...
Defining \tl_trim_spaces:oN on line ...
Defining \tl_trim_spaces:N on line ...
Defining \tl_gtrim_spaces:N on line ...
Defining \tl_trim_spaces:c on line ...
Expand Down Expand Up @@ -2335,6 +2337,7 @@ Defining \clist_item:nn on line ...
Defining \__clist_item_n:nw on line ...
Defining \__clist_item_n_loop:nw on line ...
Defining \__clist_item_n_end:n on line ...
Defining \__clist_item_n_strip:n on line ...
Defining \__clist_item_n_strip:w on line ...
Defining \clist_show:N on line ...
Defining \clist_show:c on line ...
Expand Down Expand Up @@ -2651,7 +2654,9 @@ Defining \prop_const_from_keyval:cn on line ...
Defining \__prop_from_keyval:n on line ...
Defining \__prop_from_keyval_loop:w on line ...
Defining \__prop_from_keyval_split:Nw on line ...
Defining \__prop_from_keyval_key:n on line ...
Defining \__prop_from_keyval_key:w on line ...
Defining \__prop_from_keyval_value:n on line ...
Defining \__prop_from_keyval_value:w on line ...
Defining \__prop_split:NnTF on line ...
Defining \__prop_split_aux:NnTF on line ...
Expand Down
5 changes: 5 additions & 0 deletions l3kernel/testfiles/m3expl003.luatex.tlg
Expand Up @@ -530,6 +530,8 @@ Defining \__tl_reverse_items:nwNwn on line ...
Defining \__tl_reverse_items:wn on line ...
Defining \tl_trim_spaces:n on line ...
Defining \tl_trim_spaces:o on line ...
Defining \tl_trim_spaces:nN on line ...
Defining \tl_trim_spaces:oN on line ...
Defining \tl_trim_spaces:N on line ...
Defining \tl_gtrim_spaces:N on line ...
Defining \tl_trim_spaces:c on line ...
Expand Down Expand Up @@ -2337,6 +2339,7 @@ Defining \clist_item:nn on line ...
Defining \__clist_item_n:nw on line ...
Defining \__clist_item_n_loop:nw on line ...
Defining \__clist_item_n_end:n on line ...
Defining \__clist_item_n_strip:n on line ...
Defining \__clist_item_n_strip:w on line ...
Defining \clist_show:N on line ...
Defining \clist_show:c on line ...
Expand Down Expand Up @@ -2653,7 +2656,9 @@ Defining \prop_const_from_keyval:cn on line ...
Defining \__prop_from_keyval:n on line ...
Defining \__prop_from_keyval_loop:w on line ...
Defining \__prop_from_keyval_split:Nw on line ...
Defining \__prop_from_keyval_key:n on line ...
Defining \__prop_from_keyval_key:w on line ...
Defining \__prop_from_keyval_value:n on line ...
Defining \__prop_from_keyval_value:w on line ...
Defining \__prop_split:NnTF on line ...
Defining \__prop_split_aux:NnTF on line ...
Expand Down
5 changes: 5 additions & 0 deletions l3kernel/testfiles/m3expl003.ptex.tlg
Expand Up @@ -529,6 +529,8 @@ Defining \__tl_reverse_items:nwNwn on line ...
Defining \__tl_reverse_items:wn on line ...
Defining \tl_trim_spaces:n on line ...
Defining \tl_trim_spaces:o on line ...
Defining \tl_trim_spaces:nN on line ...
Defining \tl_trim_spaces:oN on line ...
Defining \tl_trim_spaces:N on line ...
Defining \tl_gtrim_spaces:N on line ...
Defining \tl_trim_spaces:c on line ...
Expand Down Expand Up @@ -2018,6 +2020,7 @@ Defining \clist_item:nn on line ...
Defining \__clist_item_n:nw on line ...
Defining \__clist_item_n_loop:nw on line ...
Defining \__clist_item_n_end:n on line ...
Defining \__clist_item_n_strip:n on line ...
Defining \__clist_item_n_strip:w on line ...
Defining \clist_show:N on line ...
Defining \clist_show:c on line ...
Expand Down Expand Up @@ -2590,7 +2593,9 @@ Defining \prop_const_from_keyval:cn on line ...
Defining \__prop_from_keyval:n on line ...
Defining \__prop_from_keyval_loop:w on line ...
Defining \__prop_from_keyval_split:Nw on line ...
Defining \__prop_from_keyval_key:n on line ...
Defining \__prop_from_keyval_key:w on line ...
Defining \__prop_from_keyval_value:n on line ...
Defining \__prop_from_keyval_value:w on line ...
Defining \__prop_split:NnTF on line ...
Defining \__prop_split_aux:NnTF on line ...
Expand Down

0 comments on commit ffb5def

Please sign in to comment.