Skip to content

Commit

Permalink
Avoid using \__str_if_eq_x:nn outside l3str
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
josephwright committed Mar 29, 2018
1 parent 632c579 commit 0f59491
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 64 deletions.
27 changes: 27 additions & 0 deletions l3kernel/l3fp-aux.dtx
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion l3kernel/l3fp-expo.dtx
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions l3kernel/l3fp-parse.dtx
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions l3kernel/l3skip.dtx
Expand Up @@ -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}
Expand Down
69 changes: 28 additions & 41 deletions l3kernel/l3str.dtx
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand All @@ -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 }
Expand All @@ -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} }
Expand All @@ -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
{
Expand All @@ -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 }
}
Expand Down
8 changes: 3 additions & 5 deletions l3kernel/l3token.dtx
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl001.luatex.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl001.ptex.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl001.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl001.uptex.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl001.xetex.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl003.luatex.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl003.ptex.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl003.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl003.uptex.tlg
Expand Up @@ -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 ...
Expand Down
1 change: 1 addition & 0 deletions l3kernel/testfiles/m3expl003.xetex.tlg
Expand Up @@ -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 ...
Expand Down
20 changes: 18 additions & 2 deletions l3trial/l3bigint/l3bigint.dtx
Expand Up @@ -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}
%
Expand Down
8 changes: 3 additions & 5 deletions l3trial/l3kernel-extras/l3kernel-extras.dtx
Expand Up @@ -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
Expand Down

0 comments on commit 0f59491

Please sign in to comment.