[latex3-commits] [git/LaTeX3-latex3-latex3] master: Move away from \str_if_eq in l3regex (c6467ef)

Bruno Le Floch bruno at le-floch.fr
Sun May 6 06:56:22 CEST 2018


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

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

commit c6467efdddf4c7978d4c4888dbe6fec30b671816
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun May 6 00:55:18 2018 -0400

    Move away from \str_if_eq in l3regex
    
    String comparisons are convenient but in LuaTeX sending to Lua and back
    is much slower than tl comparison, itself slightly slower than direct
    meaning/catcode tests as done here.  Some \str_if_eq left as they are
    in code that is not run often.


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

c6467efdddf4c7978d4c4888dbe6fec30b671816
 l3kernel/l3regex.dtx                    |   71 +++++++++++++++++++------------
 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 +
 11 files changed, 53 insertions(+), 28 deletions(-)

diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index a9e2efc..038af83 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -1924,6 +1924,28 @@
 %
 % \subsubsection{Generic helpers used when compiling}
 %
+% \begin{macro}{\@@_two_if_eq:NNNNTF}
+%   Used to compare pairs of things like \cs{@@_compile_special:N} |?|
+%   together.  It's often inconvenient to get the catcodes of the
+%   character to match so we just compare the character code.
+%   Besides, the expanding behaviour of \cs{if:w} is very useful as that
+%   means we can use \cs{c_left_brace_str} and the like.
+%    \begin{macrocode}
+\prg_new_conditional:Npnn \@@_two_if_eq:NNNN #1#2#3#4 { TF }
+  {
+    \if_meaning:w #1 #3
+      \if:w #2 #4
+        \prg_return_true:
+      \else:
+        \prg_return_false:
+      \fi:
+    \else:
+      \prg_return_false:
+    \fi:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\@@_get_digits:NTFw}
 % \begin{macro}[rEXP]{\@@_get_digits_loop:w}
 %   If followed by some raw digits, collect them one by one in the
@@ -2340,7 +2362,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_compile_quantifier_lazyness:nnNN #1#2#3#4
   {
-    \str_if_eq:nnTF { #3 #4 } { \@@_compile_special:N ? }
+    \@@_two_if_eq:NNNNTF #3 #4 \@@_compile_special:N ?
       {
         \tl_build_put_right:Nn \l_@@_build_tl
           { \if_false: { \fi: } { #1 } { #2 } \c_true_bool }
@@ -2421,8 +2443,7 @@
   }
 \cs_new_protected:Npn \@@_compile_quantifier_braced_auxii:w #1#2
   {
-    \str_if_eq_x:nnTF
-      { #1 #2 } { \@@_compile_special:N \c_right_brace_str }
+    \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_special:N \c_right_brace_str
       {
         \exp_args:No \@@_compile_quantifier_lazyness:nnNN
           { \int_use:N \l_@@_internal_a_int } { -1 }
@@ -2435,8 +2456,7 @@
   }
 \cs_new_protected:Npn \@@_compile_quantifier_braced_auxiii:w #1#2
   {
-    \str_if_eq_x:nnTF
-      { #1 #2 } { \@@_compile_special:N \c_right_brace_str }
+    \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_special:N \c_right_brace_str
       {
         \if_int_compare:w \l_@@_internal_a_int >
           \l_@@_internal_b_int
@@ -2489,7 +2509,7 @@
   {
     \@@_if_in_class:TF
       {
-        \str_if_eq:nnTF {#2#3} { \@@_compile_special:N - }
+        \@@_two_if_eq:NNNNTF #2 #3 \@@_compile_special:N -
           { \@@_compile_range:Nw #1 }
           {
             \@@_compile_one:n
@@ -2785,7 +2805,7 @@
 \cs_new_protected:Npn \@@_compile_class:TFNN #1#2#3#4
   {
     \l_@@_mode_int = \int_value:w \l_@@_mode_int 3 \exp_stop_f:
-    \str_if_eq:nnTF { #3 #4 } { \@@_compile_special:N ^ }
+    \@@_two_if_eq:NNNNTF #3 #4 \@@_compile_special:N ^
       {
         \tl_build_put_right:Nn \l_@@_build_tl { #2 { \if_false: } \fi: }
         \@@_compile_class:NN
@@ -2840,7 +2860,7 @@
   }
 \cs_new_protected:Npn \@@_compile_class_posix:NNNNw #1#2#3#4#5#6
   {
-    \str_if_eq:nnTF { #5 #6 } { \@@_compile_special:N ^ }
+    \@@_two_if_eq:NNNNTF #5 #6 \@@_compile_special:N ^
       {
         \bool_set_false:N \l_@@_internal_bool
         \tl_set:Nx \l_@@_internal_a_tl { \if_false: } \fi:
@@ -2860,8 +2880,9 @@
   }
 \cs_new_protected:Npn \@@_compile_class_posix_end:w #1#2#3#4
   {
-    \str_if_eq:nnTF { #1 #2 #3 #4 }
-      { \@@_compile_special:N : \@@_compile_special:N ] }
+    \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_special:N :
+      { \@@_two_if_eq:NNNNTF #3 #4 \@@_compile_special:N ] }
+      { \use_ii:nn }
       {
         \cs_if_exist:cTF { @@_posix_ \l_@@_internal_a_tl : }
           {
@@ -2956,7 +2977,7 @@
   }
 \cs_new_protected:Npn \@@_compile_lparen:w #1#2#3#4
   {
-    \str_if_eq:nnTF { #1 #2 } { \@@_compile_special:N ? }
+    \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_special:N ?
       {
         \cs_if_exist_use:cF
           { @@_compile_special_group_\token_to_str:N #4 :w }
@@ -3022,7 +3043,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_compile_special_group_i:w #1#2
   {
-    \str_if_eq:nnTF { #1 #2 } { \@@_compile_special:N ) }
+    \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_special:N )
       {
         \cs_set:Npn \@@_item_equal:n 
           { \@@_item_caseless_equal:n }
@@ -3039,8 +3060,9 @@
   }
 \cs_new_protected:cpn { @@_compile_special_group_-:w } #1#2#3#4
   {
-    \str_if_eq:nnTF { #1 #2 #3 #4 }
-      { \@@_compile_raw:N i \@@_compile_special:N ) }
+    \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_raw:N i
+      { \@@_two_if_eq:NNNNTF #3 #4 \@@_compile_special:N ) }
+      { \use_ii:nn }
       {
         \cs_set:Npn \@@_item_equal:n
           { \@@_item_caseful_equal:n }
@@ -3134,7 +3156,7 @@
           \c_@@_catcode_in_class_mode_int
         \fi:
     \int_zero:N \l_@@_catcodes_int
-    \str_if_eq:nnTF { #1 #2 } { \@@_compile_special:N ^ }
+    \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_special:N ^
       {
         \bool_set_false:N \l_@@_catcodes_bool
         \@@_compile_c_lbrack_loop:NN
@@ -3304,8 +3326,7 @@
     \@@_if_in_class_or_catcode:TF
       { \@@_compile_raw_error:N u #1 #2 }
       {
-        \str_if_eq_x:nnTF {#1#2}
-          { \@@_compile_special:N \c_left_brace_str }
+        \@@_two_if_eq:NNNNTF #1 #2 \@@_compile_special:N \c_left_brace_str
           {
             \tl_set:Nx \l_@@_internal_a_tl { \if_false: } \fi:
             \@@_compile_u_loop:NN
@@ -5356,9 +5377,8 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_replacement_g:w #1#2
   {
-    \str_if_eq_x:nnTF
-      { #1#2 }
-      { \@@_replacement_normal:n \c_left_brace_str }
+    \@@_two_if_eq:NNNNTF
+      #1 #2 \@@_replacement_normal:n \c_left_brace_str
       { \l_@@_internal_a_int = \@@_replacement_g_digits:NN }
       { \@@_replacement_error:NNN g #1 #2 }
   }
@@ -5447,9 +5467,8 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_replacement_u:w #1#2
   {
-    \str_if_eq_x:nnTF
-      { #1#2 }
-      { \@@_replacement_normal:n \c_left_brace_str }
+    \@@_two_if_eq:NNNNTF
+      #1 #2 \@@_replacement_normal:n \c_left_brace_str
       { \@@_replacement_cu_aux:Nw \exp_not:V }
       { \@@_replacement_error:NNN u #1#2 }
   }
@@ -5495,11 +5514,7 @@
             #2 #3
           }
           {
-            \str_if_eq:nnTF
-              { #2#3 }
-              { 
-                \@@_replacement_normal:n ( % )
-              }
+            \@@_two_if_eq:NNNNTF #2 #3 \@@_replacement_normal:n (
               {
                 \seq_push:NV \l_@@_replacement_category_seq
                   \l_@@_replacement_category_tl
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index e888370..28983eb 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -4553,6 +4553,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index dbcfd89..63baa8f 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -4809,6 +4809,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index e40a2c4..9e63f3d 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -4809,6 +4809,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index b671ee9..183cc35 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -4807,6 +4807,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index cb0e879..ba2a823 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -4527,6 +4527,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index e888370..28983eb 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -4553,6 +4553,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index dbcfd89..63baa8f 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -4809,6 +4809,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index e40a2c4..9e63f3d 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -4809,6 +4809,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index b671ee9..183cc35 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -4807,6 +4807,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index cb0e879..ba2a823 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -4527,6 +4527,7 @@ Defining \l__regex_internal_regex on line ...
 Defining \l__regex_show_prefix_seq on line ...
 Defining \l__regex_show_lines_int on line ...
 \l__regex_show_lines_int=\count...
+Defining \__regex_two_if_eq:NNNNTF on line ...
 Defining \__regex_get_digits:NTFw on line ...
 Defining \__regex_get_digits_loop:nw on line ...
 Defining \__regex_if_raw_digit:NNTF on line ...





More information about the latex3-commits mailing list