[latex3-commits] [git/LaTeX3-latex3-latex3] master: Use tl_build in l3draw-softpath.dtx (5039070)
Bruno Le Floch
bruno at le-floch.fr
Mon Apr 2 06:50:51 CEST 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/5039070cb0e1718aecd98792e0a93a32ce7285bc
>---------------------------------------------------------------
commit 5039070cb0e1718aecd98792e0a93a32ce7285bc
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Mon Apr 2 00:50:51 2018 -0400
Use tl_build in l3draw-softpath.dtx
>---------------------------------------------------------------
5039070cb0e1718aecd98792e0a93a32ce7285bc
l3experimental/l3draw/l3draw-paths.dtx | 7 +-
l3experimental/l3draw/l3draw-softpath.dtx | 98 +++++--------------------
l3experimental/l3draw/testfiles/m3draw000.tlg | 2 -
l3kernel/l3candidates.dtx | 23 ++++++
l3kernel/testfiles/m3expl001.luatex.tlg | 2 +
l3kernel/testfiles/m3expl001.ptex.tlg | 2 +
l3kernel/testfiles/m3expl001.tlg | 2 +
l3kernel/testfiles/m3expl001.uptex.tlg | 2 +
l3kernel/testfiles/m3expl001.xetex.tlg | 2 +
l3kernel/testfiles/m3expl003.luatex.tlg | 2 +
l3kernel/testfiles/m3expl003.ptex.tlg | 2 +
l3kernel/testfiles/m3expl003.tlg | 2 +
l3kernel/testfiles/m3expl003.uptex.tlg | 2 +
l3kernel/testfiles/m3expl003.xetex.tlg | 2 +
14 files changed, 63 insertions(+), 87 deletions(-)
diff --git a/l3experimental/l3draw/l3draw-paths.dtx b/l3experimental/l3draw/l3draw-paths.dtx
index 09df839..861ee87 100644
--- a/l3experimental/l3draw/l3draw-paths.dtx
+++ b/l3experimental/l3draw/l3draw-paths.dtx
@@ -1001,8 +1001,7 @@
\dim_set_eq:NN \l_@@_softpath_lastx_dim \g_@@_softpath_lastx_dim
\dim_set_eq:NN \l_@@_softpath_lasty_dim \g_@@_softpath_lasty_dim
\@@_path_reset_limits:
- \@@_softpath_concat:n { }
- \tl_set_eq:NN \l_@@_softpath_main_tl \g_@@_softpath_main_tl
+ \tl_build_get:NN \g_@@_softpath_main_tl \l_@@_softpath_main_tl
\bool_set_eq:NN
\l_@@_softpath_corners_bool
\g_@@_softpath_corners_bool
@@ -1010,11 +1009,11 @@
}
\cs_new_protected:Npn \draw_path_scope_end:
{
+ \@@_softpath_clear:
\bool_gset_eq:NN
\g_@@_softpath_corners_bool
\l_@@_softpath_corners_bool
- \@@_softpath_clear:
- \tl_gset_eq:NN \g_@@_softpath_main_tl \l_@@_softpath_main_tl
+ \@@_softpath_add:o \l_@@_softpath_main_tl
\dim_gset_eq:NN \g_@@_softpath_lastx_dim \l_@@_softpath_lastx_dim
\dim_gset_eq:NN \g_@@_softpath_lasty_dim \l_@@_softpath_lasty_dim
\dim_gset_eq:NN \g_@@_path_xmax_dim \l_@@_path_xmax_dim
diff --git a/l3experimental/l3draw/l3draw-softpath.dtx b/l3experimental/l3draw/l3draw-softpath.dtx
index f980835..2cfc715 100644
--- a/l3experimental/l3draw/l3draw-softpath.dtx
+++ b/l3experimental/l3draw/l3draw-softpath.dtx
@@ -65,40 +65,25 @@
% the corners. This means that the path cannot be written piecemeal as
% specials, but rather needs to be held in macros. The second aspect that
% follows from this is performance: simply adding to a single macro a piece
-% at a time will have poor performance as the list gets long. Paths need to
-% be global (as specials are), so we cannot use \pkg{l3tl-build} or a similar
-% approach. Instead, we use the same idea as \pkg{pgf}: use a series of buffer
-% macros such that in most cases we don't add tokens to the main list. This
-% will get slow only for \emph{enormous} paths.
+% at a time will have poor performance as the list gets long so we use
+% \cs[no-index]{tl_build_\ldots{}} functions.
%
% Each marker (operation) token takes two arguments, which makes processing
% more straight-forward. As such, some operations have dummy arguments, whilst
% others have to be split over several tokens. As the code here is at a low
% level, all dimension arguments are assumed to be explicit and fully-expanded.
%
-% \begin{variable}
-% {
-% \g_@@_softpath_main_tl ,
-% \g_@@_softpath_buffer_a_tl ,
-% \g_@@_softpath_buffer_b_tl
-% }
+% \begin{variable}{\g_@@_softpath_main_tl}
% The soft path itself.
% \begin{macrocode}
\tl_new:N \g_@@_softpath_main_tl
-\tl_new:N \g_@@_softpath_buffer_a_tl
-\tl_new:N \g_@@_softpath_buffer_b_tl
% \end{macrocode}
% \end{variable}
%
-% \begin{variable}
-% {
-% \g_@@_softpath_buffer_a_int ,
-% \g_@@_softpath_buffer_b_int
-% }
-% Tracking data.
+% \begin{variable}{\l_@@_softpath_internal_tl}
+% The soft path itself.
% \begin{macrocode}
-\int_new:N \g_@@_softpath_buffer_a_int
-\int_new:N \g_@@_softpath_buffer_b_int
+\tl_new:N \l_@@_softpath_internal_tl
% \end{macrocode}
% \end{variable}
%
@@ -109,60 +94,13 @@
% \end{macrocode}
% \end{variable}
%
-% \begin{macro}{\@@_softpath_add:n, \@@_softpath_add:x}
-% \begin{macro}{\@@_softpath_concat:n}
-% \begin{macro}{\@@_softpath_reset_buffers:}
-% The softpath itself is quite simple. We use three token lists to hold the
-% data: two buffers of limited length, and the main list of arbitrary size.
-% Most of the time this will mean that we don't add to the full list, so
-% performance will be acceptable.
+% \begin{macro}{\@@_softpath_add:n, \@@_softpath_add:o, \@@_softpath_add:x}
% \begin{macrocode}
-\cs_new_protected:Npn \@@_softpath_add:n #1
- {
- \int_compare:nNnTF \g_@@_softpath_buffer_a_int < { 40 }
- {
- \int_gincr:N \g_@@_softpath_buffer_a_int
- \tl_gput_right:Nn \g_@@_softpath_buffer_a_tl {#1}
- }
- {
- \int_compare:nNnTF \g_@@_softpath_buffer_b_int < { 40 }
- {
- \int_gincr:N \g_@@_softpath_buffer_b_int
- \tl_gset:Nx \g_@@_softpath_buffer_b_tl
- {
- \exp_not:V \g_@@_softpath_buffer_b_tl
- \exp_not:V \g_@@_softpath_buffer_a_tl
- \exp_not:n {#1}
- }
- \int_gzero:N \g_@@_softpath_buffer_a_int
- \tl_gclear:N \g_@@_softpath_buffer_a_tl
- }
- { \@@_softpath_concat:n {#1} }
- }
- }
-\cs_generate_variant:Nn \@@_softpath_add:n { x }
-\cs_new_protected:Npn \@@_softpath_concat:n #1
- {
- \tl_gset:Nx \g_@@_softpath_main_tl
- {
- \exp_not:V \g_@@_softpath_main_tl
- \exp_not:V \g_@@_softpath_buffer_b_tl
- \exp_not:V \g_@@_softpath_buffer_a_tl
- \exp_not:n {#1}
- }
- \@@_softpath_reset_buffers:
- }
-\cs_new_protected:Npn \@@_softpath_reset_buffers:
- {
- \int_gzero:N \g_@@_softpath_buffer_a_int
- \tl_gclear:N \g_@@_softpath_buffer_a_tl
- \int_gzero:N \g_@@_softpath_buffer_b_int
- \tl_gclear:N \g_@@_softpath_buffer_b_tl
- }
+\cs_new_protected:Npn \@@_softpath_add:n
+ { \tl_build_gput_right:Nn \g_@@_softpath_main_tl }
+\cs_generate_variant:Nn \@@_softpath_add:n { o, x }
% \end{macrocode}
% \end{macro}
-% \end{macro}
-% \end{macro}
%
% \begin{macro}
% {\@@_softpath_use:, \@@_softpath_clear:, \@@_softpath_use_clear:}
@@ -170,15 +108,12 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_softpath_use:
{
- \g_@@_softpath_main_tl
- \g_@@_softpath_buffer_b_tl
- \g_@@_softpath_buffer_a_tl
+ \tl_build_get:NN \g_@@_softpath_main_tl \l_@@_softpath_internal_tl
+ \l_@@_softpath_internal_tl
}
\cs_new_protected:Npn \@@_softpath_clear:
{
- \tl_gclear:N \g_@@_softpath_main_tl
- \tl_gclear:N \g_@@_softpath_buffer_a_tl
- \tl_gclear:N \g_@@_softpath_buffer_b_tl
+ \tl_build_gclear:N \g_@@_softpath_main_tl
\bool_gset_false:N \g_@@_softpath_corners_bool
}
\cs_new_protected:Npn \@@_softpath_use_clear:
@@ -391,9 +326,9 @@
\fp_zero:N \l_@@_softpath_lasty_fp
\tl_clear:N \l_@@_softpath_first_tl
\tl_clear:N \l_@@_softpath_move_tl
- \@@_softpath_concat:n { }
+ \tl_build_get:NN \g_@@_softpath_main_tl \l_@@_softpath_internal_tl
\exp_after:wN \@@_softpath_round_loop:Nnn
- \g_@@_softpath_main_tl
+ \l_@@_softpath_internal_tl
\q_recursion_tail ? ?
\q_recursion_stop
\group_end:
@@ -653,7 +588,8 @@
\l_@@_softpath_move_tl
\tl_put_right:No \l_@@_softpath_main_tl
\l_@@_softpath_part_tl
- \tl_gset_eq:NN \g_@@_softpath_main_tl \l_@@_softpath_main_tl
+ \tl_build_gclear:N \g_@@_softpath_main_tl
+ \@@_softpath_add:o \l_@@_softpath_main_tl
}
% \end{macrocode}
% \end{macro}
diff --git a/l3experimental/l3draw/testfiles/m3draw000.tlg b/l3experimental/l3draw/testfiles/m3draw000.tlg
index 1d85788..c3d7d3b 100644
--- a/l3experimental/l3draw/testfiles/m3draw000.tlg
+++ b/l3experimental/l3draw/testfiles/m3draw000.tlg
@@ -38,8 +38,6 @@ Author: Joseph Wright
\l__draw_xmin_dim=\dimen...
\l__draw_ymax_dim=\dimen...
\l__draw_ymin_dim=\dimen...
-\g__draw_softpath_buffer_a_int=\count...
-\g__draw_softpath_buffer_b_int=\count...
\g__draw_softpath_lastx_dim=\dimen...
\g__draw_softpath_lasty_dim=\dimen...
\l__draw_softpath_corneri_dim=\dimen...
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 85d369e..c96a892 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -1091,6 +1091,16 @@
% and global \meta{tl~var} respectively.
% \end{function}
%
+% \begin{function}[added = 2018-04-01]{\tl_build_clear:N, \tl_build_gclear:N}
+% \begin{syntax}
+% \cs{tl_build_clear:N} \meta{tl~var}
+% \end{syntax}
+% Clears the \meta{tl~var} and sets it up to support other
+% \cs[no-index]{tl_build_\ldots{}} functions. The |clear| and
+% |gclear| functions must be used for local and global \meta{tl~var}
+% respectively.
+% \end{function}
+%
% \begin{function}[added = 2018-04-01]
% {
% \tl_build_put_left:Nn, \tl_build_put_left:Nx,
@@ -4199,6 +4209,19 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}{\tl_build_clear:N, \tl_build_gclear:N}
+% The |begin| and |gbegin| functions already clear enough to make the
+% token list variable effectively empty. Eventually the |begin| and
+% |gbegin| functions should check that |#1'| is empty or undefined,
+% while the |clear| and |gclear| functions ought to empty |#1'|,
+% |#1''| and so on, similar to \cs{tl_build_end:N}. This only affects
+% memory usage.
+% \begin{macrocode}
+\cs_new_eq:NN \tl_build_clear:N \tl_build_begin:N
+\cs_new_eq:NN \tl_build_gclear:N \tl_build_gbegin:N
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}
% {
% \tl_build_put_right:Nn, \tl_build_put_right:Nx,
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 51e0d2a..4009e63 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -5953,6 +5953,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 222788f..8c09301 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5893,6 +5893,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 88ee4ed..a0e6ec6 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -6094,6 +6094,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 755856a..0bbf153 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -6092,6 +6092,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 2ac06d1..9e65c6d 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5926,6 +5926,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 51e0d2a..4009e63 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -5953,6 +5953,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 222788f..8c09301 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5893,6 +5893,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 88ee4ed..a0e6ec6 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -6094,6 +6094,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 755856a..0bbf153 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -6092,6 +6092,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 2ac06d1..9e65c6d 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5926,6 +5926,8 @@ Defining \tl_build_begin:N on line ...
Defining \tl_build_gbegin:N on line ...
Defining \__tl_build_begin:NN on line ...
Defining \__tl_build_begin:NNN on line ...
+Defining \tl_build_clear:N on line ...
+Defining \tl_build_gclear:N on line ...
Defining \tl_build_put_right:Nn on line ...
Defining \tl_build_put_right:Nx on line ...
Defining \tl_build_gput_right:Nn on line ...
More information about the latex3-commits
mailing list