[latex3-commits] [git/LaTeX3-latex3-latex3] master: Speed up boolean expressions that consist of a single predicate (7ede6d6)

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


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/7ede6d6a21307d7598119242925abb0356c6fc39

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

commit 7ede6d6a21307d7598119242925abb0356c6fc39
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Wed May 9 13:23:38 2018 -0400

    Speed up boolean expressions that consist of a single predicate
    
    It's now 1.5x faster, at a slight cost for other boolean expressions.
    Such single-predicate boolean expressions show up a lot as arguments
    of \bool_lazy_or:nnTF or similar.


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

7ede6d6a21307d7598119242925abb0356c6fc39
 l3kernel/l3prg.dtx                      |   16 +++++++++++++---
 l3kernel/testfiles/m3expl001.luatex.tlg |    2 ++
 l3kernel/testfiles/m3expl001.ptex.tlg   |    2 ++
 l3kernel/testfiles/m3expl001.tlg        |    2 ++
 l3kernel/testfiles/m3expl001.uptex.tlg  |    2 ++
 l3kernel/testfiles/m3expl001.xetex.tlg  |    2 ++
 l3kernel/testfiles/m3expl003.luatex.tlg |    2 ++
 l3kernel/testfiles/m3expl003.ptex.tlg   |    2 ++
 l3kernel/testfiles/m3expl003.tlg        |    2 ++
 l3kernel/testfiles/m3expl003.uptex.tlg  |    2 ++
 l3kernel/testfiles/m3expl003.xetex.tlg  |    2 ++
 11 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/l3kernel/l3prg.dtx b/l3kernel/l3prg.dtx
index 5f2e06c..83924a8 100644
--- a/l3kernel/l3prg.dtx
+++ b/l3kernel/l3prg.dtx
@@ -1013,21 +1013,31 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[EXP]{\bool_if_p:n}
-%   First issue a \cs{group_align_safe_begin:} as we are using |&&| as
+% \begin{macro}[EXP]{\bool_if_p:n, \@@_if_p:n, \@@_if_p_aux:w}
+%   To speed up the case of a single predicate, \texttt{f}-expand and
+%   check whether the result is one token (possibly surrounded by
+%   spaces), which must be \cs{c_true_bool} or \cs{c_false_bool}.  We
+%   use a version of \cs{tl_if_single:nTF} optimized for speed since we
+%   know that an empty~|#1| is an error.  The auxiliary
+%   \cs{@@_if_p_aux:w} removes the trailing parenthesis and gets rid of
+%   any space.  For the general case, first issue a
+%   \cs{group_align_safe_begin:} as we are using |&&| as
 %   syntax shorthand for the And operation and we need to hide it for
 %   \TeX{}.  This group is closed after \cs{@@_get_next:NN} returns
 %   \cs{c_true_bool} or \cs{c_false_bool}.  That function requires the
 %   trailing parenthesis to know where the expression ends.
 %    \begin{macrocode}
-\cs_new:Npn \bool_if_p:n #1
+\cs_new:Npn \bool_if_p:n { \exp_args:Nf \@@_if_p:n }
+\cs_new:Npn \@@_if_p:n #1
   {
+    \tl_if_empty:oT { \use_none:nn #1 . } { \@@_if_p_aux:w }
     \group_align_safe_begin:
     \exp_after:wN
     \group_align_safe_end:
     \exp:w \exp_end_continue_f:w % (
     \@@_get_next:NN \use_i:nnnn #1 )
   }
+\cs_new:Npn \@@_if_p_aux:w #1 \use_i:nnnn #2#3 {#2}
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index c525916..f72b1cc 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -1557,6 +1557,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 1c28913..40d3223 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index fd31af4..47f97b7 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 0e21b26..3f35f3f 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 771c785..ddf3c55 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index c525916..f72b1cc 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -1557,6 +1557,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 1c28913..40d3223 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index fd31af4..47f97b7 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 0e21b26..3f35f3f 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 771c785..ddf3c55 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -1555,6 +1555,8 @@ Defining \bool_if:nT on line ...
 Defining \bool_if:nF on line ...
 Defining \bool_if:nTF on line ...
 Defining \bool_if_p:n on line ...
+Defining \__bool_if_p:n on line ...
+Defining \__bool_if_p_aux:w on line ...
 Defining \__bool_get_next:NN on line ...
 Defining \__bool_!:Nw on line ...
 Defining \__bool_(:Nw on line ...





More information about the latex3-commits mailing list