Subject: Re: fpath+="${(u)fpath[@]}" can hog system
From: Bart Schaefer <[email-masked]>
To: Zsh hackers list <[email-masked]>
Date: Wed, 27 Jan 2016 14:50:41 -0800
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Jan 27, 10:36am, Sebastian Gniazdowski wrote:
}
} repeat 20; do fpath+="${(u)fpath[@]}"; done

Why would you do that?  What's the intended result?

Appending a string to an array creates a single new array element; it
doesn't matter that you've used [@] inside the double quotes, you are
still appending a new single element to the array every time.  Since
the new element consists of all the previous elements joined, it is
always unique and (u) will never filter out anything.

And then all of that will be duplicated as a single colon-separated
string in $FPATH.

Yeah, if you increase the size (in bytes) of $fpath by 20! (factorial),
and then make a copy of that, you are going to consume a buttload of
resources.

If what you mean is to append new elements to the array, you want array
assignment syntax:

fpath+=("${(u)fpath[@]}")

But even that probably doesn't do what you meant. because unless you have
already done "typeset -U fpath" all the existing elements are still going
to be repeated twice ... and IF you HAVE done "typeset -U" then (u) is a
no-op.