[latex3-commits] [git/LaTeX3-latex3-latex2e] apdf161: Simplify a bit \@@_make_name:n (e6a1a69e)

Bruno Le Floch blflatex at gmail.com
Wed Sep 9 16:48:07 CEST 2020


On 9/9/20 3:57 PM, PhelypeOleinik wrote:
>      \exp_after:wN \exp_after:wN \exp_after:wN \@@_make_name:w
> -    \exp_after:wN \token_to_str:N \cs:w g@@ ~ #1 \cs_end:
> +    \exp_after:wN \token_to_str:N \cs:w @@~ #1 \cs_end:

Good.  So my previous email is moot.

>    }
> -\cs_new:Npn \@@_make_name:w #1#2 ~ { }
> +\exp_last_unbraced:NNNNo
> +\cs_new:Npn \@@_make_name:w #1 \tl_to_str:n { @@~ } { }

Indeed, that makes \@@_make_name:w slightly faster I believe (fewer args to copy
around in memory).

>  %    \end{macrocode}
>  % \end{macro}
>  %
> @@ -2678,8 +2681,8 @@
>      \hook_if_exist:nT {#1}
>        {
>          \prop_if_empty:cTF {g_@@_#1_code_prop}
> -          { \tl_gset:co {@@~#1}
> -                        {\cs:w g_@@_#1_code_next_tl \cs_end: } }
> +          { \tl_gset:co { @@~#1 }
> +                        { \cs:w g_@@_#1_code_next_tl \cs_end: } }

I wonder if it would be nicer to call it \cs:w @@_next~#1 \cs_end: to match the
@@~#1 (note I was careful to avoid name clashes, you cannot do @@~next_#1 or
similar).


> -\cs_new:Npn \@@_use_undefined:w #1 #2 \use:n #3 #4 \cs_end:
> +\cs_new:Npn \@@_use_undefined:w #1 #2 @@~#3 \cs_end:

Unsafe.  The \use:n was there so that a \cs_end: inside the hook name wouldn't
mark the end of the argument of \@@_use_undefined:w.  One safe and fast option
would be

\cs_new_eq:NN \@@_use_end: \cs_end:

and use \@@_use_end: as the end-marker.  It looks odd in the code but at least
is safe and avoids the ugly \use:n.

Alternatively, if we want maximum speed for the case where the hook exists, we
could accept to always turn the cs to \relax, something like

\cs_new:Npn \@@_use_initialized:n #1
  { \exp_after:wN \@@_use_initialized:N \cs:w @@ ~ #1 \cs_end: }
\cs_new:Npn \@@_use_initialized:N #1
  {
    \if_meaning:w \scan_stop: #1
      \@@_use_undefined:w
    \fi:
    #1
  }
\cs_new:Npn \@@_use_undefined:w #1#2
  {
    #1
    \exp_after:wN \@@_use_undefined_aux:w
    \token_to_str:N #2 \scan_stop:
  }
\cs_new:Npn \@@_use_undefined_aux:w #1 @@~ #2 \scan_stop: { ... }

Ok, it's really ugly, I don't like it.  But it should be a bit faster since it
avoids making the cs from its csname twice, and manipulates fewer tokens as a
result.

Bruno



More information about the latex3-commits mailing list.