zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Example / partial fix for printf with math expressions
Date: Sun, 25 Feb 2024 16:04:34 -0800	[thread overview]
Message-ID: <CAH+w=7bZBQNvft8cqQ7CahMsF9=cMGEYTbpfLOidQH=4kc5HeA@mail.gmail.com> (raw)
In-Reply-To: <20240225065400.wrb3jxr7vub6t42v@chazelas.org>

On Sat, Feb 24, 2024 at 10:54 PM Stephane Chazelas
<stephane@chazelas.org> wrote:
>
> 2024-02-24 14:40:41 +0000, Stephane Chazelas:
> [...]
> > +                     zlongval = (curarg) ? mathevali(metafy(curarg, curlen, META_HEAPDUP)) : 0;
>
> That incur a performance penalty:
>
> The numbers end up being metafied (earlier), unmetafied by
> printf, metafied again by printf here and that metafication
> processed by the math handler I guess.

The reason this went unobserved for so long is that metafication only
matters to a couple of things in math:
1) proper handling of parameter references, like your a[x]++ example
2) those pesky error messages that started this whole thread

As far as I can tell there are no other circumstances in which
metafication is necessary for the syntax of math expressions.

> Maybe the performance could be *improved* instead if the
> unmetafication could be skipped altogether in printf in those
> cases?

That's certainly possible, but it would mean that every branch of the
big "case" statements for %-replacement would have to do their own
unmetafy(), rather than a single loop at the top covering the entire
argv array.  The -s/-S/-z options also reverse the unmetafy(), so some
heavy refactoring of bin_print() is needed to unroll this completely.

However, I think you could change META_HEAPDUP and META_USEHEAP to
META_NOALLOC, becuase you're re-metafying back into the same space
that was originally unmetafied?  That might cut the performance
penalty a lot.


  reply	other threads:[~2024-02-26  0:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-23 23:23 Bart Schaefer
2024-02-24 14:40 ` Stephane Chazelas
2024-02-24 15:10   ` Stephane Chazelas
2024-02-24 21:51   ` Bart Schaefer
2024-02-25  6:54   ` Stephane Chazelas
2024-02-26  0:04     ` Bart Schaefer [this message]
2024-02-26 17:12       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bZBQNvft8cqQ7CahMsF9=cMGEYTbpfLOidQH=4kc5HeA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).