Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: A way to untie -T vars?



On Sat, Jan 21, 2023 at 6:32 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Sat, Jan 21, 2023 at 8:38 AM Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
> >
> > I'm using -U flag to quickly uniquify the scalar, however this method is problematic as the array vars are left over.
>
> Oh, now I see what you mean.  You're adding an array with typeset -T
> so that -U will remove duplicates from the scalar, but then you want
> only the scalar to be left at the end -- the array is just a vehicle
> for the "uniqueness" semantics.
>
> Is using a tied array really that much faster than VAR=${(us.:.)VAR} ?

A quick test shows that VAR=${(j.:.)${(us.:.)VAR}} is slightly faster
than `typeset -T VAR _VAR`. I could see it going either way depending
on the value and what exactly is being benchmarked, but the ballpark
performance should be the same.

Roman.




Messages sorted by: Reverse Date, Date, Thread, Author