[latex3-commits] [git/LaTeX3-latex3-latex3] master: Avoid using \__str_if_eq_x:nn outside l3str (0f59491)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Mar 30 00:06:01 CEST 2018


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

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

commit 0f594910668d85dae7a822fc70022ffde402cd47
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Thu Mar 29 22:43:07 2018 +0100

    Avoid using \__str_if_eq_x:nn outside l3str
    
    The only places that really require the same functionality are the FPU
    and bigint comparison. Both of these can use private copies which are
    slightly more efficient. One might consider making the FPU version
    wrap-up the "= 0" part other than for the bigint stuff.


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

0f594910668d85dae7a822fc70022ffde402cd47
 l3kernel/l3fp-aux.dtx                       |   27 +++++++++++
 l3kernel/l3fp-expo.dtx                      |    2 +-
 l3kernel/l3fp-parse.dtx                     |    6 +--
 l3kernel/l3skip.dtx                         |   10 ++--
 l3kernel/l3str.dtx                          |   69 +++++++++++----------------
 l3kernel/l3token.dtx                        |    8 ++--
 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 +
 l3trial/l3bigint/l3bigint.dtx               |   20 +++++++-
 l3trial/l3kernel-extras/l3kernel-extras.dtx |    8 ++--
 18 files changed, 96 insertions(+), 64 deletions(-)

diff --git a/l3kernel/l3fp-aux.dtx b/l3kernel/l3fp-aux.dtx
index f7e763e..462b22f 100644
--- a/l3kernel/l3fp-aux.dtx
+++ b/l3kernel/l3fp-aux.dtx
@@ -1239,6 +1239,33 @@
 % \end{macro}
 % \end{macro}
 %
+% \subsection{Fast string comparison}
+%
+% \begin{macro}{\@@_str_if_eq_x:nn}
+%   A private version of the low-level string comparison function. As
+%   the nature of the is restricted and as speed is of the essence,
+%   this version does not seek to deal with |#| tokens (\emph{cf.}
+%   No \pkg{l3sys} or \pkg{l3luaex} just yet so we have to define in terms of
+%   primitives.
+%    \begin{macrocode}
+\cs_new:Npn \@@_str_if_eq_x:nn #1#2 { \pdftex_strcmp:D {#1} {#2} }
+\cs_if_exist:NT \luatex_luatexversion:D
+  {
+    \cs_set:Npn \@@_str_if_eq_x:nn #1#2
+      {
+        \luatex_directlua:D
+          {
+            l3kernel.strcmp
+              (
+                " \luatex_luaescapestring:D {#1}",
+                " \luatex_luaescapestring:D {#2}"
+              )
+          }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{Name of a function from its \pkg{l3fp-parse} name}
 %
 % \begin{macro}[EXP]{\@@_func_to_name:N, \@@_func_to_name_aux:w}
diff --git a/l3kernel/l3fp-expo.dtx b/l3kernel/l3fp-expo.dtx
index d250be9..29ee2a8 100644
--- a/l3kernel/l3fp-expo.dtx
+++ b/l3kernel/l3fp-expo.dtx
@@ -989,7 +989,7 @@
 \cs_new:Npn \@@_pow_normal_o:ww
     \s_@@ \@@_chk:w 1 #1#2#3; \s_@@ \@@_chk:w #4#5
   {
-    \if_int_compare:w \__str_if_eq_x:nn { #2 #3 }
+    \if_int_compare:w \@@_str_if_eq_x:nn { #2 #3 }
               { 1 {1000} {0000} {0000} {0000} } = 0 \exp_stop_f:
       \if_int_compare:w #4 #1 = 32 \exp_stop_f:
         \exp_after:wN \@@_case_return_ii_o:ww
diff --git a/l3kernel/l3fp-parse.dtx b/l3kernel/l3fp-parse.dtx
index 50b7807..ac07716 100644
--- a/l3kernel/l3fp-parse.dtx
+++ b/l3kernel/l3fp-parse.dtx
@@ -1716,7 +1716,7 @@
     \if_catcode:w \scan_stop: \exp_not:N #1
       \if_meaning:w \scan_stop: #1
         \if_int_compare:w
-            \__str_if_eq_x:nn { \s_@@ } { \exp_not:N #1 }
+            \@@_str_if_eq_x:nn { \s_@@ } { \exp_not:N #1 }
             = 0 \exp_stop_f:
           0
           \__kernel_msg_expandable_error:nnn
@@ -1730,7 +1730,7 @@
         \fi:
       \else:
         \if_int_compare:w
-            \__str_if_eq_x:nn { \int_value:w #1 } { \tex_the:D #1 }
+            \@@_str_if_eq_x:nn { \int_value:w #1 } { \tex_the:D #1 }
             = 0 \exp_stop_f:
           \int_value:w #1
         \else:
@@ -2224,7 +2224,7 @@
   {
     \if_catcode:w \scan_stop: \exp_not:N #2
       \if_int_compare:w
-          \__str_if_eq_x:nn { \s_@@_mark } { \exp_not:N #2 }
+          \@@_str_if_eq_x:nn { \s_@@_mark } { \exp_not:N #2 }
           = 0 \exp_stop_f:
         \exp_after:wN \exp_after:wN
         \exp_after:wN \@@_parse_infix_mark:NNN
diff --git a/l3kernel/l3skip.dtx b/l3kernel/l3skip.dtx
index 8cfda68..86d2b3c 100644
--- a/l3kernel/l3skip.dtx
+++ b/l3kernel/l3skip.dtx
@@ -1957,13 +1957,9 @@
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \skip_if_eq:nn #1#2 { p , T , F , TF }
   {
-    \if_int_compare:w
-      \__str_if_eq_x:nn { \skip_eval:n { #1 } } { \skip_eval:n { #2 } }
-      = 0 \exp_stop_f:
-        \prg_return_true:
-    \else:
-        \prg_return_false:
-    \fi:
+    \str_if_eq_x:nnTF { \skip_eval:n { #1 } } { \skip_eval:n { #2 } }
+       { \prg_return_true: }
+       { \prg_return_false: }
   }
 %    \end{macrocode}
 % \end{macro}
diff --git a/l3kernel/l3str.dtx b/l3kernel/l3str.dtx
index d8115fe..e24b676 100644
--- a/l3kernel/l3str.dtx
+++ b/l3kernel/l3str.dtx
@@ -801,16 +801,6 @@
 %
 % \subsection{Internal string functions}
 %
-% \begin{function}[EXP]{\__str_if_eq_x:nn}
-%   \begin{syntax}
-%     \cs{__str_if_eq_x:nn} \Arg{tl_1} \Arg{tl_2}
-%   \end{syntax}
-%   Compares the full expansion of two \meta{token lists} on a character by
-%   character basis, and is \texttt{true} if the two lists contain the same
-%   characters in the same order. Leaves |0| in the input stream if the
-%   condition is true, and |+1| or |-1| otherwise.
-% \end{function}
-%
 % \begin{function}[EXP]{\__str_to_other:n}
 %   \begin{syntax}
 %     \cs{__str_to_other:n} \Arg{token list}
@@ -2094,10 +2084,8 @@
           \reverse_if:N \if:w \c_hash_str #1
             \@@_parse_auxi:w #1#2 \q_stop
           \else:
-            \if_int_compare:w \__str_if_eq_x:nn
-              { \exp_not:n {#2} } { ~Conditional~Mappings~ } = 0 \exp_stop_f:
-              \cs_set_protected:Npn \@@_parse:w ##1 \q_stop { }
-            \fi:
+            \str_if_eq:nnT {#2} { ~Conditional~Mappings~ }
+              { \cs_set_protected:Npn \@@_parse:w ##1 \q_stop { } }
           \fi:
         }
 %    \end{macrocode}
@@ -2113,12 +2101,12 @@
         {
           \tl_if_blank:nF {#7}
             {
-              \if_int_compare:w \__str_if_eq_x:nn { #5 ~ } {#7} = 0 \exp_stop_f:
-              \else:
-                \tl_const:cx
-                  { c__tl_mixed_case_ \utex_char:D "#1 _tl }
-                  { \utex_char:D "#7 }
-              \fi:
+              \str_if_eq:nnF { #5 ~ } {#7}
+                {
+                  \tl_const:cx
+                    { c__tl_mixed_case_ \utex_char:D "#1 _tl }
+                    { \utex_char:D "#7 }
+                }
             }
         }
       \@@_map_inline:n { UnicodeData.txt }
@@ -2130,18 +2118,19 @@
 %    \begin{macrocode}
       \cs_set_protected:Npn \@@_parse_auxi:w #1 ;~ #2 ;~ #3 ; #4 \q_stop
         {
-          \if_int_compare:w \__str_if_eq_x:nn {#2} { C } = 0 \exp_stop_f:
-            \if_int_compare:w \tex_lccode:D "#1 = "#3 \scan_stop:
-            \else:
-              \str_const:cx
-                { c__str_fold_case_ \utex_char:D "#1 _str }
-                { \utex_char:D "#3 ~ }
-            \fi:
-          \else:
-            \if_int_compare:w \__str_if_eq_x:nn {#2} { F } = 0 \exp_stop_f:
-              \@@_parse_auxii:w #1 ~ #3 ~ \q_stop
-            \fi:
-          \fi:
+          \str_if_eq:nnTF {#2} { C }
+            {
+              \if_int_compare:w \tex_lccode:D "#1 = "#3 \scan_stop:
+              \else:
+                \str_const:cx
+                  { c__str_fold_case_ \utex_char:D "#1 _str }
+                  { \utex_char:D "#3 ~ }
+              \fi:
+            }
+            {
+              \str_if_eq:nnT {#2} { F }
+               { \@@_parse_auxii:w #1 ~ #3 ~ \q_stop }
+            }
         }
       \cs_set_protected:Npn \@@_parse_auxii:w #1 ~ #2 ~ #3 ~ #4 \q_stop
         { \@@_store:nnnnn {#1} { fold } {#2} {#3} {#4} }
@@ -2165,10 +2154,8 @@
         {
           \use:n { \@@_parse_auxii:w #1 ~ lower ~ #2 ~ } ~ \q_stop
           \use:n { \@@_parse_auxii:w #1 ~ upper ~ #4 ~ } ~ \q_stop
-          \if_int_compare:w \__str_if_eq_x:nn {#3} {#4} = 0 \exp_stop_f:
-          \else:
-            \use:n { \@@_parse_auxii:w #1 ~ mixed ~ #3 ~ } ~ \q_stop
-          \fi:
+          \str_if_eq:nnF {#3} {#4}
+            { \use:n { \@@_parse_auxii:w #1 ~ mixed ~ #3 ~ } ~ \q_stop }
         }
       \cs_set_protected:Npn \@@_parse_auxii:w #1 ~ #2 ~ #3 ~ #4 ~ #5 \q_stop
         {
@@ -2184,11 +2171,11 @@
               \tl_if_blank:nF {#5}
                 { \utex_char:D "#5 }
             }
-          \if_int_compare:w \__str_if_eq_x:nn {#2} { mixed } = 0 \exp_stop_f:
-          \else:
-            \str_const:cx { c__str_ #2 _case_ \utex_char:D "#1 _str }
-              { \tl_use:c { c__tl_ #2 _case_ \utex_char:D "#1 _tl } }
-          \fi:
+          \str_if_eq:nnF {#2} { mixed }
+            {
+              \str_const:cx { c__str_ #2 _case_ \utex_char:D "#1 _str }
+                { \tl_use:c { c__tl_ #2 _case_ \utex_char:D "#1 _tl } }
+            }
         }
       \@@_map_inline:n { SpecialCasing.txt }
     }
diff --git a/l3kernel/l3token.dtx b/l3kernel/l3token.dtx
index 518270e..40bc54e 100644
--- a/l3kernel/l3token.dtx
+++ b/l3kernel/l3token.dtx
@@ -1867,11 +1867,9 @@
       ##1 \tl_to_str:n { ma } ##2 \c_colon_str ##3 \exp_not:N \q_stop
   }
       {
-        \if_int_compare:w \__str_if_eq_x:nn { #2 } { cro } = 0 \exp_stop_f:
-            \prg_return_true:
-        \else:
-            \prg_return_false:
-        \fi:
+        \str_if_eq_x:nnTF { #2 } { cro }
+          { \prg_return_true: }
+          { \prg_return_false: }
       }
 %    \end{macrocode}
 %  \end{macro}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 2798c9f..a272544 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -3840,6 +3840,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index fbf5d37..4fce46d 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -3777,6 +3777,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 5190e48..05ced54 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -3777,6 +3777,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 2b46b93..34fb5fd 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -3777,6 +3777,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 9b35993..7485633 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -3838,6 +3838,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 2798c9f..a272544 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -3840,6 +3840,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index fbf5d37..4fce46d 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -3777,6 +3777,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 5190e48..05ced54 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -3777,6 +3777,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 2b46b93..34fb5fd 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -3777,6 +3777,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 9b35993..7485633 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -3838,6 +3838,7 @@ Defining \__fp_small_int_normal:NnwTF on line ...
 Defining \__fp_small_int_test:NnnwNw on line ...
 Defining \__fp_expand:n on line ...
 Defining \__fp_expand_loop:nwnN on line ...
+Defining \__fp_str_if_eq_x:nn on line ...
 Defining \__fp_func_to_name:N on line ...
 Defining \__fp_func_to_name_aux:w on line ...
 Defining message LaTeX/kernel/misused-fp on line ...
diff --git a/l3trial/l3bigint/l3bigint.dtx b/l3trial/l3bigint/l3bigint.dtx
index 2256119..af2eb4a 100644
--- a/l3trial/l3bigint/l3bigint.dtx
+++ b/l3trial/l3bigint/l3bigint.dtx
@@ -622,9 +622,25 @@
 % packages.
 %
 % \begin{macro}{\@@_str_cmp_x:nn}
-%   This is a wrapper around the primitive \tn{pdfstrcmp} or \tn{strcmp} or some equivalent Lua code.
+%   Af in \pkg{l3fp}, we use a private string comparison set up here. Note
+%   that in this case we do need non-zero return values: no other string
+%   comparison requires this.
 %    \begin{macrocode}
-\cs_new_eq:NN \@@_str_cmp_x:nn \__str_if_eq_x:nn
+\cs_new:Npn \@@_str_cmp_x:nn #1#2 { \pdftex_strcmp:D {#1} {#2} }
+\cs_if_exist:NT \luatex_luatexversion:D
+  {
+    \cs_set:Npn \@@_str_cmp_x:nn #1#2
+      {
+        \lua_now_x:n
+          {
+            l3kernel.strcmp
+              (
+                " \lua_escape_x:n {#1}",
+                " \lua_escape_x:n {#2}"
+              )
+          }
+      }
+  }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3trial/l3kernel-extras/l3kernel-extras.dtx b/l3trial/l3kernel-extras/l3kernel-extras.dtx
index 7a2e87d..2b3f55f 100644
--- a/l3trial/l3kernel-extras/l3kernel-extras.dtx
+++ b/l3trial/l3kernel-extras/l3kernel-extras.dtx
@@ -1266,11 +1266,9 @@
 \cs_new:Npn \__skip_compare:wwN #1; #2; #3
   {
     \if_charcode:w = #3
-       \if_int_compare:w \__str_if_eq_x:nn {#1} {#2} = 0 \exp_stop_f:
-         \prg_return_true:
-       \else:
-         \prg_return_false:
-       \fi:
+      \str_if_eq:nnTF {#1} {#2}
+         { \prg_return_true:}
+         { \prg_return_false: }
     \else:
       \if_dim:w \etex_glueexpr:D #1 #3 \etex_glueexpr:D #2 \scan_stop:
         \exp_after:wN \__skip_compare_auxii:wwN





More information about the latex3-commits mailing list