kiss: speedup pkg_find when finding one package

pkg_find is used for 2 purposes:
 - finding all packages in KISS_PATH that meet some criteria
 - finding the first package in KISS_PATH that meets criteria

The first is the case for `kiss search` but the second is more common.
It is used everywhere to find the first package, that is, the package to
be used for builds, downloads, upgrades etc.
However, in both cases, every repo in KISS_PATH is scanned for the
package, which is unnecessary in the second case which only needs the
first match. Therefore, break after the first match in this case.

On my system, this results in a 2x speedup of `kiss U` (just the logic
to detect upgrades, exiting before prompting).
This commit is contained in:
phoebos 2023-06-14 01:57:40 +01:00
parent 37e6a59ed3
commit a0f6e89299
No known key found for this signature in database

5
kiss
View File

@ -330,7 +330,10 @@ _pkg_find() {
for _find_path in $4 "${3:-$sys_db}"; do set +f
ok "$_find_path" || continue
for _find_pkg in "$_find_path/"$1; do
test "${3:--d}" "$_find_pkg" && set -f -- "$@" "$_find_pkg"
test "${3:--d}" "$_find_pkg" && {
set -f -- "$@" "$_find_pkg"
case $2- in -) break 2 ;; esac
}
done
done