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

Re: A method to not leak unneeded functions



i've noticed one thing: the need of "--" passed to unset, to be able
to unset dash-starting functions. The snippet is thus:

local -a ef
ef=( ${(k)functions} )
trap "unset -f -- \"\${(k)functions[@]:#(${(j:|:)${(q@)ef}})}\"
&>/dev/null" EXIT
trap "unset -f -- \"\${(k)functions[@]:#(${(j:|:)${(q@)ef}})}\"
&>/dev/null; return 1" INT
unset ef

That said, I've also noticed that the method is somewhat slow. For
2700 functions, the trap takes 0.39 seconds. If it could use the $ef
parameter, then it could do $${(k)functions:|ef} which I measured to
take only 1 ms. However, at the time of the EXIT trap, the local
parameters are being unset.

Is there any way to speed this up?

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



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