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

Re: Slow completion when using aptitude



On Jan 30, 11:51am, Julien Nicoulaud wrote:
} 
} By the way, this issue was already known:
} http://www.zsh.org/mla/workers/2008/msg00930.html

So ...

_deb_packages_update_avail uses the cache to populate an array variable
of the same name.

As does _deb_packages_update_installed.

Then _deb_packages_update_uninstalled constructs a massive glob pattern
from the results of the latter, and applies it as a filter against the
former, to set a variable _deb_packages_update_uninstalled.

Thereafter the value of _deb_packages_update_uninstalled is used rather
than go through that filter again, so it *is* caching.  The disk cache
isn't used by _deb*_uninstalled because the files are all on the disk
already from the other two functions. 

All the time is being spent building that glob pattern, and filtering.

So try using this instead:

_deb_packages_update_uninstalled () {
  _deb_packages_update_avail
  _deb_packages_update_installed
  if (( ! $+_deb_packages_cache_uninstalled )); then
    local avail
    for avail in $_deb_packages_cache_avail
    do
	(( ${+_deb_packages_cache_installed[(r)$avail]} )) && continue
	_deb_packages_cache_uninstalledr+=( $avail )
    done
  fi
  cachevar=_deb_packages_cache_uninstalled
}

Sometimes the most zsh-ish way to do something isn't the most efficient
way to do it.  It may even be still faster to replace the "for" loop
with:

    _dep_packages_cache_uninstalled=(
	$( print -l $_deb_packages_cache_avail | 
	   fgrep -vf =(print -l $_deb_packages_cache_installed) )
    )



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