aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_docmd.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2021-12-20 18:58:13 +0800
committerzeertzjq <zeertzjq@outlook.com>2021-12-20 18:58:13 +0800
commit09c412837fc9690ac8817dfd9c623dc6771c8d25 (patch)
treec55be458ffb1022ac1ca3dfe71fc4114143e386c /src/nvim/ex_docmd.c
parent67bb01ae27db3cbba9e2e908c4e6612040f650aa (diff)
downloadrneovim-09c412837fc9690ac8817dfd9c623dc6771c8d25.tar.gz
rneovim-09c412837fc9690ac8817dfd9c623dc6771c8d25.tar.bz2
rneovim-09c412837fc9690ac8817dfd9c623dc6771c8d25.zip
refactor: remove some chdir-related unnecessary calls and checks
xmalloc() always retuns a valid pointer. Calling os_chdir() with the same directory as the current one doesn't do anything other than wasting time.
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r--src/nvim/ex_docmd.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 9f0f8d93a3..ee7946fe3e 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -7816,8 +7816,9 @@ bool changedir_func(char_u *new_dir, CdScope scope)
}
#endif
- if (vim_chdir(new_dir) == 0) {
- bool dir_differs = pdir == NULL || pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
+ bool dir_differs = new_dir == NULL || pdir == NULL
+ || pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
+ if (new_dir != NULL && (!dir_differs || vim_chdir(new_dir) == 0)) {
post_chdir(scope, dir_differs);
retval = true;
} else {