From 6481d1451dca0320e7549367f1d7f263c94b5146 Mon Sep 17 00:00:00 2001 From: native-api Date: Fri, 24 Apr 2026 00:34:40 +0300 Subject: [PATCH] pyenv-latest: fast path for when there is an exact match (#3437) Avoids O(N^2) complexity when `pyenv-latest` is called in a loop for existing entries --- libexec/pyenv-latest | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libexec/pyenv-latest b/libexec/pyenv-latest index 7d85e302..3a32439e 100755 --- a/libexec/pyenv-latest +++ b/libexec/pyenv-latest @@ -10,6 +10,7 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x + while [[ $# -gt 0 ]] do case "$1" in @@ -38,6 +39,10 @@ exitcode=0 IFS=$'\n' if [[ -z $FROM_KNOWN ]]; then + if [[ -d $PYENV_ROOT/versions/$prefix ]]; then + echo "$prefix" + exit $exitcode; + fi DEFINITION_CANDIDATES=( $(pyenv-versions --bare --skip-envs) ) else DEFINITION_CANDIDATES=( $(python-build --definitions ) )