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

Re: fast subshell



On 01/04/18 11:39 AM, Bart Schaefer wrote:

It's quite possible that doing the memory management for the
assignment to all_matches in a newly forked process is faster than in
the original shell (perhaps because the subshell never needs to free
it again?).  There is also some overhead involved in saving/restoring
IFS with "local" which you are avoiding.
It's rather interesting.  I suppose the deepest gurus could actually discuss the nuts and bolts in detail.  Meanwhile my fears of some dreadful overhead are dead.

Also there's really no reason to do both "local IFS=..." and
"IFS=$OLD_IFS"
I need the thing restored for use latter in the same function. I've since seen that:

(
IFS=...
...
)

Somehow screws up, I'm not sure why but it has effects outside the parenthesis.  Issues with a subshell within a subshell?  Don't seem right.
   (){ local IFS=$'\n'; all_matches=( $( whence -mavS $@ ) ) }
I'll try that.
Or you can do it without changing IFS at all, like this:

   all_matches=( ${(f)"$( whence -mavS $@ )"} )

Now that's the 'real' answer.  Direct control within the statement itself.   Gotta get used to these nested parameters, it's not really that scary.



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