mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-29 18:51:15 -03:00
functions/cd: Optimize check for too many args
This ran two `test`s a `count` and one `echo`, which is a bit wasteful. So instead, for the common case where you pass one argument, this will run one `set -q`. This can save off ~160 microseconds for each ordinary `cd`, which speeds it up by a factor of ~2 (so 1000 runs of cd might take 260ms instead of 550ms). Ideally the cd function would just be incorporated into the builtin, but that's a bigger change.
This commit is contained in:
@@ -4,7 +4,10 @@
|
||||
function cd --description "Change directory"
|
||||
set -l MAX_DIR_HIST 25
|
||||
|
||||
if test (count $argv) -gt (test "$argv[1]" = "--" && echo 2 || echo 1)
|
||||
if set -q argv[2]; and begin
|
||||
set -q argv[3]
|
||||
or not test "$argv[1]" = --
|
||||
end
|
||||
printf "%s\n" (_ "Too many args for cd command") >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user