[latex3-commits] [git/LaTeX3-latex3-latex3] main: Precompile key settings (0a59d38dc)
GitHub
noreply at github.com
Fri Mar 4 14:44:08 CET 2022
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/0a59d38dc01e06713795d9ee09a26a7357396714
>---------------------------------------------------------------
commit 0a59d38dc01e06713795d9ee09a26a7357396714
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Fri Mar 4 13:44:08 2022 +0000
Precompile key settings
>---------------------------------------------------------------
0a59d38dc01e06713795d9ee09a26a7357396714
l3kernel/CHANGELOG.md | 4 ++
l3kernel/l3debug.dtx | 2 +-
l3kernel/l3keys.dtx | 74 +++++++++++++++++++---
l3kernel/testfiles/m3keys004.tlg | 6 +-
l3kernel/testfiles/m3keys008.lvt | 106 ++++++++++++++++++++++++++++++++
l3kernel/testfiles/m3keys008.tlg | 32 ++++++++++
l3kernel/testfiles/m3show002.luatex.tlg | 6 +-
l3kernel/testfiles/m3show002.tlg | 6 +-
l3kernel/testfiles/m3show003.tlg | 6 +-
9 files changed, 224 insertions(+), 18 deletions(-)
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index ba245c3c9..d3c297a0b 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -7,6 +7,10 @@ this project uses date-based 'snapshot' version identifiers.
## [Unreleased]
+### Added
+- `\keys_precompile:Nnn` for conversion of keyvals to fast-to-apply token
+ lists
+
## [2022-02-24]
### Changed
diff --git a/l3kernel/l3debug.dtx b/l3kernel/l3debug.dtx
index 81d3d81c4..bf0058223 100644
--- a/l3kernel/l3debug.dtx
+++ b/l3kernel/l3debug.dtx
@@ -1015,7 +1015,7 @@
{ \__kernel_debug_log:x { Defining~key~#1~\msg_line_context: } }
}
{ }
- { \@@_cmd_set:nn }
+ { \@@_cmd_set_direct:nn }
%<@@=msg>
\__kernel_patch:nnn
{ }
diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index 360a00899..f48b9e9b5 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -882,6 +882,18 @@
% group and are thus never set.
% \end{function}
%
+% \section{Digesting keys}
+%
+% \begin{function}[added = 2022-03-04]{\keys_precompile:Nnn}
+% \begin{syntax}
+% \cs{keys_precompile:Nnn} \meta{tl} \Arg{module} \Arg{keyval list}
+% \end{syntax}
+% Parses the \meta{keyval list} as for \cs{keys_set:nn}, placing the
+% resulting code for those which set variables or functions into the
+% \meta{tl}. Thus this function \enquote{precompiles} the keyval list into
+% a set of results which can be applied rapidly.
+% \end{function}
+%
% \section{Utility functions for keys}
%
% \begin{function}[EXP, pTF, updated = 2022-01-10]
@@ -1661,6 +1673,14 @@
% \end{macrocode}
% \end{variable}
%
+% \begin{variable}{\l_@@_precompile_bool, \l_@@_precompile_tl}
+% For digesting keys.
+% \begin{macrocode}
+\bool_new:N \l_@@_precompile_bool
+\tl_new:N \l_@@_precompile_tl
+% \end{macrocode}
+% \end{variable}
+%
% \begin{variable}{\l_keys_usage_load_prop, \l_keys_usage_preamble_prop}
% Global data for document-level information.
% \begin{macrocode}
@@ -1866,7 +1886,7 @@
{ \exp_not:c { bool_ #2 set_ #3 :N } \exp_not:N #1 }
\@@_cmd_set:nx { \l_keys_path_str / false }
{ \exp_not:c { bool_ #2 set_ #4 :N } \exp_not:N #1 }
- \@@_cmd_set:nn { \l_keys_path_str / unknown }
+ \@@_cmd_set_direct:nn { \l_keys_path_str / unknown }
{
\msg_error:nnx { keys } { boolean-values-only }
\l_keys_key_str
@@ -1909,8 +1929,8 @@
{
\cs_set_nopar:cpn { \c_@@_type_root_str \l_keys_path_str }
{ choice }
- \@@_cmd_set:nn \l_keys_path_str { #1 {##1} }
- \@@_cmd_set:nn { \l_keys_path_str / unknown }
+ \@@_cmd_set_direct:nn \l_keys_path_str { #1 {##1} }
+ \@@_cmd_set_direct:nn { \l_keys_path_str / unknown }
{
\msg_error:nnxx { keys } { choice-unknown }
\l_keys_path_str {##1}
@@ -1952,13 +1972,26 @@
% \end{macro}
%
% \begin{macro}
-% {\@@_cmd_set:nn, \@@_cmd_set:nx, \@@_cmd_set:Vn, \@@_cmd_set:Vo}
+% {
+% \@@_cmd_set:nn, \@@_cmd_set:nx, \@@_cmd_set:Vn, \@@_cmd_set:Vo,
+% \@@_cmd_set_direct:nn
+% }
% Setting the code for a key first logs if appropriate that we are
% defining a new key, then saves the code.
% \begin{macrocode}
\cs_new_protected:Npn \@@_cmd_set:nn #1#2
- { \cs_set_protected:cpn { \c_@@_code_root_str #1 } ##1 {#2} }
+ {
+ \@@_cmd_set_direct:nn {#1}
+ {
+ \bool_if:NTF \l_@@_precompile_bool
+ { \tl_put_right:Nn \l_@@_precompile_tl }
+ { \use:n }
+ {#2}
+ }
+ }
\cs_generate_variant:Nn \@@_cmd_set:nn { nx , Vn , Vo }
+\cs_new_protected:Npn \@@_cmd_set_direct:nn #1#2
+ { \cs_set_protected:cpn { \c_@@_code_root_str #1 } ##1 {#2} }
% \end{macrocode}
% \end{macro}
%
@@ -1970,7 +2003,12 @@
\cs_new_protected:Npn \@@_cs_set:NNpn #1#2#3#
{
\cs_set_protected:cpx { \c_@@_code_root_str \l_keys_path_str } ##1
- { #1 \exp_not:N #2 \exp_not:n {#3} {##1} }
+ {
+ \exp_not:N \bool_if:NTF \exp_not:N \l_@@_precompile_bool
+ { \tl_put_right:Nn \exp_not:N \l_@@_precompile_tl }
+ { \exp_not:N \use:n }
+ { #1 \exp_not:N #2 \exp_not:n {#3} {##1} }
+ }
\use_none:n
}
\cs_generate_variant:Nn \@@_cs_set:NNpn { Nc }
@@ -2089,13 +2127,17 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_meta_make:n #1
{
- \@@_cmd_set:Vo \l_keys_path_str
+ \exp_args:NVo \@@_cmd_set_direct:nn \l_keys_path_str
{
- \exp_after:wN \keys_set:nn \exp_after:wN { \l_@@_module_str } {#1}
+ \exp_after:wN \keys_set:nn \exp_after:wN
+ { \l_@@_module_str } {#1}
}
}
\cs_new_protected:Npn \@@_meta_make:nn #1#2
- { \@@_cmd_set:Vn \l_keys_path_str { \keys_set:nn {#1} {#2} } }
+ {
+ \exp_args:NV \@@_cmd_set_direct:nn
+ \l_keys_path_str { \keys_set:nn {#1} {#2} }
+ }
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -2895,6 +2937,20 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}{\keys_precompile:Nnn}
+% A simple wrapper.
+% \begin{macrocode}
+\cs_new_protected:Npn \keys_precompile:Nnn #1#2#3
+ {
+ \bool_set_true:N \l_@@_precompile_bool
+ \tl_clear:N \l_@@_precompile_tl
+ \keys_set:nn {#2} {#3}
+ \bool_set_false:N \l_@@_precompile_bool
+ \tl_set_eq:NN #1 \l_@@_precompile_tl
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\@@_set_keyval:n, \@@_set_keyval:nn}
% \begin{macro}{\@@_set_keyval:nnn, \@@_set_keyval:onn}
% \begin{macro}{\@@_find_key_module:wNN}
diff --git a/l3kernel/testfiles/m3keys004.tlg b/l3kernel/testfiles/m3keys004.tlg
index ab1a45c19..7e72fdebc 100644
--- a/l3kernel/testfiles/m3keys004.tlg
+++ b/l3kernel/testfiles/m3keys004.tlg
@@ -187,11 +187,13 @@ FALSE
TEST 11: \keys_show:nn
============================================================
The key module/key-one has the properties:
-> code => \TYPE {"#1"}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\TYPE {"#1"}}.
<recently read> }
l. ... }
The key module/key-two has the properties:
-> code => \tl_set:Nn \l_tmpa_tl {#1}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\tl_set:Nn \l_tmpa_tl {#1}}.
<recently read> }
l. ... }
The key module/key-three is undefined.
diff --git a/l3kernel/testfiles/m3keys008.lvt b/l3kernel/testfiles/m3keys008.lvt
new file mode 100644
index 000000000..496cf9531
--- /dev/null
+++ b/l3kernel/testfiles/m3keys008.lvt
@@ -0,0 +1,106 @@
+% Copyright (C) 2022 The LaTeX Project
+
+
+\documentclass{minimal}
+\input{regression-test}
+
+\RequirePackage[enable-debug]{expl3}
+\ExplSyntaxOn
+\debug_on:n { check-declarations , deprecation , log-functions }
+\ExplSyntaxOff
+
+
+\begin{document}
+\START
+\AUTHOR{Joseph Wright}
+\ExplSyntaxOn
+
+\TEST { Key~precompilation~of~settings }
+ {
+ \OMIT
+ \keys_define:nn { test }
+ {
+ key-one .bool_set_inverse:N = \l_tmpa_bool ,
+ key-two .clist_set:N = \l_tmpa_clist ,
+ key-three .code:n = #1 ,
+ key-four .cs_set:Np = \foo #1#2 ,
+ key-five .dim_set:N = \l_tmpa_dim ,
+ key-six .fp_set:N = \l_tmpa_fp ,
+ key-seven .int_set:N = \l_tmpa_int ,
+ key-eight .muskip_set:N = \l_tmpa_muskip ,
+ key-nine .skip_set:N = \l_tmpa_skip ,
+ key-ten .str_set:N = \l_tmpa_str ,
+ key-eleven .tl_set:N = \l_tmpa_tl ,
+ key-twelve .tl_set_x:N = \l_tmpb_tl
+ }
+ \TIMO
+ \keys_precompile:Nnn
+ \l_tmpa_tl
+ { test }
+ {
+ key-one = true ,
+ key-two = { a , b } ,
+ key-three = foo ,
+ key-four = #1:#2 ,
+ key-five = 0.3pt ,
+ key-six = 2 * 0.3 ,
+ key-seven = 123 ,
+ key-eight = 0.4mu ,
+ key-nine = 0.66pt ,
+ key-ten = foo ,
+ key-eleven = footoo ,
+ key-twelve = \l_tmpa_tl
+ }
+ \tl_show:N \l_tmpa_tl
+ }
+
+\TEST { Precompiling~choices }
+ {
+ \OMIT
+ \keys_define:nn { test }
+ {
+ key-one .choice: ,
+ key-one / choice-one .code:n = AAAA ,
+ key-one / choice-two .code:n = BBBB ,
+ key-one / choice-three .code:n = CCCC ,
+ key-one / choice-four .code:n = DDDD ,
+ key-two .choice: ,
+ key-two / choice-one .code:n = AAAA ,
+ key-two / choice-two .code:n = BBBB ,
+ key-two / choice-three .code:n = CCCC ,
+ key-two / choice-four .code:n = DDDD ,
+ key-three .choices:nn =
+ { choice-one , choice-two , choice-three , choice-four }
+ {#1}
+ }
+ \TIMO
+ \keys_precompile:Nnn
+ \l_tmpa_tl
+ { test }
+ {
+ key-one = choice-one , key-one = choice-three ,
+ key-two = choice-one , key-two = choice-three ,
+ key-three = choice-one , key-three = choice-three
+ }
+ \tl_show:N \l_tmpa_tl
+ }
+
+\TEST { Precompiling~meta~keys }
+ {
+ \OMIT
+ \keys_define:nn { test }
+ {
+ key-one .code:n = #1 ,
+ key-two .meta:n = {key-one = "#1"}
+ }
+ \TIMO
+ \keys_precompile:Nnn
+ \l_tmpa_tl
+ { test }
+ {
+ key-one = AAA, key-two = BBB
+ }
+ \tl_show:N \l_tmpa_tl
+ }
+
+\END
\ No newline at end of file
diff --git a/l3kernel/testfiles/m3keys008.tlg b/l3kernel/testfiles/m3keys008.tlg
new file mode 100644
index 000000000..fc76f6098
--- /dev/null
+++ b/l3kernel/testfiles/m3keys008.tlg
@@ -0,0 +1,32 @@
+This is a generated file for the LaTeX (2e + expl3) validation system.
+Don't change this file in any respect.
+Author: Joseph Wright
+============================================================
+TEST 1: Key precompilation of settings
+============================================================
+> \l_tmpa_tl=\bool_set_false:N \l_tmpa_bool \clist_set:Nn \l_tmpa_clist
+{a,b}foo\cs_set:Npn \foo ##1##2{##1:##2}\dim_set:Nn \l_tmpa_dim
+{0.3pt}\fp_set:Nn \l_tmpa_fp {2*0.3}\int_set:Nn \l_tmpa_int
+{123}\muskip_set:Nn \l_tmpa_muskip {0.4mu}\skip_set:Nn \l_tmpa_skip
+{0.66pt}\str_set:Nn \l_tmpa_str {foo}\tl_set:Nn \l_tmpa_tl {footoo}\tl_set:Nx
+\l_tmpb_tl {\l_tmpa_tl }.
+<recently read> }
+l. ... }
+============================================================
+============================================================
+TEST 2: Precompiling choices
+============================================================
+> \l_tmpa_tl=AAAACCCCAAAACCCC\tl_set:Nn \l_keys_choice_tl
+{choice-one}\int_set:Nn \l_keys_choice_int {1}choice-one\tl_set:Nn
+\l_keys_choice_tl {choice-three}\int_set:Nn \l_keys_choice_int
+{3}choice-three.
+<recently read> }
+l. ... }
+============================================================
+============================================================
+TEST 3: Precompiling meta keys
+============================================================
+> \l_tmpa_tl=AAA"BBB".
+<recently read> }
+l. ... }
+============================================================
diff --git a/l3kernel/testfiles/m3show002.luatex.tlg b/l3kernel/testfiles/m3show002.luatex.tlg
index 50d79103b..91edd50bd 100644
--- a/l3kernel/testfiles/m3show002.luatex.tlg
+++ b/l3kernel/testfiles/m3show002.luatex.tlg
@@ -177,9 +177,11 @@ l. ... }
TEST 7: KEYS
============================================================
The key test/text has the properties:
-> code => \tl_set:Nn \l_tmpa_tl {#1}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\tl_set:Nn \l_tmpa_tl {#1}}.
The key test/expanded has the properties:
-> code => \tl_gset:Nx \l_tmpb_tl {#1}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\tl_gset:Nx \l_tmpb_tl {#1}}.
============================================================
============================================================
TEST 8: CHAR
diff --git a/l3kernel/testfiles/m3show002.tlg b/l3kernel/testfiles/m3show002.tlg
index 3c217bc1d..ea37f9307 100644
--- a/l3kernel/testfiles/m3show002.tlg
+++ b/l3kernel/testfiles/m3show002.tlg
@@ -177,9 +177,11 @@ l. ... }
TEST 7: KEYS
============================================================
The key test/text has the properties:
-> code => \tl_set:Nn \l_tmpa_tl {#1}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\tl_set:Nn \l_tmpa_tl {#1}}.
The key test/expanded has the properties:
-> code => \tl_gset:Nx \l_tmpb_tl {#1}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\tl_gset:Nx \l_tmpb_tl {#1}}.
============================================================
============================================================
TEST 8: CHAR
diff --git a/l3kernel/testfiles/m3show003.tlg b/l3kernel/testfiles/m3show003.tlg
index 36e5ffab2..3a5764da6 100644
--- a/l3kernel/testfiles/m3show003.tlg
+++ b/l3kernel/testfiles/m3show003.tlg
@@ -156,9 +156,11 @@ The following output streams are in use:
TEST 9: keys
============================================================
The key test/text has the properties:
-> code => \tl_set:Nn \l_tmpa_tl {#1}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\tl_set:Nn \l_tmpa_tl {#1}}.
The key test/expanded has the properties:
-> code => \tl_gset:Nx \l_tmpb_tl {#1}.
+> code => \bool_if:NTF \l__keys_digest_bool {\tl_put_right:Nn
+\l__keys_digest_tl }{\use:n }{\tl_gset:Nx \l_tmpb_tl {#1}}.
============================================================
============================================================
TEST 10: muskip
More information about the latex3-commits
mailing list.