[latex3-commits] [git/LaTeX3-latex3-latex3] master: faster tl_if_empty:n (20b2c18d1)

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/20b2c18d1ffcd75b9bd037684a3b395928812621

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

commit 20b2c18d1ffcd75b9bd037684a3b395928812621
Author: Jonathan Spratte <jspratte at yahoo.de>
Date:   Sat Aug 8 00:01:51 2020 +0200

    faster tl_if_empty:n


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

20b2c18d1ffcd75b9bd037684a3b395928812621
 l3kernel/l3tl.dtx | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index 2ef110b38..a44d692e3 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -2069,22 +2069,21 @@
 %
 % \begin{macro}[pTF]{\tl_if_empty:n, \tl_if_empty:V}
 %   Convert the argument to a string: this is empty if and only if
-%   the argument is.  Then |\if_meaning:w \q_@@_nil ... \q_@@_nil| is
+%   the argument is.  Then |\if:w \scan_stop: ... \scan_stop:| is
 %   \texttt{true} if and only if the string |...| is empty.
-%   It could be tempting to use |\if_meaning:w \q_@@_nil #1 \q_@@_nil| directly.
+%   It could be tempting to use |\if:w \scan_stop: #1 \scan_stop:| directly.
 %   This fails on a token
-%   list starting with \cs{q_@@_nil} of course but more troubling is the
+%   list starting with \cs{scan_stop:} of course but more troubling is the
 %   case where argument is a complete conditional such as \cs{if_true:}
 %   a \cs{else:} b \cs{fi:} because then \cs{if_true:} is used by
-%   \cs{if_meaning:w}, the test turns out \texttt{false}, the \cs{else:}
+%   \cs{if:w}, the test turns out \texttt{false}, the \cs{else:}
 %   executes the \texttt{false} branch, the \cs{fi:} ends it and the
-%   \cs{q_@@_nil} at the end
-%   starts executing\dots{}
+%   \cs{scan_stop:} at the end stays in the input stream as well as the now
+%   unbalanced |\else:| and |\fi:|.
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \tl_if_empty:n #1 { p , TF , T , F }
   {
-    \exp_after:wN \if_meaning:w \exp_after:wN \q_@@_nil
-        \tl_to_str:n {#1} \q_@@_nil
+    \if:w \scan_stop: \tl_to_str:n {#1} \scan_stop:
       \prg_return_true:
     \else:
       \prg_return_false:
@@ -2107,13 +2106,15 @@
 %   We don't put \cs{prg_return_true:} and so on in the definition of
 %   the auxiliary, because that would prevent an optimization applied to
 %   conditionals that end with this code.
+%   Also the |\@@_if_empty_if:o| is expanded once in |\tl_if_empty:oTF| for
+%   efficiency as well (and to reduce code doubling).
 %    \begin{macrocode}
 \cs_new:Npn \@@_if_empty_if:o #1
   {
-    \exp_after:wN \if_meaning:w \exp_after:wN \q_@@_nil
-      \__kernel_tl_to_str:w \exp_after:wN {#1} \q_@@_nil
+    \if:w \scan_stop: \__kernel_tl_to_str:w \exp_after:wN {#1} \scan_stop:
   }
-\prg_new_conditional:Npnn \tl_if_empty:o #1 { p , TF , T , F }
+\exp_args:Nno \use:n
+  { \prg_new_conditional:Npnn \tl_if_empty:o #1 { p , TF , T , F } }
   {
     \@@_if_empty_if:o {#1}
       \prg_return_true:





More information about the latex3-commits mailing list.