Skip to content

Commit 6df817b

Browse files
hridhinvarkeyjosephljharb
authored andcommitted
[Perf] nvm_resolve_local_alias: skip nvm_version for an exact, installed version
See #3416
1 parent 5ec9b3b commit 6df817b

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎nvm.sh‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,11 +1673,18 @@ nvm_resolve_local_alias() {
16731673
if [ -z "${VERSION}" ]; then
16741674
return $EXIT_CODE
16751675
fi
1676-
if [ "_${VERSION}" != '_∞' ]; then
1677-
nvm_version "${VERSION}"
1678-
else
1676+
if [ "_${VERSION}" = '_∞' ]; then
16791677
nvm_echo "${VERSION}"
1678+
return
16801679
fi
1680+
1681+
# Fast path: an exact, installed vX.Y.Z needs no further resolution.
1682+
if nvm_is_installed_exact_version "${VERSION}"; then
1683+
nvm_echo "${VERSION}"
1684+
return
1685+
fi
1686+
1687+
nvm_version "${VERSION}"
16811688
}
16821689

16831690
nvm_iojs_prefix() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
die () { echo "$@" ; exit 1; }
4+
5+
: nvm.sh
6+
\. ../../../nvm.sh
7+
8+
nvm_version() {
9+
echo 'nvm_version was called' >&2
10+
return 42
11+
}
12+
13+
EXACT="$(nvm_resolve_local_alias test-stable-1)"
14+
[ "_$EXACT" = "_v0.0.1" ] || die "'nvm_resolve_local_alias test-stable-1' was not v0.0.1; got $EXACT"
15+
16+
echo v0.0.99 > ../../../alias/test-not-installed
17+
NOT_INSTALLED="$(nvm_resolve_local_alias test-not-installed 2>/dev/null)"
18+
EXIT_CODE=$?
19+
rm -f ../../../alias/test-not-installed
20+
[ "_$EXIT_CODE" = "_42" ] || die "an exact version that is not installed should still go through nvm_version; got exit code $EXIT_CODE"

0 commit comments

Comments
 (0)