[latex3-commits] [git/LaTeX3-latex3-latex3] main: Use fewer string comparisons since they are slow in LuaTeX (fixes #174) (5e25dd95c)

Bruno Le Floch blflatex at gmail.com
Wed May 12 13:10:19 CEST 2021


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/5e25dd95c137cb5a9c7c5048aec02e69a5ee787c

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

commit 5e25dd95c137cb5a9c7c5048aec02e69a5ee787c
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Tue May 11 11:19:31 2021 +0200

    Use fewer string comparisons since they are slow in LuaTeX (fixes #174)


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

5e25dd95c137cb5a9c7c5048aec02e69a5ee787c
 l3kernel/l3keys.dtx  |  4 ++++
 l3kernel/l3prop.dtx  |  6 +++---
 l3kernel/l3regex.dtx | 23 ++++++++++++++++-------
 l3kernel/l3text.dtx  |  2 +-
 l3kernel/l3tl.dtx    | 23 ++++++++++++++---------
 5 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index fba59760b..c3c8d7567 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -2776,6 +2776,10 @@
 %    of groups which apply to a key with the list of those which have been
 %    set active. That requires two mappings, and again a different outcome
 %    depending on whether opt-in or opt-out is set.
+%    We cannot replace the clist mapping by \cs{clist_if_in:NnTF} because
+%    catcodes may not be the same; they cannot be normalized easily in the
+%    clist because of the remote possibility that some items need braces
+%    if they involve commas or leading/trailing spaces.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_check_groups:
   {
diff --git a/l3kernel/l3prop.dtx b/l3kernel/l3prop.dtx
index 371f894c4..28711889d 100644
--- a/l3kernel/l3prop.dtx
+++ b/l3kernel/l3prop.dtx
@@ -808,10 +808,10 @@
   { \@@_from_keyval_value:w #1 \s_@@_mark }
 \cs_new_protected:Npn \@@_from_keyval_value:w #1 \s_@@_mark #2 \s_@@_stop #3#4
   {
-    \tl_if_empty:nF { #3 #1 #2 }
+    \tl_if_single:nTF {#2}
+      { \prop_put:Nnn \l_@@_internal_prop {#3} {#1} }
       {
-        \str_if_eq:nnTF {#2} { = }
-          { \prop_put:Nnn \l_@@_internal_prop {#3} {#1} }
+        \tl_if_empty:nF { #3 #1 #2 }
           {
             \__kernel_msg_error:nnx { prop } { prop-keyval }
               { \exp_not:o {#4} }
diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 4962ca6fa..37ba50587 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -1574,7 +1574,7 @@
       \tl_put_right:Nx \l_@@_internal_a_tl
         {
           \exp_after:wN \@@_escape_loop:N \g_@@_internal_tl
-          { break } \prg_break_point:
+          \scan_stop: \prg_break_point:
         }
       \exp_after:wN
     \group_end:
@@ -1620,7 +1620,7 @@
 %
 % \begin{macro}
 %   {
-%     \@@_escape_break:w, \@@_escape_/break:w,
+%     \@@_escape_\scan_stop::w, \@@_escape_/\scan_stop::w,
 %     \@@_escape_/a:w, \@@_escape_/e:w, \@@_escape_/f:w,
 %     \@@_escape_/n:w, \@@_escape_/r:w, \@@_escape_/t:w
 %   }
@@ -1630,8 +1630,8 @@
 %   backslash.  Spaces are ignored, and |\a|, |\e|, |\f|, |\n|, |\r|,
 %   |\t| take their meaning here.
 %    \begin{macrocode}
-\cs_new_eq:NN \@@_escape_break:w \prg_break:
-\cs_new:cpn { @@_escape_/break:w }
+\cs_new_eq:cN { @@_escape_ \iow_char:N\\scan_stop: :w } \prg_break:
+\cs_new:cpn { @@_escape_/ \iow_char:N\\scan_stop: :w }
   {
     \__kernel_msg_expandable_error:nn { regex } { trailing-backslash }
     \prg_break:
@@ -1691,7 +1691,10 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_escape_x_test:N #1
   {
-    \str_if_eq:nnTF {#1} { break } { ; }
+    \if_meaning:w \scan_stop: #1
+      \exp_after:wN \use_i:nnn \exp_after:wN ;
+    \fi:
+    \use:n
       {
         \if_charcode:w \c_space_token #1
           \exp_after:wN \@@_escape_x_test:N
@@ -1719,7 +1722,10 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_escape_x:N #1
   {
-    \str_if_eq:nnTF {#1} { break } { ; }
+    \if_meaning:w \scan_stop: #1
+      \exp_after:wN \use_i:nnn \exp_after:wN ;
+    \fi:
+    \use:n
       {
         \@@_hexadecimal_use:NTF #1
           { ; \@@_escape_loop:N }
@@ -1736,7 +1742,10 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_escape_x_loop:N #1
   {
-    \str_if_eq:nnTF {#1} { break }
+    \if_meaning:w \scan_stop: #1
+      \exp_after:wN \use_ii:nnn
+    \fi:
+    \use_ii:nn
       { ; \@@_escape_x_loop_error:n { } {#1} }
       {
         \@@_hexadecimal_use:NTF #1
diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index 58e87ba0e..d8e7f4550 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -955,7 +955,7 @@
   }
 \cs_new:Npn \@@_expand_testopt:N #1
   {
-    \str_if_eq:nnTF {#1} { \@protected at testopt }
+    \token_if_eq_meaning:NNTF #1 \@protected at testopt
       { \@@_expand_testopt:NNn }
       { \@@_expand_encoding:N #1 }
   }
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index fb2a14b6f..4967c19a6 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -2304,22 +2304,27 @@
 %
 % \begin{macro}[pTF, EXP]{\tl_if_novalue:n}
 % \begin{macro}[EXP]{\@@_if_novalue:w}
-%   Tests for |-NoValue-|: this is similar to \cs{tl_if_in:nn} but set
-%   up to be expandable and to check the value exactly.  The question
-%   mark prevents the auxiliary from losing braces.
+%   Tests whether |##1| matches |-NoValue-| exactly (with suitable
+%   catcodes): this is similar to \cs{quark_if_nil:nTF}.  The first
+%   argument of \cs{@@_if_novalue:w} is empty if and only if |##1|
+%   starts with |-NoValue-|, while the second argument is empty if |##1|
+%   is exactly |-NoValue-| or if it has a question mark just following
+%   |-NoValue-|.  In this second case, however, the material after the
+%   first |?!| remains and makes the emptyness test return
+%   \texttt{false}.
 %    \begin{macrocode}
 \cs_set_protected:Npn \@@_tmp:w #1
   {
     \prg_new_conditional:Npnn \tl_if_novalue:n ##1
       { p , T ,  F , TF }
       {
-        \str_if_eq:onTF
-          { \@@_if_novalue:w ? ##1 { } #1 }
-          { ? { } #1 }
-          { \prg_return_true: }
-          { \prg_return_false: }
+        \@@_if_empty_if:o { \@@_if_novalue:w {} ##1 {} ? ! #1 ? ? ! }
+          \prg_return_true:
+        \else:
+          \prg_return_false:
+        \fi:
       }
-    \cs_new:Npn \@@_if_novalue:w ##1 #1 {##1}
+    \cs_new:Npn \@@_if_novalue:w ##1 #1 ##2 ? ##3 ? ! { ##1 ##2 }
   }
 \exp_args:No \@@_tmp:w { \c_novalue_tl }
 %    \end{macrocode}





More information about the latex3-commits mailing list.