[latex3-commits] [git/LaTeX3-latex3-latex3] master: faster keys_trim_spaces (d4fac2c5d)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Aug 5 08:40:39 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/d4fac2c5d2af05a21505f21ba335a61ad51ad9c2
>---------------------------------------------------------------
commit d4fac2c5d2af05a21505f21ba335a61ad51ad9c2
Author: Jonathan Spratte <jspratte at yahoo.de>
Date: Sun Aug 2 21:09:46 2020 +0200
faster keys_trim_spaces
>---------------------------------------------------------------
d4fac2c5d2af05a21505f21ba335a61ad51ad9c2
l3kernel/l3keys.dtx | 52 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 18 deletions(-)
diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index 321d5e797..d13fc6cb0 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -1493,9 +1493,11 @@
%
% \subsubsection{Internal auxiliaries}
%
-% \begin{variable}{\s_@@_stop}
+% \begin{variable}{\s_@@_nil,\s_@@_mark,\s_@@_stop}
% Internal scan marks.
% \begin{macrocode}
+\scan_new:N \s_@@_nil
+\scan_new:N \s_@@_mark
\scan_new:N \s_@@_stop
% \end{macrocode}
% \end{variable}
@@ -2974,29 +2976,43 @@
% \@@_trim_spaces_auxiii:w
% }
% Space stripping has to allow for the fact that the key here might have
-% several parts, and spaces need to be stripped from each part.
+% several parts, and spaces need to be stripped from each part. Since the key
+% name is turned into a string groups can't be stripped accidentally and the
+% precautions of \cs{tl_trim_spaces:n} aren't necessary, in this case it is
+% much faster to just directly strip spaces around |/|.
% \begin{macrocode}
-\cs_new:Npn \@@_trim_spaces:n #1
- {
- \exp_after:wN \@@_trim_spaces_auxi:w \tl_to_str:n {#1}
- / \q_@@_nil \s_@@_stop
- }
-\cs_new:Npn \@@_trim_spaces_auxi:w #1 / #2 \s_@@_stop
+\group_begin:
+ \cs_set:Npn \@@_tmp:n #1
+ {
+ \cs_new:Npn \@@_trim_spaces:n ##1
+ {
+ \exp_after:wN \@@_trim_spaces_auxi:w \tl_to_str:n { / ##1 } /
+ \s_@@_nil \@@_trim_spaces_auxi:w
+ \s_@@_mark \@@_trim_spaces_auxii:w
+ #1 / #1
+ \s_@@_nil \@@_trim_spaces_auxii:w
+ \s_@@_mark \@@_trim_spaces_auxiii:w
+ }
+ }
+ \@@_tmp:n { ~ }
+\group_end:
+\cs_new:Npn \@@_trim_spaces_auxi:w #1 ~ / #2 \s_@@_nil #3
{
- \@@_quark_if_nil:nTF {#2}
- { \tl_trim_spaces:n {#1} }
- { \@@_trim_spaces_auxii:w #1 / #2 }
+ #3 #1 / #2 \s_@@_nil #3
}
-\cs_new:Npn \@@_trim_spaces_auxii:w #1 / #2 / \q_@@_nil
+\cs_new:Npn \@@_trim_spaces_auxii:w #1 / ~ #2 \s_@@_mark #3
{
- \tl_trim_spaces:n {#1}
- \@@_trim_spaces_auxiii:w #2 / \q_@@_recursion_tail / \q_@@_recursion_stop
+ #3 #1 / #2 \s_@@_mark #3
}
-\cs_set:Npn \@@_trim_spaces_auxiii:w #1 /
+\cs_new:Npn \@@_trim_spaces_auxiii:w
+ / #1 /
+ \s_@@_nil \@@_trim_spaces_auxi:w
+ \s_@@_mark \@@_trim_spaces_auxii:w
+ /
+ \s_@@_nil \@@_trim_spaces_auxii:w
+ \s_@@_mark \@@_trim_spaces_auxiii:w
{
- \@@_if_recursion_tail_stop:n {#1}
- / \tl_trim_spaces:n { #1 }
- \@@_trim_spaces_auxiii:w
+ #1
}
% \end{macrocode}
% \end{macro}
More information about the latex3-commits
mailing list.