[latex3-commits] [latex3/latex3] main: Speed up `\str_set:Nn` and friends (7ed7d4ffd)

github at latex-project.org github at latex-project.org
Sun Nov 26 21:51:43 CET 2023


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

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

commit 7ed7d4ffd702717383b3a2a5aae54c3e75c867f8
Author: Yukai Chou <muzimuzhi at gmail.com>
Date:   Sat Nov 25 07:46:25 2023 +0800

    Speed up `\str_set:Nn` and friends
    
    Full list is `\str_(g)set:Nn`, `\str_const:Nn`, `\str_(g)put_left:Nn`,
    and `\str_(g)put_right:Nn`.


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

7ed7d4ffd702717383b3a2a5aae54c3e75c867f8
 l3kernel/CHANGELOG.md |  4 +++
 l3kernel/l3str.dtx    | 72 ++++++++++++++++++++++++++++++---------------------
 2 files changed, 46 insertions(+), 30 deletions(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 9593f3a09..b0fbddca0 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -18,6 +18,10 @@ this project uses date-based 'snapshot' version identifiers.
 - Documentation for `\c_nan_fp`
 - `\str_case_e:en(TF)`
 
+### Changes
+- Speed up `\str_(g)set:Nn`, `\str_const:Nn`, `\str_(g)put_left:Nn`,
+  and `\str_(g)put_right:Nn`
+
 ### Fixed
 - Normalisation of `.inherit:n` key data (issue \#1314)
 
diff --git a/l3kernel/l3str.dtx b/l3kernel/l3str.dtx
index 5dfc05bde..ceea8bfd7 100644
--- a/l3kernel/l3str.dtx
+++ b/l3kernel/l3str.dtx
@@ -106,7 +106,7 @@
 %   initially empty.
 % \end{function}
 %
-% \begin{function}[added = 2015-09-18, updated = 2018-07-28]
+% \begin{function}[added = 2015-09-18, updated = 2023-11-25]
 %   {
 %     \str_const:Nn, \str_const:NV, \str_const:Ne,
 %     \str_const:cn, \str_const:cV, \str_const:ce
@@ -176,7 +176,7 @@
 %
 % \section{Adding data to string variables}
 %
-% \begin{function}[added = 2015-09-18, updated = 2018-07-28]
+% \begin{function}[added = 2015-09-18, updated = 2023-11-25]
 %   {
 %     \str_set:Nn,  \str_set:NV, \str_set:Ne,
 %     \str_set:cn,  \str_set:cV, \str_set:ce,
@@ -190,7 +190,7 @@
 %   result in \meta{str var}.
 % \end{function}
 %
-% \begin{function}[added = 2015-09-18, updated = 2018-07-28]
+% \begin{function}[added = 2015-09-18, updated = 2023-11-25]
 %   {
 %     \str_put_left:Nn, \str_put_left:NV, \str_put_left:Ne,
 %     \str_put_left:cn, \str_put_left:cV, \str_put_left:ce,
@@ -205,7 +205,7 @@
 %     var} are not automatically converted to a string.
 % \end{function}
 %
-% \begin{function}[added = 2015-09-18, updated = 2018-07-28]
+% \begin{function}[added = 2015-09-18, updated = 2023-11-25]
 %   {
 %     \str_put_right:Nn, \str_put_right:NV, \str_put_right:Ne,
 %     \str_put_right:cn, \str_put_right:cV, \str_put_right:Ne,
@@ -979,33 +979,45 @@
 %     \str_gput_right:Nn, \str_gput_right:NV, \str_gput_right:Ne, \str_gput_right:Nx,
 %     \str_gput_right:cn, \str_gput_right:cV, \str_gput_right:ce, \str_gput_right:cx
 %   }
-%   Simply convert the token list inputs to \meta{strings}.
+%   Similar to corresponding \pkg{l3tl} base functions, except that
+%   \cs{__kernel_exp_not:w} is replaced with \cs{__kernel_tl_to_str:w}.
 %    \begin{macrocode}
-\group_begin:
-  \cs_set_protected:Npn \@@_tmp:n #1
-    {
-      \tl_if_blank:nF {#1}
-        {
-          \cs_new_protected:cpe { str_ #1 :Nn } ##1##2
-            {
-              \exp_not:c { tl_ #1 :Ne } ##1
-                { \exp_not:N \tl_to_str:n {##2} }
-            }
-          \cs_generate_variant:cn { str_ #1 :Nn }
-            { NV , Ne , Nx , cn , cV , ce , cx }
-          \@@_tmp:n
-        }
-    }
-  \@@_tmp:n
-    { set }
-    { gset }
-    { const }
-    { put_left }
-    { gput_left }
-    { put_right }
-    { gput_right }
-    { }
-\group_end:
+\cs_new_protected:Npn \str_set:Nn #1#2
+  { \__kernel_tl_set:Ne #1 { \__kernel_tl_to_str:w {#2} } }
+\cs_gset_protected:Npn \str_gset:Nn #1#2
+  { \__kernel_tl_gset:Ne #1 { \__kernel_tl_to_str:w {#2} } }
+\cs_new_protected:Npn \str_const:Nn #1#2
+  {
+    \__kernel_chk_if_free_cs:N #1
+    \cs_gset_nopar:Npe #1 { \__kernel_tl_to_str:w {#2} }
+  }
+\cs_new_protected:Npn \str_put_left:Nn #1#2
+  {
+    \__kernel_tl_set:Ne #1
+      { \__kernel_tl_to_str:w {#2} \__kernel_exp_not:w \exp_after:wN {#1} }
+  }
+\cs_new_protected:Npn \str_gput_left:Nn #1#2
+  {
+    \__kernel_tl_gset:Ne #1
+      { \__kernel_tl_to_str:w {#2} \__kernel_exp_not:w \exp_after:wN {#1} }
+  }
+\cs_new_protected:Npn \str_put_right:Nn #1#2
+  {
+    \__kernel_tl_set:Ne #1
+      { \__kernel_exp_not:w \exp_after:wN {#1} \__kernel_tl_to_str:w {#2} }
+  }
+\cs_new_protected:Npn \str_gput_right:Nn #1#2
+  {
+    \__kernel_tl_gset:Ne #1
+      { \__kernel_exp_not:w \exp_after:wN {#1} \__kernel_tl_to_str:w {#2} }
+  }
+\cs_generate_variant:Nn \str_set:Nn        { NV , Ne , Nx , c , cV , ce , cx }
+\cs_generate_variant:Nn \str_gset:Nn       { NV , Ne , Nx , c , cV , ce , cx }
+\cs_generate_variant:Nn \str_const:Nn      { NV , Ne , Nx , c , cV , ce , cx }
+\cs_generate_variant:Nn \str_put_left:Nn   { NV , Ne , Nx , c , cV , ce , cx }
+\cs_generate_variant:Nn \str_gput_left:Nn  { NV , Ne , Nx , c , cV , ce , cx }
+\cs_generate_variant:Nn \str_put_right:Nn  { NV , Ne , Nx , c , cV , ce , cx }
+\cs_generate_variant:Nn \str_gput_right:Nn { NV , Ne , Nx , c , cV , ce , cx }
 %    \end{macrocode}
 % \end{macro}
 %





More information about the latex3-commits mailing list.