[latex3-commits] [git/LaTeX3-latex3-latex3] master: Add and use \flag_raise_if_clear:n (801eafa)

Bruno Le Floch bruno at le-floch.fr
Mon Apr 2 06:01:09 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/801eafab949e3a587f03a03e0963cae6c21869f8

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

commit 801eafab949e3a587f03a03e0963cae6c21869f8
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Mon Apr 2 00:01:09 2018 -0400

    Add and use \flag_raise_if_clear:n
    
    Raising a flag takes a time proportional to its height, while this
    function takes a constant time.  When the actual height is not useful
    it's much faster to only raise the flag once.


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

801eafab949e3a587f03a03e0963cae6c21869f8
 contrib/commit.org                      |    1 +
 l3kernel/l3candidates.dtx               |   33 +++++++++++++++++++++++++++++++
 l3kernel/l3fp-traps.dtx                 |   12 +++++------
 l3kernel/l3regex.dtx                    |    4 ++--
 l3kernel/testfiles/m3expl001.luatex.tlg |    1 +
 l3kernel/testfiles/m3expl001.ptex.tlg   |    1 +
 l3kernel/testfiles/m3expl001.tlg        |    1 +
 l3kernel/testfiles/m3expl001.uptex.tlg  |    1 +
 l3kernel/testfiles/m3expl001.xetex.tlg  |    1 +
 l3kernel/testfiles/m3expl003.luatex.tlg |    1 +
 l3kernel/testfiles/m3expl003.ptex.tlg   |    1 +
 l3kernel/testfiles/m3expl003.tlg        |    1 +
 l3kernel/testfiles/m3expl003.uptex.tlg  |    1 +
 l3kernel/testfiles/m3expl003.xetex.tlg  |    1 +
 l3kernel/testfiles/m3flag001.lvt        |    6 +++++-
 l3kernel/testfiles/m3flag001.tlg        |   10 ++++++++++
 l3trial/l3fp-extras/l3fp-symbolic.dtx   |    2 +-
 17 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/contrib/commit.org b/contrib/commit.org
new file mode 100644
index 0000000..9b3b5cd
--- /dev/null
+++ b/contrib/commit.org
@@ -0,0 +1 @@
+Load all third-party modules with deprecation errors on (related to #420)
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index dbfb360..85d369e 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -335,6 +335,16 @@
 %   \end{texnote}
 % \end{function}
 %
+% \section{Additions to \pkg{l3flag}}
+%
+% \begin{function}[EXP]{\flag_raise_if_clear:n}
+%   \begin{syntax}
+%     \cs{flag_raise_if_clear:n} \Arg{flag name}
+%   \end{syntax}
+%   Ensures the \meta{flag} is raised by making its height at least~$1$,
+%   locally.
+% \end{function}
+%
 % \section{Additions to \pkg{l3int}}
 %
 % \begin{function}[EXP, added = 2016-12-06]{\int_rand:nn}
@@ -1927,6 +1937,29 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \subsection{Additions to \pkg{l3flag}}
+%
+%    \begin{macrocode}
+%<@@=flag>
+%    \end{macrocode}
+%
+% \begin{macro}[EXP]{\flag_raise_if_clear:n}
+%   It might be faster to just call the \enquote{trap} function in all
+%   cases but conceptually the function name suggests we should only run
+%   it if the flag is zero in case the \enquote{trap} made customizable
+%   in the future.
+%    \begin{macrocode}
+\__kernel_patch:nnNNpn { \@@_chk_exist:n {#1} } { }
+\cs_new:Npn \flag_raise_if_clear:n #1
+  {
+    \if_cs_exist:w flag~#1~0 \cs_end:
+    \else:
+      \cs:w flag~#1 \cs_end: 0 ;
+    \fi:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{Additions to \pkg{l3int}}
 %
 %    \begin{macrocode}
diff --git a/l3kernel/l3fp-traps.dtx b/l3kernel/l3fp-traps.dtx
index 8548fa1..b772ffe 100644
--- a/l3kernel/l3fp-traps.dtx
+++ b/l3kernel/l3fp-traps.dtx
@@ -163,7 +163,7 @@
       {
         #1
         \@@_error:nnfn { fp-invalid } {##2} { \fp_to_tl:n { ##3; } } { }
-        \flag_raise:n { fp_invalid_operation }
+        \flag_raise_if_clear:n { fp_invalid_operation }
         ##1
       }
     \exp_args:Nno \use:n
@@ -172,7 +172,7 @@
         #1
         \@@_error:nffn { fp-invalid-ii }
           { \fp_to_tl:n { ##2; } } { \fp_to_tl:n { ##3; } } {##1}
-        \flag_raise:n { fp_invalid_operation }
+        \flag_raise_if_clear:n { fp_invalid_operation }
         \exp_after:wN \c_nan_fp
       }
     \exp_args:Nno \use:n
@@ -180,7 +180,7 @@
       {
         #1
         \@@_error:nffn { fp-invalid } {##1} {##2} { }
-        \flag_raise:n { fp_invalid_operation }
+        \flag_raise_if_clear:n { fp_invalid_operation }
         \exp_after:wN \c_nan_fp
       }
   }
@@ -213,7 +213,7 @@
       {
         #1
         \@@_error:nnfn { fp-zero-div } {##2} { \fp_to_tl:n { ##3; } } { }
-        \flag_raise:n { fp_division_by_zero }
+        \flag_raise_if_clear:n { fp_division_by_zero }
         \exp_after:wN ##1
       }
     \exp_args:Nno \use:n
@@ -222,7 +222,7 @@
         #1
         \@@_error:nffn { fp-zero-div-ii }
           { \fp_to_tl:n { ##3; } } { \fp_to_tl:n { ##4; } } {##2}
-        \flag_raise:n { fp_division_by_zero }
+        \flag_raise_if_clear:n { fp_division_by_zero }
         \exp_after:wN ##1
       }
   }
@@ -285,7 +285,7 @@
           { \fp_to_tl:n { \s_@@ \@@_chk:w ##1##2##3; } }
           { \token_if_eq_meaning:NNF 0 ##2 { - } #4 }
           {#2}
-        \flag_raise:n { fp_#2 }
+        \flag_raise_if_clear:n { fp_#2 }
         #3 ##2
       }
   }
diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 0f9beff..9cc4f1e 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -3218,7 +3218,7 @@
         \@@_compile_cs_aux:Nn
       }
       {
-        \quark_if_nil:NF #1 { \flag_raise:n { @@_cs } }
+        \quark_if_nil:NF #1 { \flag_raise_if_clear:n { @@_cs } }
         \use_none_delimit_by_q_recursion_stop:w
       }
   }
@@ -3240,7 +3240,7 @@
       {
         \quark_if_nil:NF #1
           {
-            \flag_raise:n { @@_cs }
+            \flag_raise_if_clear:n { @@_cs }
             \use_i_delimit_by_q_recursion_stop:nw
           }
         \use_none_delimit_by_q_recursion_stop:w
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 37b3488..51e0d2a 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -5732,6 +5732,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index c6bbe6c..222788f 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5671,6 +5671,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index b3c9392..88ee4ed 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -5671,6 +5671,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index eb3b632..755856a 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -5669,6 +5669,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index e7c0e63..2ac06d1 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5709,6 +5709,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \msg_expandable_error:nnnnnn on line ...
 Defining \msg_expandable_error:nnnnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 37b3488..51e0d2a 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -5732,6 +5732,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index c6bbe6c..222788f 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5671,6 +5671,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index b3c9392..88ee4ed 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -5671,6 +5671,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index eb3b632..755856a 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -5669,6 +5669,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \__int_rand:ww on line ...
 Defining \__int_rand_narrow:nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index e7c0e63..2ac06d1 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5709,6 +5709,7 @@ Defining message LaTeX/kernel/xetex-primitive-not-available on line ...
 Defining \file_if_exist_input:n on line ...
 Defining \file_if_exist_input:nF on line ...
 Defining \file_input_stop: on line ...
+Defining \flag_raise_if_clear:n on line ...
 Defining \int_rand:nn on line ...
 Defining \msg_expandable_error:nnnnnn on line ...
 Defining \msg_expandable_error:nnnnn on line ...
diff --git a/l3kernel/testfiles/m3flag001.lvt b/l3kernel/testfiles/m3flag001.lvt
index 8a5174a..ca6a8b3 100644
--- a/l3kernel/testfiles/m3flag001.lvt
+++ b/l3kernel/testfiles/m3flag001.lvt
@@ -1,5 +1,5 @@
 %
-% Copyright (C) 2011,2017 LaTeX3 Project
+% Copyright (C) 2011,2017,2018 LaTeX3 Project
 %
 
 \documentclass{minimal}
@@ -66,7 +66,10 @@
 \TEST { show,~log }
   {
     \flag_raise:n {C}
+    \flag_raise_if_clear:n {C}
     \flag_show:n {C}
+    \flag_clear:n {C}
+    \flag_raise_if_clear:n {C}
     \flag_raise:n {C}
     \flag_raise:n {C}
     \flag_log:n {C}
@@ -79,6 +82,7 @@
     \flag_clear:n { other }
     \flag_raise:n { other }
     \TYPE { | \flag_raise:n { other } | }
+    \TYPE { | \flag_raise_if_clear:n { other } | }
     \TYPE { | \flag_height:n { other } | }
     \TYPE { | \flag_if_raised:nTF { other } {T} {F} | }
     \TYPE { | \flag_if_raised:nT { other } {T} | }
diff --git a/l3kernel/testfiles/m3flag001.tlg b/l3kernel/testfiles/m3flag001.tlg
index dfd21fa..80e86af 100644
--- a/l3kernel/testfiles/m3flag001.tlg
+++ b/l3kernel/testfiles/m3flag001.tlg
@@ -124,6 +124,16 @@ of your error message was never \def'ed. If you have
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
+|\flag other 0;|
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Erroneous variable flag other used!
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
 |0|
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
diff --git a/l3trial/l3fp-extras/l3fp-symbolic.dtx b/l3trial/l3fp-extras/l3fp-symbolic.dtx
index 79f0424..71bcde0 100644
--- a/l3trial/l3fp-extras/l3fp-symbolic.dtx
+++ b/l3trial/l3fp-extras/l3fp-symbolic.dtx
@@ -653,7 +653,7 @@
     \@@_variable_set_parsing:Nn \cs_set_eq:NN {#1}
     \fp_set:Nn \l_@@_symbolic_fp {#2}
     \cs_set_nopar:cpn { l_@@_variable_#1_fp }
-      { \flag_raise:n { @@_symbolic } \c_nan_fp }
+      { \flag_raise_if_clear:n { @@_symbolic } \c_nan_fp }
     \flag_clear:n { @@_symbolic }
     \fp_set:cn { l_@@_variable_#1_fp } { \l_@@_symbolic_fp }
     \flag_if_raised:nT { @@_symbolic }





More information about the latex3-commits mailing list