[latex3-commits] [latex3/latex3] main: l3regex performance tweaks (#1394) (aa8e74e34)

github at latex-project.org github at latex-project.org
Wed Jan 10 23:12:36 CET 2024


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

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

commit aa8e74e346745fb13685cf336585dd654828a672
Author: Skillmon <Skillmon at users.noreply.github.com>
Date:   Wed Jan 10 23:12:36 2024 +0100

    l3regex performance tweaks (#1394)
    
    * speed up some regex-functions
    
    * small integer optimisations
    
    * tune up some conditionals
    
    * use semantically correct function name in toks_clear
    
    * remove unnecessary empty line
    
    * fix __kernel_tl_set:Nx vs __kernel_tl_set:Ne


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

aa8e74e346745fb13685cf336585dd654828a672
 l3kernel/l3regex.dtx | 476 +++++++++++++++++++++++++--------------------------
 1 file changed, 238 insertions(+), 238 deletions(-)

diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 6542fc114..db1631d41 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -1132,10 +1132,10 @@
 %   Empty a \tn{toks} or set it to a value, given its number.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_toks_clear:N #1
-  { \@@_toks_set:Nn #1 { } }
+  { \tex_toks:D #1 = { } }
 \cs_new_eq:NN \@@_toks_set:Nn \tex_toks:D
 \cs_new_protected:Npn \@@_toks_set:No #1
-  { \tex_toks:D #1 \exp_after:wN }
+  { \tex_toks:D #1 = \exp_after:wN }
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1164,20 +1164,24 @@
 %   \cs{@@_toks_put_right:Ne} is provided because it is more
 %   efficient than \texttt{e}-expanding with \cs{exp_not:n}.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_toks_put_left:Ne #1#2
+\cs_if_exist:NTF \tex_etokspre:D
+  { \cs_new_eq:NN \@@_toks_put_left:Ne \tex_etokspre:D }
   {
-    \cs_set_nopar:Npe \@@_tmp:w { #2 }
-    \tex_toks:D #1 \exp_after:wN \exp_after:wN \exp_after:wN
-      { \exp_after:wN \@@_tmp:w \tex_the:D \tex_toks:D #1 }
+    \cs_new_protected:Npn \@@_toks_put_left:Ne #1#2
+      { \tex_toks:D #1 = \tex_expanded:D {{ #2 \tex_the:D \tex_toks:D #1 }} }
   }
-\cs_new_protected:Npn \@@_toks_put_right:Ne #1#2
+\cs_if_exist:NTF \tex_etoksapp:D
+  { \cs_new_eq:NN \@@_toks_put_right:Ne \tex_etoksapp:D }
   {
-    \cs_set_nopar:Npe \@@_tmp:w {#2}
-    \tex_toks:D #1 \exp_after:wN
-      { \tex_the:D \tex_toks:D \exp_after:wN #1 \@@_tmp:w }
+    \cs_new_protected:Npn \@@_toks_put_right:Ne #1#2
+      { \tex_toks:D #1 = \tex_expanded:D {{ \tex_the:D \tex_toks:D #1 #2 }} }
+  }
+\cs_if_exist:NTF \tex_toksapp:D
+  { \cs_new_eq:NN \@@_toks_put_right:Nn \tex_toksapp:D }
+  {
+    \cs_new_protected:Npn \@@_toks_put_right:Nn #1#2
+      { \tex_toks:D #1 = \exp_after:wN { \tex_the:D \tex_toks:D #1 #2 } }
   }
-\cs_new_protected:Npn \@@_toks_put_right:Nn #1#2
-  { \tex_toks:D #1 \exp_after:wN { \tex_the:D \tex_toks:D #1 #2 } }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -1200,15 +1204,13 @@
 %   Item of intarray, with a default value.
 %    \begin{macrocode}
 \cs_new:Npn \@@_intarray_item:NnF #1#2
-  { \exp_args:Nf \@@_intarray_item_aux:nNF { \int_eval:n {#2} } #1 }
+  { \exp_args:No \@@_intarray_item_aux:nNF { \tex_the:D \@@_int_eval:w #2 } #1 }
 \cs_new:Npn \@@_intarray_item_aux:nNF #1#2
   {
     \if_int_compare:w #1 > \c_zero_int
-      \exp_after:wN \use_i:nn
-    \else:
-      \exp_after:wN \use_ii:nn
+      \exp_after:wN \use_ii:nnn
     \fi:
-    { \__kernel_intarray_item:Nn #2 {#1} }
+    \use_ii:nn { \__kernel_intarray_item:Nn #2 {#1} }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1462,14 +1464,12 @@
     \if_int_compare:w \l_@@_curr_char_int > `Z \exp_stop_f:
       \if_int_compare:w \l_@@_curr_char_int > `z \exp_stop_f: \else:
         \if_int_compare:w \l_@@_curr_char_int < `a \exp_stop_f: \else:
-          \int_sub:Nn \l_@@_case_changed_char_int
-            { \c_@@_ascii_lower_int }
+          \int_sub:Nn \l_@@_case_changed_char_int \c_@@_ascii_lower_int
         \fi:
       \fi:
     \else:
       \if_int_compare:w \l_@@_curr_char_int < `A \exp_stop_f: \else:
-        \int_add:Nn \l_@@_case_changed_char_int
-          { \c_@@_ascii_lower_int }
+        \int_add:Nn \l_@@_case_changed_char_int \c_@@_ascii_lower_int
       \fi:
     \fi:
     \cs_set_eq:NN \@@_maybe_compute_ccc: \prg_do_nothing:
@@ -1507,12 +1507,12 @@
     \or: 1000000 \or: 4000000 \else: 1*0
     \fi:
   }
-\cs_new_protected:Npn \@@_item_catcode:nT #1
+\prg_new_protected_conditional:Npnn \@@_item_catcode:n #1 { T }
   {
-    \if_int_odd:w \int_eval:n { #1 / \@@_item_catcode: } \exp_stop_f:
-      \exp_after:wN \use:n
+    \if_int_odd:w \@@_int_eval:w #1 / \@@_item_catcode: \scan_stop:
+      \prg_return_true:
     \else:
-      \exp_after:wN \use_none:n
+      \prg_return_false:
     \fi:
   }
 \cs_new_protected:Npn \@@_item_catcode_reverse:nT #1#2
@@ -1536,7 +1536,7 @@
   }
 \cs_new_protected:Npn \@@_item_exact_cs:n #1
   {
-    \int_compare:nNnTF \l_@@_curr_catcode_int = 0
+    \int_compare:nNnTF \l_@@_curr_catcode_int = \c_zero_int
       {
         \__kernel_tl_set:Nx \l_@@_internal_a_tl
           { \scan_stop: \@@_curr_cs_to_str: \scan_stop: }
@@ -1557,7 +1557,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_item_cs:n #1
   {
-    \int_compare:nNnT \l_@@_curr_catcode_int = 0
+    \int_compare:nNnT \l_@@_curr_catcode_int = \c_zero_int
       {
         \group_begin:
           \@@_single_match:
@@ -1933,13 +1933,13 @@
 %   lowercase letters, which we need to detect and replace by their
 %   uppercase counterpart.
 %    \begin{macrocode}
-\prg_new_conditional:Npnn \@@_hexadecimal_use:N #1 { TF }
+\cs_new:Npn \@@_hexadecimal_use:NTF #1
   {
-    \if_int_compare:w 1 < "1 \token_to_str:N #1 \exp_stop_f:
-      #1 \prg_return_true:
+    \if_int_compare:w \c_one_int < "1 \token_to_str:N #1 \exp_stop_f:
+      #1
     \else:
       \if_case:w
-        \int_eval:n { \exp_after:wN ` \token_to_str:N #1 - `a }
+        \@@_int_eval:w \exp_after:wN ` \token_to_str:N #1 - `a \scan_stop:
            A
       \or: B
       \or: C
@@ -1947,11 +1947,10 @@
       \or: E
       \or: F
       \else:
-        \prg_return_false:
-        \exp_after:wN \use_none:n
+        \exp_after:wN \exp_after:wN \exp_after:wN \use_iii:nnn
       \fi:
-      \prg_return_true:
     \fi:
+    \use_i:nn
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1983,43 +1982,57 @@
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \@@_char_if_special:N #1 { TF }
   {
-    \if_int_compare:w `#1 > `Z \exp_stop_f:
-      \if_int_compare:w `#1 > `z \exp_stop_f:
-        \if_int_compare:w `#1 < \c_@@_ascii_max_int
-          \prg_return_true: \else: \prg_return_false: \fi:
-      \else:
-        \if_int_compare:w `#1 < `a \exp_stop_f:
-          \prg_return_true: \else: \prg_return_false: \fi:
-      \fi:
+    \if:w
+        T
+        \if_int_compare:w `#1 > `Z \exp_stop_f:
+          \if_int_compare:w `#1 > `z \exp_stop_f:
+            \if_int_compare:w `#1 < \c_@@_ascii_max_int
+              \else: F \fi:
+          \else:
+            \if_int_compare:w `#1 < `a \exp_stop_f:
+              \else: F \fi:
+          \fi:
+        \else:
+          \if_int_compare:w `#1 > `9 \exp_stop_f:
+            \if_int_compare:w `#1 < `A \exp_stop_f:
+              \else: F \fi:
+          \else:
+            \if_int_compare:w `#1 < `0 \exp_stop_f:
+              \if_int_compare:w `#1 < `\ \exp_stop_f:
+                F \fi:
+            \else: F \fi:
+          \fi:
+        \fi:
+        T
+      \prg_return_true:
     \else:
-      \if_int_compare:w `#1 > `9 \exp_stop_f:
-        \if_int_compare:w `#1 < `A \exp_stop_f:
-          \prg_return_true: \else: \prg_return_false: \fi:
-      \else:
-        \if_int_compare:w `#1 < `0 \exp_stop_f:
-          \if_int_compare:w `#1 < `\ \exp_stop_f:
-            \prg_return_false: \else: \prg_return_true: \fi:
-        \else: \prg_return_false: \fi:
-      \fi:
+      \prg_return_false:
     \fi:
   }
 \prg_new_conditional:Npnn \@@_char_if_alphanumeric:N #1 { TF }
   {
-    \if_int_compare:w `#1 > `Z \exp_stop_f:
-      \if_int_compare:w `#1 > `z \exp_stop_f:
-        \prg_return_false:
-      \else:
-        \if_int_compare:w `#1 < `a \exp_stop_f:
-          \prg_return_false: \else: \prg_return_true: \fi:
-      \fi:
+    \if:w
+        T
+        \if_int_compare:w `#1 > `Z \exp_stop_f:
+          \if_int_compare:w `#1 > `z \exp_stop_f:
+            F
+          \else:
+            \if_int_compare:w `#1 < `a \exp_stop_f:
+              F \fi:
+          \fi:
+        \else:
+          \if_int_compare:w `#1 > `9 \exp_stop_f:
+            \if_int_compare:w `#1 < `A \exp_stop_f:
+              F \fi:
+          \else:
+            \if_int_compare:w `#1 < `0 \exp_stop_f:
+              F \fi:
+          \fi:
+        \fi:
+        T
+      \prg_return_true:
     \else:
-      \if_int_compare:w `#1 > `9 \exp_stop_f:
-        \if_int_compare:w `#1 < `A \exp_stop_f:
-          \prg_return_false: \else: \prg_return_true: \fi:
-      \else:
-        \if_int_compare:w `#1 < `0 \exp_stop_f:
-          \prg_return_false: \else: \prg_return_true: \fi:
-      \fi:
+      \prg_return_false:
     \fi:
   }
 %    \end{macrocode}
@@ -2176,17 +2189,14 @@
 %   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 }
+\cs_new:Npn \@@_two_if_eq:NNNNTF #1#2#3#4
   {
     \if_meaning:w #1 #3
       \if:w #2 #4
-        \prg_return_true:
-      \else:
-        \prg_return_false:
+        \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nnn
       \fi:
-    \else:
-      \prg_return_false:
     \fi:
+    \use_ii:nn
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2217,17 +2227,14 @@
 %   Test used when grabbing digits for the |{m,n}| quantifier.
 %   It only accepts non-escaped digits.
 %    \begin{macrocode}
-\prg_new_conditional:Npnn \@@_if_raw_digit:NN #1#2 { TF }
+\cs_new:Npn \@@_if_raw_digit:NNTF #1#2
   {
     \if_meaning:w \@@_compile_raw:N #1
-      \if_int_compare:w 1 < 1 #2 \exp_stop_f:
-        \prg_return_true:
-      \else:
-        \prg_return_false:
+      \if_int_compare:w \c_one_int < 1 #2 \exp_stop_f:
+        \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nnn
       \fi:
-    \else:
-      \prg_return_false:
     \fi:
+    \use_ii:nn
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2281,12 +2288,12 @@
 %   and special characters are normal. Also, for every raw character, we
 %   must look ahead for a possible raw dash.
 %   \begin{macrocode}
-\cs_new:Npn \@@_if_in_class:TF
+\prg_new_conditional:Npnn \@@_if_in_class: { TF }
   {
     \if_int_odd:w \l_@@_mode_int
-      \exp_after:wN \use_i:nn
+      \prg_return_true:
     \else:
-      \exp_after:wN \use_ii:nn
+      \prg_return_false:
     \fi:
   }
 %    \end{macrocode}
@@ -2299,14 +2306,12 @@
 \cs_new:Npn \@@_if_in_cs:TF
   {
     \if_int_odd:w \l_@@_mode_int
-      \exp_after:wN \use_ii:nn
     \else:
       \if_int_compare:w \l_@@_mode_int < \c_@@_outer_mode_int
-        \exp_after:wN \exp_after:wN \exp_after:wN \use_i:nn
-      \else:
-        \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nn
+        \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nnn
       \fi:
     \fi:
+    \use_ii:nn
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2318,14 +2323,13 @@
 \cs_new:Npn \@@_if_in_class_or_catcode:TF
   {
     \if_int_odd:w \l_@@_mode_int
-      \exp_after:wN \use_i:nn
     \else:
       \if_int_compare:w \l_@@_mode_int > \c_@@_outer_mode_int
-        \exp_after:wN \exp_after:wN \exp_after:wN \use_i:nn
       \else:
-        \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nn
+        \exp_after:wN \exp_after:wN \exp_after:wN \use_iii:nnn
       \fi:
     \fi:
+    \use_i:nn
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2336,12 +2340,12 @@
 %   it applies (modes $23$ and $63$). This is used to tweak how left
 %   brackets behave in modes $2$ and $6$.
 %    \begin{macrocode}
-\cs_new:Npn \@@_if_within_catcode:TF
+\prg_new_conditional:Npnn \@@_if_within_catcode: { TF }
   {
     \if_int_compare:w \l_@@_mode_int > \c_@@_outer_mode_int
-      \exp_after:wN \use_i:nn
+      \prg_return_true:
     \else:
-      \exp_after:wN \use_ii:nn
+      \prg_return_false:
     \fi:
   }
 %    \end{macrocode}
@@ -2354,15 +2358,14 @@
 \cs_new_protected:Npn \@@_chk_c_allowed:T
   {
     \if_int_compare:w \l_@@_mode_int = \c_@@_outer_mode_int
-      \exp_after:wN \use:n
     \else:
       \if_int_compare:w \l_@@_mode_int = \c_@@_class_mode_int
-        \exp_after:wN \exp_after:wN \exp_after:wN \use:n
       \else:
         \msg_error:nn { regex } { c-bad-mode }
-        \exp_after:wN \exp_after:wN \exp_after:wN \use_none:n
+        \exp_after:wN \use_i:nnn
       \fi:
     \fi:
+    \use:n
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2421,7 +2424,7 @@
         \msg_error:nne { regex } { missing-rparen }
           { \int_use:N \l_@@_group_level_int }
         \prg_replicate:nn
-          { \l_@@_group_level_int }
+          \l_@@_group_level_int
           {
               \tl_build_put_right:Nn \l_@@_build_tl
                 {
@@ -2709,7 +2712,7 @@
         { \@@_compile_special:N \c_right_brace_str }
           {
             \exp_args:No \@@_compile_quantifier_lazyness:nnNN
-              { \int_use:N \l_@@_internal_a_int } { 0 }
+              { \int_use:N \l_@@_internal_a_int } 0
           }
         { \@@_compile_special:N , }
           {
@@ -2815,21 +2818,19 @@
 %   raw character; any special character, except a right bracket. In
 %   particular, escaped characters are forbidden.
 %    \begin{macrocode}
-\prg_new_protected_conditional:Npnn \@@_if_end_range:NN #1#2 { TF }
+\cs_new_protected:Npn \@@_if_end_range:NNTF #1#2
   {
     \if_meaning:w \@@_compile_raw:N #1
-      \prg_return_true:
     \else:
       \if_meaning:w \@@_compile_special:N #1
         \if_charcode:w ] #2
-          \prg_return_false:
-        \else:
-          \prg_return_true:
+          \use_i:nn
         \fi:
       \else:
-        \prg_return_false:
+        \exp_after:wN \exp_after:wN \exp_after:wN \use_iii:nnn
       \fi:
     \fi:
+    \use_i:nn
   }
 \cs_new_protected:Npn \@@_compile_range:Nw #1#2#3
   {
@@ -3457,7 +3458,7 @@
   }
 \cs_new_protected:Npn \@@_compile_c_lbrack_add:N #1
   {
-    \if_int_odd:w \int_eval:n { \l_@@_catcodes_int / #1 } \exp_stop_f:
+    \if_int_odd:w \@@_int_eval:w \l_@@_catcodes_int / #1 \scan_stop:
     \else:
       \int_add:Nn \l_@@_catcodes_int {#1}
     \fi:
@@ -3570,7 +3571,7 @@
         {#2}
         { \tl_if_head_eq_meaning_p:nN {#3} \@@_item_caseful_equal:n }
         { \int_compare_p:nNn { \tl_count:n {#3} } = { 2 } }
-        { \int_compare_p:nNn {#5} = { 0 } }
+        { \int_compare_p:nNn {#5} = \c_zero_int }
       }
       {
         \prg_replicate:nn {#4}
@@ -3854,10 +3855,10 @@
   }
 \cs_new:Npn \@@_clean_int_aux:N #1
   {
-    \if_int_compare:w 1 < 1 #1 ~
+    \if_int_compare:w \c_one_int < 1 #1 ~
       #1
     \else:
-      \exp_after:wN \str_map_break:
+      \str_map_break:n
     \fi:
   }
 \cs_new:Npn \@@_clean_regex:n #1
@@ -3878,7 +3879,7 @@
   }
 \cs_new:Npn \@@_clean_branch_loop:n #1
   {
-    \tl_if_single:nF {#1} { \prg_break: }
+    \tl_if_single:nF {#1} \prg_break:
     \token_case_meaning:NnF #1
       {
         \@@_command_K: { #1 \@@_clean_branch_loop:n }
@@ -3888,7 +3889,7 @@
         \@@_group_no_capture:nnnN { #1 \@@_clean_group:nnnN }
         \@@_group_resetting:nnnN { #1 \@@_clean_group:nnnN }
       }
-      { \prg_break: }
+      \prg_break:
   }
 \cs_new:Npn \@@_clean_assertion:Nn #1#2
   {
@@ -3909,16 +3910,16 @@
   {
     \@@_clean_bool:n {#1}
     { \@@_clean_class:n {#2} }
-    { \int_max:nn { 0 } { \@@_clean_int:n {#3} } }
-    { \int_max:nn { -1 } { \@@_clean_int:n {#4} } }
+    { \int_max:nn \c_zero_int { \@@_clean_int:n {#3} } }
+    { \int_max:nn { -\c_one_int } { \@@_clean_int:n {#4} } }
     \@@_clean_bool:n {#5}
     \@@_clean_branch_loop:n
   }
 \cs_new:Npn \@@_clean_group:nnnN #1#2#3#4
   {
     { \@@_clean_regex:n {#1} }
-    { \int_max:nn { 0 } { \@@_clean_int:n {#2} } }
-    { \int_max:nn { -1 } { \@@_clean_int:n {#3} } }
+    { \int_max:nn \c_zero_int { \@@_clean_int:n {#2} } }
+    { \int_max:nn { -\c_one_int } { \@@_clean_int:n {#3} } }
     \@@_clean_bool:n {#4}
     \@@_clean_branch_loop:n
   }
@@ -3933,7 +3934,7 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_clean_class_loop:nnn #1#2#3
   {
-    \tl_if_single:nF {#1} { \prg_break: }
+    \tl_if_single:nF {#1} \prg_break:
     \token_case_meaning:NnTF #1
       {
         \@@_item_cs:n { #1 { \@@_clean_regex:n {#2} } }
@@ -3965,10 +3966,10 @@
                 \@@_clean_class_loop:nnn
               }
               {
-                \exp_args:Nf \str_case:nnTF
+                \exp_args:Ne \str_case:nnTF
                   {
-                    \exp_args:Nf \str_range:nnn
-                      { \cs_to_str:N #1 } { 1 } { 13 }
+                    \exp_args:Ne \str_range:nnn
+                      { \cs_to_str:N #1 } \c_one_int { 13 }
                   }
                   {
                     { @@_prop_ } { }
@@ -3978,7 +3979,7 @@
                     #1
                     \@@_clean_class_loop:nnn {#2} {#3}
                   }
-                  { \prg_break: }
+                  \prg_break:
               }
           }
       }
@@ -4161,14 +4162,14 @@
       \int_zero:N \l_@@_show_lines_int
       \@@_show_push:n {~}
       #2
-    \int_compare:nTF { \l_@@_show_lines_int = 0 }
+    \int_compare:nTF { \l_@@_show_lines_int = \c_zero_int }
       {
         \group_end:
         \@@_show_one:n { \bool_if:NTF #1 { Fail } { Pass } }
       }
       {
         \bool_if:nTF
-          { #1 && \int_compare_p:n { \l_@@_show_lines_int = 1 } }
+          { #1 && \int_compare_p:n { \l_@@_show_lines_int = \c_one_int } }
           {
             \group_end:
             #2
@@ -4386,7 +4387,7 @@
     %
     \@@_build_new_state:
     \@@_toks_put_left:Ne \l_@@_left_state_int
-      { \@@_action_submatch:nN { 0 } < }
+      { \@@_action_submatch:nN \c_zero_int < }
     \@@_push_lr_states:
     \int_zero:N \l_@@_case_max_group_int
     \int_gzero:N \g_@@_case_int
@@ -4400,18 +4401,15 @@
   }
 \cs_new_protected:Npn \@@_case_build_loop:n #1
   {
-    \int_set:Nn \l_@@_capturing_group_int { 1 }
+    \int_set_eq:NN \l_@@_capturing_group_int \c_one_int
     \@@_compile_use:n {#1}
     \int_set:Nn \l_@@_case_max_group_int
-      {
-        \int_max:nn { \l_@@_case_max_group_int }
-          { \l_@@_capturing_group_int }
-      }
+      { \int_max:nn \l_@@_case_max_group_int \l_@@_capturing_group_int }
     \seq_pop:NN \l_@@_right_state_seq \l_@@_internal_a_tl
     \int_set:Nn \l_@@_right_state_int \l_@@_internal_a_tl
     \@@_toks_put_left:Ne \l_@@_right_state_int
       {
-        \@@_action_submatch:nN { 0 } >
+        \@@_action_submatch:nN \c_zero_int >
         \int_gset:Nn \g_@@_case_int
           { \int_use:N \g_@@_case_int }
         \@@_action_success:
@@ -4497,9 +4495,9 @@
 %   differing usage later on. Both functions could be optimized.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_build_transition_left:NNN #1#2#3
-  { \@@_toks_put_left:Ne  #2 { #1 { \int_eval:n { #3 - #2 } } } }
+  { \@@_toks_put_left:Ne  #2 { #1 { \tex_the:D \@@_int_eval:w #3 - #2 } } }
 \cs_new_protected:Npn \@@_build_transition_right:nNn #1#2#3
-  { \@@_toks_put_right:Ne #2 { #1 { \int_eval:n { #3 - #2 } } } }
+  { \@@_toks_put_right:Ne #2 { #1 { \tex_the:D \@@_int_eval:w #3 - #2 } } }
 %    \end{macrocode}
 % \end{macro}
 %
@@ -4531,11 +4529,11 @@
     \@@_toks_put_right:Ne \l_@@_left_state_int
       {
         \if_meaning:w \c_true_bool #1
-          #2 { \int_eval:n { #3 - \l_@@_left_state_int } }
-          #4 { \int_eval:n { #5 - \l_@@_left_state_int } }
+          #2 { \tex_the:D \@@_int_eval:w #3 - \l_@@_left_state_int }
+          #4 { \tex_the:D \@@_int_eval:w #5 - \l_@@_left_state_int }
         \else:
-          #4 { \int_eval:n { #5 - \l_@@_left_state_int } }
-          #2 { \int_eval:n { #3 - \l_@@_left_state_int } }
+          #4 { \tex_the:D \@@_int_eval:w #5 - \l_@@_left_state_int }
+          #2 { \tex_the:D \@@_int_eval:w #3 - \l_@@_left_state_int }
         \fi:
       }
   }
@@ -4633,7 +4631,7 @@
   {
     \@@_class_repeat:n {#1}
     \int_set:Nn \l_@@_internal_a_int
-      { \l_@@_max_state_int + #2 - 1 }
+      { \l_@@_max_state_int + #2 - \c_one_int }
     \prg_replicate:nn { #2 }
       {
         \@@_build_transitions_lazyness:NNNNN #3
@@ -4727,8 +4725,8 @@
     \use_none:nn #3 { \int_set:Nn \l_@@_capturing_group_int {#1} }
     \int_set:Nn \l_@@_capturing_group_int {#2}
     #3 {#4}
-    \exp_args:Nf \@@_group_resetting_loop:nnNn
-      { \int_max:nn {#1} { \l_@@_capturing_group_int } }
+    \exp_args:Ne \@@_group_resetting_loop:nnNn
+      { \int_max:nn {#1} \l_@@_capturing_group_int }
       {#2}
   }
 %    \end{macrocode}
@@ -4771,7 +4769,7 @@
   {
     \if_int_compare:w #2 = \c_zero_int
       \int_set:Nn \l_@@_max_state_int
-        { \l_@@_left_state_int - 1 }
+        { \l_@@_left_state_int - \c_one_int }
       \@@_build_new_state:
     \else:
       \@@_group_repeat_aux:n {#2}
@@ -4813,14 +4811,14 @@
       \l_@@_right_state_int \l_@@_max_state_int
     \int_set_eq:NN \l_@@_internal_a_int \l_@@_left_state_int
     \int_set_eq:NN \l_@@_internal_b_int \l_@@_max_state_int
-    \if_int_compare:w \int_eval:n {#1} > \c_one_int
+    \if_int_compare:w \@@_int_eval:w #1 > \c_one_int
       \int_set:Nn \l_@@_internal_c_int
         {
-          ( #1 - 1 )
+          ( #1 - \c_one_int )
           * ( \l_@@_internal_b_int - \l_@@_internal_a_int )
         }
-      \int_add:Nn \l_@@_right_state_int { \l_@@_internal_c_int }
-      \int_add:Nn \l_@@_max_state_int   { \l_@@_internal_c_int }
+      \int_add:Nn \l_@@_right_state_int \l_@@_internal_c_int
+      \int_add:Nn \l_@@_max_state_int   \l_@@_internal_c_int
       \@@_toks_memcpy:NNn
         \l_@@_internal_b_int
         \l_@@_internal_a_int
@@ -4856,7 +4854,7 @@
       \@@_group_submatches:nNN {#1}
         \l_@@_left_state_int \l_@@_right_state_int
       \int_set:Nn \l_@@_internal_a_int
-        { \l_@@_left_state_int - 1 }
+        { \l_@@_left_state_int - \c_one_int }
       \@@_build_transition_right:nNn \@@_action_free:n
         \l_@@_right_state_int \l_@@_internal_a_int
       \@@_build_new_state:
@@ -4916,7 +4914,7 @@
             \l_@@_left_state_int \l_@@_max_state_int
         }
     \else:
-      \prg_replicate:nn { #3 - 1 }
+      \prg_replicate:nn { #3 - \c_one_int }
         {
           \int_sub:Nn \l_@@_right_state_int
             { \l_@@_internal_b_int - \l_@@_internal_a_int }
@@ -4925,7 +4923,7 @@
         }
       \if_int_compare:w #2 = \c_zero_int
         \int_set:Nn \l_@@_right_state_int
-          { \l_@@_left_state_int - 1 }
+          { \l_@@_left_state_int - \c_one_int }
       \else:
         \int_sub:Nn \l_@@_right_state_int
           { \l_@@_internal_b_int - \l_@@_internal_a_int }
@@ -4960,8 +4958,8 @@
           {
             \@@_action_free:n
               {
-                \int_eval:n
-                  { \l_@@_right_state_int - \l_@@_left_state_int }
+                \tex_the:D \@@_int_eval:w
+                  \l_@@_right_state_int - \l_@@_left_state_int
               }
           }
           \bool_if:NT #1 { { } }
@@ -5006,12 +5004,12 @@
     \@@_build_new_state:
     \@@_toks_put_right:Ne \l_@@_left_state_int
       {
-        \@@_action_submatch:nN { 0 } <
+        \@@_action_submatch:nN \c_zero_int <
         \bool_set_true:N \l_@@_fresh_thread_bool
         \@@_action_free:n
           {
-            \int_eval:n
-              { \l_@@_right_state_int - \l_@@_left_state_int }
+            \tex_the:D \@@_int_eval:w
+              \l_@@_right_state_int - \l_@@_left_state_int
           }
         \bool_set_false:N \l_@@_fresh_thread_bool
       }
@@ -5297,10 +5295,10 @@
   {
     \bool_gset_false:N \g_@@_success_bool
     \int_step_inline:nnn
-      \l_@@_min_state_int { \l_@@_max_state_int - 1 }
+      \l_@@_min_state_int { \l_@@_max_state_int - \c_one_int }
       {
         \__kernel_intarray_gset:Nnn
-          \g_@@_state_active_intarray {##1} { 1 }
+          \g_@@_state_active_intarray {##1} \c_one_int
       }
     \int_zero:N \l_@@_step_int
     \int_set:Nn \l_@@_min_pos_int { 2 }
@@ -5308,7 +5306,7 @@
     \int_set:Nn \l_@@_last_char_success_int { -2 }
     \tl_build_begin:N \l_@@_matched_analysis_tl
     \tl_clear:N \l_@@_curr_analysis_tl
-    \int_set:Nn \l_@@_min_submatch_int { 1 }
+    \int_set_eq:NN \l_@@_min_submatch_int \c_one_int
     \int_set_eq:NN \l_@@_submatch_int \l_@@_min_submatch_int
     \bool_set_false:N \l_@@_empty_success_bool
   }
@@ -5350,8 +5348,7 @@
       { \prg_replicate:nn { 2 * \l_@@_capturing_group_int } { 0 , } }
     \int_set_eq:NN \l_@@_max_thread_int \l_@@_min_thread_int
     \@@_store_state:n { \l_@@_min_state_int }
-    \int_set:Nn \l_@@_curr_pos_int
-      { \l_@@_start_pos_int - 1 }
+    \int_set:Nn \l_@@_curr_pos_int { \l_@@_start_pos_int - \c_one_int }
     \int_set_eq:NN \l_@@_curr_char_int \l_@@_last_char_success_int
     \tl_build_get_intermediate:NN \l_@@_matched_analysis_tl \l_@@_internal_a_tl
     \exp_args:NNf \@@_match_once_init_aux:
@@ -5429,15 +5426,15 @@
       {
         \int_set_eq:NN \l_@@_max_thread_int \l_@@_min_thread_int
         \int_step_function:nnN
-          { \l_@@_min_thread_int }
-          { \l_@@_max_thread_int - 1 }
+          \l_@@_min_thread_int
+          { \l_@@_max_thread_int - \c_one_int }
           \@@_match_one_active:n
       }
     \prg_break_point:
     \bool_set_false:N \l_@@_fresh_thread_bool
     \if_int_compare:w \l_@@_max_thread_int > \l_@@_min_thread_int
       \if_int_compare:w -2 < \l_@@_curr_char_int
-        \exp_after:wN \exp_after:wN \exp_after:wN \use_none:n
+        \exp_after:wN \use_i:nn
       \fi:
     \fi:
     \l_@@_every_match_tl
@@ -5447,8 +5444,8 @@
     \@@_use_state_and_submatches:w
     \__kernel_intarray_range_to_clist:Nnn
       \g_@@_thread_info_intarray
-      { 1 + #1 * (\l_@@_capturing_group_int * 2 + 1) }
-      { (1 + #1) * (\l_@@_capturing_group_int * 2 + 1) }
+      { \c_one_int + #1 * (\l_@@_capturing_group_int * 2 + \c_one_int) }
+      { (\c_one_int + #1) * (\l_@@_capturing_group_int * 2 + \c_one_int) }
     ;
   }
 %    \end{macrocode}
@@ -5468,11 +5465,11 @@
 \cs_new_protected:Npn \@@_use_state:
   {
     \__kernel_intarray_gset:Nnn \g_@@_state_active_intarray
-      { \l_@@_curr_state_int } { \l_@@_step_int }
+      \l_@@_curr_state_int \l_@@_step_int
     \@@_toks_use:w \l_@@_curr_state_int
     \__kernel_intarray_gset:Nnn \g_@@_state_active_intarray
-      { \l_@@_curr_state_int }
-      { \int_eval:n { \l_@@_step_int + 1 } }
+      \l_@@_curr_state_int
+      { \@@_int_eval:w \l_@@_step_int + \c_one_int \scan_stop: }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -5488,7 +5485,7 @@
     \int_set:Nn \l_@@_curr_state_int {#1}
     \if_int_compare:w
         \__kernel_intarray_item:Nn \g_@@_state_active_intarray
-          { \l_@@_curr_state_int }
+          \l_@@_curr_state_int
                       < \l_@@_step_int
       \tl_set:Nn \l_@@_curr_submatches_tl { #2 , }
       \exp_after:wN \@@_use_state:
@@ -5545,7 +5542,7 @@
           {
             \if_int_compare:w
                 \__kernel_intarray_item:Nn \g_@@_state_active_intarray
-                  { \l_@@_curr_state_int }
+                  \l_@@_curr_state_int
                 #1
               \exp_after:wN \@@_use_state:
             \fi:
@@ -5568,8 +5565,8 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_action_cost:n #1
   {
-    \exp_args:Ne \@@_store_state:n
-      { \int_eval:n { \l_@@_curr_state_int + #1 } }
+    \exp_args:No \@@_store_state:n
+      { \tex_the:D \@@_int_eval:w \l_@@_curr_state_int + #1 }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -5592,8 +5589,8 @@
       \g_@@_thread_info_intarray
       {
         \@@_int_eval:w
-        1 + \l_@@_max_thread_int *
-        (\l_@@_capturing_group_int * 2 + 1)
+        \c_one_int + \l_@@_max_thread_int *
+        (\l_@@_capturing_group_int * 2 + \c_one_int)
       }
       { #2 , #1 }
   }
@@ -5789,11 +5786,11 @@
   {
     \if_int_compare:w #1 < #2 \exp_stop_f:
     \else:
-      \exp_after:wN \prg_break:
+      \prg_break:n
     \fi:
     \@@_toks_use:w #1 \exp_stop_f:
     \exp_after:wN \@@_query_range_loop:ww
-      \int_value:w \@@_int_eval:w #1 + 1 ; #2 ;
+      \int_value:w \@@_int_eval:w #1 + \c_one_int ; #2 ;
   }
 %    \end{macrocode}
 % \end{macro}
@@ -5821,22 +5818,21 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_submatch_balance:n #1
   {
-    \int_eval:n
-      {
-        \@@_intarray_item:NnF \g_@@_balance_intarray
-          {
-            \__kernel_intarray_item:Nn
-              \g_@@_submatch_end_intarray {#1}
-          }
-          { 0 }
-        -
-        \@@_intarray_item:NnF \g_@@_balance_intarray
-          {
-            \__kernel_intarray_item:Nn
-              \g_@@_submatch_begin_intarray {#1}
-          }
-          { 0 }
-      }
+    \tex_the:D \@@_int_eval:w
+      \@@_intarray_item:NnF \g_@@_balance_intarray
+        {
+          \__kernel_intarray_item:Nn
+            \g_@@_submatch_end_intarray {#1}
+        }
+        \c_zero_int
+      -
+      \@@_intarray_item:NnF \g_@@_balance_intarray
+        {
+          \__kernel_intarray_item:Nn
+            \g_@@_submatch_begin_intarray {#1}
+        }
+        \c_zero_int
+    \scan_stop:
   }
 %    \end{macrocode}
 % \end{macro}
@@ -5981,7 +5977,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_replacement_normal:n #1
   {
-    \int_compare:nNnTF { \l_@@_replacement_csnames_int } > 0
+    \int_compare:nNnTF \l_@@_replacement_csnames_int > \c_zero_int
       { \exp_args:No \@@_replacement_put:n { \token_to_str:N #1 } }
       {
         \tl_if_empty:NTF \l_@@_replacement_category_tl
@@ -6037,7 +6033,7 @@
   {
     \cs_if_exist_use:cF { @@_replacement_#1:w }
       {
-        \if_int_compare:w 1 < 1#1 \exp_stop_f:
+        \if_int_compare:w \c_one_int < 1#1 \exp_stop_f:
           \@@_replacement_put_submatch:n {#1}
         \else:
           \@@_replacement_normal:n {#1}
@@ -6063,16 +6059,16 @@
       \@@_replacement_put_submatch_aux:n {#1}
     \else:
       \msg_expandable_error:nnff { regex } { submatch-too-big }
-        {#1} { \int_eval:n { \l_@@_capturing_group_int - 1 } }
+        {#1} { \int_eval:n { \l_@@_capturing_group_int - \c_one_int } }
     \fi:
   }
 \cs_new_protected:Npn \@@_replacement_put_submatch_aux:n #1
   {
     \tl_build_put_right:Nn \l_@@_build_tl
-      { \@@_query_submatch:n { \int_eval:n { #1 + ##1 } } }
+      { \@@_query_submatch:n { \@@_int_eval:w #1 + ##1 \scan_stop: } }
     \if_int_compare:w \l_@@_replacement_csnames_int = \c_zero_int
       \tl_gput_right:Nn \g_@@_balance_tl
-        { + \@@_submatch_balance:n { \int_eval:n { #1 + ##1 } } }
+        { + \@@_submatch_balance:n { \@@_int_eval:w #1 + ##1 \scan_stop: } }
     \fi:
   }
 %    \end{macrocode}
@@ -6094,7 +6090,7 @@
   {
     \token_if_eq_meaning:NNTF #1 \@@_replacement_normal:n
       {
-        \if_int_compare:w 1 < 1#2 \exp_stop_f:
+        \if_int_compare:w \c_one_int < 1#2 \exp_stop_f:
           #2
           \exp_after:wN \use_i:nnn
           \exp_after:wN \@@_replacement_g_digits:NN
@@ -6229,7 +6225,7 @@
     \token_if_eq_meaning:NNTF \prg_do_nothing: #3
       { \msg_error:nn { regex } { replacement-catcode-end } }
       {
-        \int_compare:nNnTF { \l_@@_replacement_csnames_int } > 0
+        \int_compare:nNnTF \l_@@_replacement_csnames_int > \c_zero_int
           {
             \msg_error:nnnn
               { regex } { replacement-catcode-in-cs } {#1} {#3}
@@ -6281,7 +6277,7 @@
 %    \begin{macrocode}
   \cs_new_protected:Npn \@@_replacement_char:nNN #1#2#3
     {
-      \tex_lccode:D 0 = `#3 \scan_stop:
+      \tex_lccode:D \c_zero_int = `#3 \scan_stop:
       \tex_lowercase:D { \@@_replacement_put:n {#1} }
     }
 %    \end{macrocode}
@@ -6634,7 +6630,6 @@
     \prg_generate_conditional_variant:Nnn #2 { nV } { T , F , TF }
     \cs_generate_variant:Nn #3 { NV }
     \prg_generate_conditional_variant:Nnn #3 { NV } { T , F , TF }
-
   }
 \@@_tmp:w \@@_extract_once:nnN
   \regex_extract_once:nnN \regex_extract_once:NnN
@@ -6816,7 +6811,7 @@
     \int_incr:N \l_@@_curr_pos_int
     \@@_toks_set:Nn \l_@@_curr_pos_int {#1}
     \__kernel_intarray_gset:Nnn \g_@@_balance_intarray
-      { \l_@@_curr_pos_int } { \l_@@_balance_int }
+      \l_@@_curr_pos_int \l_@@_balance_int
     \if_case:w "#2 \exp_stop_f:
     \or: \int_incr:N \l_@@_balance_int
     \or: \int_decr:N \l_@@_balance_int
@@ -6943,29 +6938,29 @@
             \l_@@_start_pos_int < \l_@@_success_pos_int
             \@@_extract:
             \__kernel_intarray_gset:Nnn \g_@@_submatch_prev_intarray
-              { \l_@@_zeroth_submatch_int } { 0 }
+              \l_@@_zeroth_submatch_int \c_zero_int
             \__kernel_intarray_gset:Nnn \g_@@_submatch_end_intarray
-              { \l_@@_zeroth_submatch_int }
+              \l_@@_zeroth_submatch_int
               {
                 \__kernel_intarray_item:Nn \g_@@_submatch_begin_intarray
-                  { \l_@@_zeroth_submatch_int }
+                  \l_@@_zeroth_submatch_int
               }
             \__kernel_intarray_gset:Nnn \g_@@_submatch_begin_intarray
-              { \l_@@_zeroth_submatch_int }
-              { \l_@@_start_pos_int }
+              \l_@@_zeroth_submatch_int
+              \l_@@_start_pos_int
           \fi:
         }
       #1
       \@@_match:n {#2}
       \@@_query_set:n {#2}
       \__kernel_intarray_gset:Nnn \g_@@_submatch_prev_intarray
-        { \l_@@_submatch_int } { 0 }
+        \l_@@_submatch_int \c_zero_int
       \__kernel_intarray_gset:Nnn \g_@@_submatch_end_intarray
-        { \l_@@_submatch_int }
-        { \l_@@_max_pos_int }
+        \l_@@_submatch_int
+        \l_@@_max_pos_int
       \__kernel_intarray_gset:Nnn \g_@@_submatch_begin_intarray
-        { \l_@@_submatch_int }
-        { \l_@@_start_pos_int }
+        \l_@@_submatch_int
+        \l_@@_start_pos_int
       \int_incr:N \l_@@_submatch_int
       \if_meaning:w \c_true_bool \l_@@_empty_success_bool
         \if_int_compare:w \l_@@_start_pos_int = \l_@@_max_pos_int
@@ -7000,8 +6995,8 @@
       \cs_set_eq:NN \@@_tmp:w \scan_stop:
       \__kernel_tl_gset:Ne \g_@@_internal_tl
         {
-          \int_step_function:nnN { \l_@@_min_submatch_int }
-            { \l_@@_submatch_int - 1 } \@@_extract_seq_aux:n
+          \int_step_function:nnN \l_@@_min_submatch_int
+            { \l_@@_submatch_int - \c_one_int } \@@_extract_seq_aux:n
           \@@_tmp:w
         }
       \int_set:Nn \l_@@_added_begin_int
@@ -7012,7 +7007,7 @@
       \__kernel_tl_gset:Ne \g_@@_internal_tl
         { \g_@@_internal_tl \if_false: { \fi: } }
       \int_compare:nNnT
-        { \l_@@_added_begin_int + \l_@@_added_end_int } > 0
+        { \l_@@_added_begin_int + \l_@@_added_end_int } > \c_zero_int
         {
           \msg_error:nneee { regex } { result-unbalanced }
             { splitting~or~extracting~submatches }
@@ -7166,15 +7161,15 @@
       \prg_replicate:nn \l_@@_capturing_group_int
         {
           \__kernel_intarray_gset:Nnn \g_@@_submatch_prev_intarray
-            { \l_@@_submatch_int } { 0 }
+            \l_@@_submatch_int \c_zero_int
           \__kernel_intarray_gset:Nnn \g_@@_submatch_case_intarray
-            { \l_@@_submatch_int } { 0 }
+            \l_@@_submatch_int \c_zero_int
           \int_incr:N \l_@@_submatch_int
         }
       \__kernel_intarray_gset:Nnn \g_@@_submatch_prev_intarray
-        { \l_@@_zeroth_submatch_int } { \l_@@_start_pos_int }
+        \l_@@_zeroth_submatch_int \l_@@_start_pos_int
       \__kernel_intarray_gset:Nnn \g_@@_submatch_case_intarray
-        { \l_@@_zeroth_submatch_int } { \g_@@_case_int }
+        \l_@@_zeroth_submatch_int \g_@@_case_int
       \int_zero:N \l_@@_internal_a_int
       \exp_after:wN \@@_extract_aux:w \l_@@_success_submatches_tl
         \prg_break_point: \@@_use_none_delimit_by_q_recursion_stop:w ,
@@ -7189,7 +7184,12 @@
         { \@@_int_eval:w \l_@@_zeroth_submatch_int + \l_@@_internal_a_int } {#1}
     \else:
       \__kernel_intarray_gset:Nnn \g_@@_submatch_end_intarray
-        { \@@_int_eval:w \l_@@_zeroth_submatch_int + \l_@@_internal_a_int - \l_@@_capturing_group_int } {#1}
+        {
+          \@@_int_eval:w
+            \l_@@_zeroth_submatch_int + \l_@@_internal_a_int
+            - \l_@@_capturing_group_int
+        }
+        {#1}
     \fi:
     \int_incr:N \l_@@_internal_a_int
     \@@_extract_aux:w
@@ -7227,20 +7227,16 @@
         \exp_args:No \@@_query_set:n {#3}
         #2
         \int_set:Nn \l_@@_balance_int
-          {
-            \@@_replacement_balance_one_match:n
-              { \l_@@_zeroth_submatch_int }
-          }
+          { \@@_replacement_balance_one_match:n \l_@@_zeroth_submatch_int }
         \__kernel_tl_set:Nx \l_@@_internal_a_tl
           {
-            \@@_replacement_do_one_match:n
-              { \l_@@_zeroth_submatch_int }
+            \@@_replacement_do_one_match:n \l_@@_zeroth_submatch_int
             \@@_query_range:nn
               {
                 \__kernel_intarray_item:Nn \g_@@_submatch_end_intarray
-                  { \l_@@_zeroth_submatch_int }
+                  \l_@@_zeroth_submatch_int
               }
-              { \l_@@_max_pos_int }
+              \l_@@_max_pos_int
           }
         \@@_group_end_replace:N #3
       }
@@ -7273,19 +7269,19 @@
       #2
       \int_set:Nn \l_@@_balance_int
         {
-          0
+          \c_zero_int
           \int_step_function:nnnN
-            { \l_@@_min_submatch_int }
+            \l_@@_min_submatch_int
             \l_@@_capturing_group_int
-            { \l_@@_submatch_int - 1 }
+            { \l_@@_submatch_int - \c_one_int }
             \@@_replacement_balance_one_match:n
         }
       \__kernel_tl_set:Nx \l_@@_internal_a_tl
         {
           \int_step_function:nnnN
-            { \l_@@_min_submatch_int }
+            \l_@@_min_submatch_int
             \l_@@_capturing_group_int
-            { \l_@@_submatch_int - 1 }
+            { \l_@@_submatch_int - \c_one_int }
             \@@_replacement_do_one_match:n
           \@@_query_range:nn
             \l_@@_start_pos_int \l_@@_max_pos_int
@@ -7318,11 +7314,12 @@
 \cs_new_protected:Npn \@@_group_end_replace:N #1
   {
     \int_set:Nn \l_@@_added_begin_int
-      { \int_max:nn { - \l_@@_balance_int } { 0 } }
+      { \int_max:nn { - \l_@@_balance_int } \c_zero_int }
     \int_set:Nn \l_@@_added_end_int
-      { \int_max:nn { \l_@@_balance_int } { 0 } }
+      { \int_max:nn \l_@@_balance_int \c_zero_int }
     \@@_group_end_replace_try:
-    \int_compare:nNnT { \l_@@_added_begin_int + \l_@@_added_end_int } > 0
+    \int_compare:nNnT { \l_@@_added_begin_int + \l_@@_added_end_int }
+                      > \c_zero_int
       {
         \msg_error:nneee { regex } { result-unbalanced }
           { replacing } { \int_use:N \l_@@_added_begin_int }
@@ -7336,9 +7333,9 @@
     \tex_afterassignment:D \@@_group_end_replace_check:w
     \__kernel_tl_gset:Ne \g_@@_internal_tl
       {
-        \prg_replicate:nn { \l_@@_added_begin_int } { { \if_false: } \fi: }
+        \prg_replicate:nn \l_@@_added_begin_int { { \if_false: } \fi: }
         \l_@@_internal_a_tl
-        \prg_replicate:nn { \l_@@_added_end_int } { \if_false: { \fi: } }
+        \prg_replicate:nn \l_@@_added_end_int { \if_false: { \fi: } }
         \if_false: { \fi: }
       }
   }
@@ -7615,14 +7612,13 @@
         \use:e
           {
             \exp_not:n { \exp_after:wN \l_@@_peek_true_tl \exp:w }
-            \@@_replacement_do_one_match:n
-              { \l_@@_zeroth_submatch_int }
+            \@@_replacement_do_one_match:n \l_@@_zeroth_submatch_int
             \@@_query_range:nn
               {
                 \__kernel_intarray_item:Nn \g_@@_submatch_end_intarray
-                  { \l_@@_zeroth_submatch_int }
+                  \l_@@_zeroth_submatch_int
               }
-              { \l_@@_max_pos_int }
+              \l_@@_max_pos_int
             \exp_end:
           }
       }
@@ -7705,10 +7701,14 @@
   {
     \if_case:w \l_@@_replacement_csnames_int
       \tl_build_put_right:Nn \l_@@_build_tl
-        { \@@_query_submatch:n { \int_eval:n { #1 + ##1 } } }
+        { \@@_query_submatch:n { \@@_int_eval:w #1 + ##1 \scan_stop: } }
     \else:
       \tl_build_put_right:Nn \l_@@_build_tl
-        { \exp:w \@@_query_submatch:n { \int_eval:n { #1 + ##1 } } \exp_end: }
+        {
+          \exp:w
+            \@@_query_submatch:n { \@@_int_eval:w #1 + ##1 \scan_stop: }
+          \exp_end:
+        }
     \fi:
   }
 %    \end{macrocode}
@@ -8138,7 +8138,7 @@
   {
     \int_step_inline:nnn
       \l_@@_min_state_int
-      { \l_@@_max_state_int - 1 }
+      { \l_@@_max_state_int - \c_one_int }
       {
         \@@_trace:nne { regex } {#1}
           { \iow_char:N \\toks ##1 = { \@@_toks_use:w ##1 } }





More information about the latex3-commits mailing list.