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.
This commit is contained in:
zeertzjq
2021-12-20 18:58:13 +08:00
parent 67bb01ae27
commit 09c412837f
3 changed files with 17 additions and 13 deletions

View File

@@ -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 {