[latex3-commits] [git/LaTeX3-latex3-latex3] master: Refactor code in l3intarray and speed up new intarray_gzero (ce757b4)

Bruno Le Floch bruno at le-floch.fr
Sat May 5 00:33:32 CEST 2018


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

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

commit ce757b42b5abb3166cf9df7a2f01cb505960f8fe
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sat May 5 00:33:32 2018 +0200

    Refactor code in l3intarray and speed up new intarray_gzero


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

ce757b42b5abb3166cf9df7a2f01cb505960f8fe
 l3kernel/l3intarray.dtx                 |   68 +++++++++++++++++++------------
 l3kernel/testfiles/m3expl001.luatex.tlg |    4 ++
 l3kernel/testfiles/m3expl001.ptex.tlg   |    4 ++
 l3kernel/testfiles/m3expl001.tlg        |    4 ++
 l3kernel/testfiles/m3expl001.uptex.tlg  |    4 ++
 l3kernel/testfiles/m3expl001.xetex.tlg  |    4 ++
 l3kernel/testfiles/m3expl003.luatex.tlg |    4 ++
 l3kernel/testfiles/m3expl003.ptex.tlg   |    4 ++
 l3kernel/testfiles/m3expl003.tlg        |    4 ++
 l3kernel/testfiles/m3expl003.uptex.tlg  |    4 ++
 l3kernel/testfiles/m3expl003.xetex.tlg  |    4 ++
 11 files changed, 82 insertions(+), 26 deletions(-)

diff --git a/l3kernel/l3intarray.dtx b/l3kernel/l3intarray.dtx
index e1e9353..c17de63 100644
--- a/l3kernel/l3intarray.dtx
+++ b/l3kernel/l3intarray.dtx
@@ -151,6 +151,13 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{variable}{\l_@@_loop_int}
+%   A loop index.
+%    \begin{macrocode}
+\int_new:N \l_@@_loop_int
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{variable}{\c_@@_sp_dim}
 %   Used to convert integers to dimensions fast.
 %    \begin{macrocode}
@@ -170,7 +177,7 @@
   { Size~of~intarray~may~not~be~negative:~#1 }
 %    \end{macrocode}
 %
-% \begin{macro}{\intarray_new:Nn}
+% \begin{macro}{\intarray_new:Nn, \@@_new:N}
 %   Declare |#1| to be a font (arbitrarily |cmr10| at a never-used
 %   size).  Store the array's size as the \tn{hyphenchar} of that font
 %   and make sure enough \tn{fontdimen} are allocated, by setting the
@@ -181,13 +188,19 @@
 %   Every \texttt{intarray} must be global; it's enough to run this
 %   check in \cs{intarray_new:Nn}.
 %    \begin{macrocode}
-\__kernel_patch:nnNNpn { \__kernel_chk_var_scope:NN g #1 } { }
-\cs_new_protected:Npn \intarray_new:Nn #1#2
+\cs_new_protected:Npn \@@_new:N #1
   {
     \__kernel_chk_if_free_cs:N #1
     \int_gincr:N \g_@@_font_int
     \tex_global:D \tex_font:D #1
       = cmr10~at~ \g_@@_font_int \c_@@_sp_dim \scan_stop:
+    \int_step_inline:nn { 8 }
+      { \__kernel_intarray_gset:Nnn #1 {##1} \c_zero }
+  }
+\__kernel_patch:nnNNpn { \__kernel_chk_var_scope:NN g #1 } { }
+\cs_new_protected:Npn \intarray_new:Nn #1#2
+  {
+    \@@_new:N #1
     \@@_count:w #1 = \int_eval:n {#2} \scan_stop:
     \int_compare:nNnT { \intarray_count:N #1 } < 0
       {
@@ -196,8 +209,6 @@
       }
     \int_compare:nNnT { \intarray_count:N #1 } > 0
       { \__kernel_intarray_gset:Nnn #1 { \intarray_count:N #1 } { 0 } }
-    \int_step_inline:nn { 8 }
-      { \__kernel_intarray_gset:Nnn #1 {##1} { 0 } }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -255,31 +266,30 @@
     \int_value:w \int_eval:n {#2} \exp_after:wN ;
     \int_value:w \int_eval:n {#3} ;
   }
+\cs_new_protected:Npn \@@_gset:Nww #1#2 ; #3 ;
+  {
+    \@@_bounds:NNnTF \__kernel_msg_error:nnxxx #1 {#2}
+      {
+        \@@_gset_overflow_test:nw {#3}
+        \__kernel_intarray_gset:Nnn #1 {#2} {#3}
+      }
+      { }
+  }
 \cs_if_exist:NTF \tex_ifabsnum:D
   {
-    \cs_new_protected:Npn \@@_gset:Nww #1#2 ; #3 ;
+    \cs_new_protected:Npn \@@_gset_overflow_test:nw #1
       {
-        \@@_bounds:NNnTF \__kernel_msg_error:nnxxx #1 {#2}
-          {
-            \tex_ifabsnum:D #3 > \c_max_dim
-              \exp_after:wN \@@_gset_overflow:NNnn
-            \fi:
-            \__kernel_intarray_gset:Nnn #1 {#2} {#3}
-          }
-          { }
+        \tex_ifabsnum:D #1 > \c_max_dim
+          \exp_after:wN \@@_gset_overflow:NNnn
+        \fi:
       }
   }
   {
-    \cs_new_protected:Npn \@@_gset:Nww #1#2 ; #3 ;
+    \cs_new_protected:Npn \@@_gset_overflow_test:nw #1
       {
-        \@@_bounds:NNnTF \__kernel_msg_error:nnxxx #1 {#2}
-          {
-            \if_int_compare:w \int_abs:n {#3} > \c_max_dim
-              \exp_after:wN \@@_gset_overflow:NNnn
-            \fi:
-            \__kernel_intarray_gset:Nnn #1 {#2} {#3}
-          }
-          { }
+        \if_int_compare:w \int_abs:n {#1} > \c_max_dim
+          \exp_after:wN \@@_gset_overflow:NNnn
+        \fi:
       }
   }
 \cs_new_protected:Npn \@@_gset_overflow:NNnn #1#2#3#4
@@ -296,12 +306,18 @@
 %
 % \begin{macro}{\intarray_gzero:N}
 %   Set the appropriate \tn{fontdimen} to zero.  No bound checking
-%   needed.
+%   needed.  The \cs{prg_replicate:nn} possibly uses quite a lot of
+%   memory, but this is somewhat comparable to the size of the array,
+%   and it is much faster than an \cs{int_step_inline:nn} loop.
 %    \begin{macrocode}
 \cs_new_protected:Npn \intarray_gzero:N #1
   {
-    \int_step_inline:nn { \intarray_count:N #1 }
-      { \@@_entry:w ##1 #1 \c_zero_dim }
+    \int_zero:N \l_@@_loop_int
+    \prg_replicate:nn { \intarray_count:N #1 }
+      {
+        \int_incr:N \l_@@_loop_int
+        \@@_entry:w \l_@@_loop_int #1 \c_zero_dim
+      }
   }
 %    \end{macrocode}
 % \end{macro}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 27171a8..e0fa715 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -4222,11 +4222,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4234,6 +4237,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 3a19505..5aaf5ce 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -4476,11 +4476,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4488,6 +4491,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 355a44c..71d1410 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -4476,11 +4476,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4488,6 +4491,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 02d8a86..ea0e5c5 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -4476,11 +4476,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4488,6 +4491,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index e30e599..7462007 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -4196,11 +4196,14 @@ Defining \__fp_randint_o:Nw on line ...
 Defining \int_rand:nn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4208,6 +4211,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 27171a8..e0fa715 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -4222,11 +4222,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4234,6 +4237,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 3a19505..5aaf5ce 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -4476,11 +4476,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4488,6 +4491,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 355a44c..71d1410 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -4476,11 +4476,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4488,6 +4491,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 02d8a86..ea0e5c5 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -4476,11 +4476,14 @@ Defining \__fp_randint_narrow:nn on line ...
 Defining \__fp_randint_narrow:nnn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4488,6 +4491,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index e30e599..7462007 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -4196,11 +4196,14 @@ Defining \__fp_randint_o:Nw on line ...
 Defining \int_rand:nn on line ...
 Defining \__intarray_entry:w on line ...
 Defining \__intarray_count:w on line ...
+Defining \l__intarray_loop_int on line ...
+\l__intarray_loop_int=\count...
 Defining \c__intarray_sp_dim on line ...
 \c__intarray_sp_dim=\dimen...
 Defining \g__intarray_font_int on line ...
 \g__intarray_font_int=\count...
 Defining message LaTeX/kernel/negative-intarray-size on line ...
+Defining \__intarray_new:N on line ...
 Defining \intarray_new:Nn on line ...
 Defining \intarray_count:N on line ...
 Defining \__intarray_bounds:NNnTF on line ...
@@ -4208,6 +4211,7 @@ Defining \__intarray_bounds_error:NNn on line ...
 Defining \__kernel_intarray_gset:Nnn on line ...
 Defining \intarray_gset:Nnn on line ...
 Defining \__intarray_gset:Nww on line ...
+Defining \__intarray_gset_overflow_test:nw on line ...
 Defining \__intarray_gset_overflow:NNnn on line ...
 Defining \intarray_gzero:N on line ...
 Defining \__kernel_intarray_item:Nn on line ...





More information about the latex3-commits mailing list