[latex3-commits] [git/LaTeX3-latex3-latex3] master: Speed up some conditionals by making them use an l3prg optimization (46735f4)

Bruno Le Floch bruno at le-floch.fr
Wed May 9 19:58:14 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/46735f4e3ca07d9668e681f305d75e4f04473df0

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

commit 46735f4e3ca07d9668e681f305d75e4f04473df0
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Wed May 9 13:58:14 2018 -0400

    Speed up some conditionals by making them use an l3prg optimization
    
    Conditionals that end with \prg_return_true: \else: \prg_return_false: \fi:
    are optimized, so I just made a few conditionals use that.


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

46735f4e3ca07d9668e681f305d75e4f04473df0
 l3kernel/l3candidates.dtx               |   10 +++++++---
 l3kernel/l3prg.dtx                      |   21 +++++++++++++++------
 l3kernel/l3quark.dtx                    |   22 +++++++++++++---------
 l3kernel/l3tl.dtx                       |   29 ++++++++++++++++++++---------
 l3kernel/testfiles/m3expl001.luatex.tlg |    4 ++--
 l3kernel/testfiles/m3expl001.ptex.tlg   |    4 ++--
 l3kernel/testfiles/m3expl001.tlg        |    4 ++--
 l3kernel/testfiles/m3expl001.uptex.tlg  |    4 ++--
 l3kernel/testfiles/m3expl001.xetex.tlg  |    4 ++--
 l3kernel/testfiles/m3expl003.luatex.tlg |    4 ++--
 l3kernel/testfiles/m3expl003.ptex.tlg   |    4 ++--
 l3kernel/testfiles/m3expl003.tlg        |    4 ++--
 l3kernel/testfiles/m3expl003.uptex.tlg  |    4 ++--
 l3kernel/testfiles/m3expl003.xetex.tlg  |    4 ++--
 14 files changed, 75 insertions(+), 47 deletions(-)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index bfaac62..4070e8b 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -2932,12 +2932,16 @@
 \prg_new_conditional:Npnn \tl_if_single_token:n #1 { p , T , F , TF }
   {
     \tl_if_head_is_N_type:nTF {#1}
-      { \@@_if_empty_return:o { \use_none:n #1 } }
+      { \@@_if_empty_if:o { \use_none:n #1 } }
       {
         \tl_if_empty:nTF {#1}
-          { \prg_return_false: }
-          { \@@_if_empty_return:o { \exp:w \exp_end_continue_f:w #1 } }
+          { \if_false: }
+          { \@@_if_empty_if:o { \exp:w \exp_end_continue_f:w #1 } }
       }
+      \prg_return_true:
+    \else:
+      \prg_return_false:
+    \fi:
   }
 %    \end{macrocode}
 % \end{macro}
diff --git a/l3kernel/l3prg.dtx b/l3kernel/l3prg.dtx
index 83924a8..4643375 100644
--- a/l3kernel/l3prg.dtx
+++ b/l3kernel/l3prg.dtx
@@ -1198,12 +1198,18 @@
 % \begin{macro}[pTF]{\bool_lazy_and:nn}
 % \UnitTested
 %   Only evaluate the second expression if the first is \texttt{true}.
+%   Note that |#2| must be removed as an argument, not just by skipping
+%   to the \cs{else:} branch of the conditional since |#2| may contain
+%   unbalanced \TeX{} conditionals.
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \bool_lazy_and:nn #1#2 { p , T , F , TF }
   {
-    \bool_if:nTF {#1}
-      { \bool_if:nTF {#2} { \prg_return_true: } { \prg_return_false: } }
-      { \prg_return_false: }
+    \if_predicate:w
+        \bool_if:nTF {#1} { \bool_if_p:n {#2} } { \c_false_bool }
+      \prg_return_true:
+    \else:
+      \prg_return_false:
+    \fi:
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1234,9 +1240,12 @@
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \bool_lazy_or:nn #1#2 { p , T , F , TF }
   {
-    \bool_if:nTF {#1}
-      { \prg_return_true: }
-      { \bool_if:nTF {#2} { \prg_return_true: } { \prg_return_false: } }
+    \if_predicate:w
+        \bool_if:nTF {#1} { \c_true_bool } { \bool_if_p:n {#2} }
+      \prg_return_true:
+    \else:
+      \prg_return_false:
+    \fi:
   }
 %    \end{macrocode}
 % \end{macro}
diff --git a/l3kernel/l3quark.dtx b/l3kernel/l3quark.dtx
index b42d4eb..964c02b 100644
--- a/l3kernel/l3quark.dtx
+++ b/l3kernel/l3quark.dtx
@@ -522,7 +522,7 @@
 % \begin{macro}[pTF]{\quark_if_no_value:n}
 % \UnitTested
 % \begin{macro}{\@@_if_nil:w, \@@_if_no_value:w}
-% \begin{macro}[EXP]{\@@_if_empty_return:o}
+% \begin{macro}[EXP]{\@@_if_empty_if:o}
 %   Let us explain |\quark_if_nil:n(TF)|.  Expanding \cs{@@_if_nil:w}
 %   once is safe thanks to the trailing \cs{q_nil} |??!|.  The result of
 %   expanding once is empty if and only if both delimited arguments |#1|
@@ -537,31 +537,35 @@
 %   final~|?!|, and the test returns \texttt{true} as wanted.  In the
 %   second case, the result is not empty since the first~|?!| in the
 %   definition of \cs{quark_if_nil:n} stop~|#3|. The auxiliary here
-%   is the same as \cs{__tl_if_empty_return:o}, with the same comments
+%   is the same as \cs{__tl_if_empty_if:o}, with the same comments
 %   applying.
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \quark_if_nil:n #1 { p, T , F , TF }
   {
-    \@@_if_empty_return:o
+    \@@_if_empty_if:o
       { \@@_if_nil:w {} #1 {} ? ! \q_nil ? ? ! }
+      \prg_return_true:
+    \else:
+      \prg_return_false:
+    \fi:
   }
 \cs_new:Npn \@@_if_nil:w #1 \q_nil #2 ? #3 ? ! { #1 #2 }
 \prg_new_conditional:Npnn \quark_if_no_value:n #1 { p, T , F , TF }
   {
-    \@@_if_empty_return:o
+    \@@_if_empty_if:o
       { \@@_if_no_value:w {} #1 {} ? ! \q_no_value ? ? ! }
+      \prg_return_true:
+    \else:
+      \prg_return_false:
+    \fi:
   }
 \cs_new:Npn \@@_if_no_value:w #1 \q_no_value #2 ? #3 ? ! { #1 #2 }
 \prg_generate_conditional_variant:Nnn \quark_if_nil:n
   { V , o } { p , TF , T , F }
-\cs_new:Npn \@@_if_empty_return:o #1
+\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
-      \prg_return_true:
-    \else:
-      \prg_return_false:
-    \fi:
   }
 %    \end{macrocode}
 % \end{macro}
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index e285386..b7a77ff 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -1896,12 +1896,18 @@
 %   \TeX{} skips spaces when reading a non-delimited arguments. Thus,
 %   a \meta{token list} is blank if and only if \cs{use_none:n}
 %   \meta{token list} |?| is empty after one expansion.  The auxiliary
-%   \cs{@@_if_empty_return:o} is a fast emptyness test, converting its
+%   \cs{@@_if_empty_if:o} is a fast emptyness test, converting its
 %   argument to a string (after one expansion) and using the test
 %   \cs{if_meaning:w} \cs{q_nil} |...| \cs{q_nil}.
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \tl_if_blank:n #1 { p , T , F , TF }
-  { \@@_if_empty_return:o { \use_none:n #1 ? } }
+  {
+    \@@_if_empty_if:o { \use_none:n #1 ? }
+      \prg_return_true:
+    \else:
+      \prg_return_false:
+    \fi:
+  }
 \prg_generate_conditional_variant:Nnn \tl_if_blank:n
   { V , o } { p , T , F , TF }
 %    \end{macrocode}
@@ -1954,26 +1960,31 @@
 % \end{macro}
 %
 % \begin{macro}[pTF,documented-as=\tl_if_empty:nTF]{\tl_if_empty:o}
-% \begin{macro}[EXP]{\@@_if_empty_return:o}
-%   The auxiliary function \cs{@@_if_empty_return:o} is for use
+% \begin{macro}[EXP]{\@@_if_empty_if:o}
+%   The auxiliary function \cs{@@_if_empty_if:o} is for use
 %   in various token list conditionals which reduce to testing
 %   if a given token list is empty after applying a simple function
 %   to it.
 %   The test for emptiness is based on \cs{tl_if_empty:nTF}, but
 %   the expansion is hard-coded for efficiency, as this auxiliary
-%   function is used in many places.
+%   function is used in several places.
+%   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.
 %    \begin{macrocode}
-\cs_new:Npn \@@_if_empty_return:o #1
+\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
+  }
+\prg_new_conditional:Npnn \tl_if_empty:o #1 { p , TF , T , F }
+  {
+    \@@_if_empty_if:o {#1}
       \prg_return_true:
     \else:
       \prg_return_false:
     \fi:
-  }
-\prg_new_conditional:Npnn \tl_if_empty:o #1 { p , TF , T , F }
-  { \@@_if_empty_return:o {#1} }
+ }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index f72b1cc..6cf375c 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -442,7 +442,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -946,7 +946,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 40d3223..f385ca0 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 47f97b7..c6c098a 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 3f35f3f..338718d 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index ddf3c55..000951d 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index f72b1cc..6cf375c 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -442,7 +442,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -946,7 +946,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 40d3223..f385ca0 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 47f97b7..c6c098a 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 3f35f3f..338718d 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index ddf3c55..000951d 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -441,7 +441,7 @@ Defining \tl_if_empty_p:V on line ...
 Defining \tl_if_empty:VTF on line ...
 Defining \tl_if_empty:VT on line ...
 Defining \tl_if_empty:VF on line ...
-Defining \__tl_if_empty_return:o on line ...
+Defining \__tl_if_empty_if:o on line ...
 Defining \tl_if_empty_p:o on line ...
 Defining \tl_if_empty:oTF on line ...
 Defining \tl_if_empty:oT on line ...
@@ -944,7 +944,7 @@ Defining \quark_if_nil:VT on line ...
 Defining \quark_if_nil:oT on line ...
 Defining \quark_if_nil:VF on line ...
 Defining \quark_if_nil:oF on line ...
-Defining \__quark_if_empty_return:o on line ...
+Defining \__quark_if_empty_if:o on line ...
 Defining \g__scan_marks_tl on line ...
 Defining \scan_new:N on line ...
 Defining \s_stop on line ...





More information about the latex3-commits mailing list