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

@@ -1082,15 +1082,13 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// Return the current directory
cwd = xmalloc(MAXPATHL);
if (cwd != NULL) {
if (os_dirname(cwd, MAXPATHL) != FAIL) {
if (os_dirname(cwd, MAXPATHL) != FAIL) {
#ifdef BACKSLASH_IN_FILENAME
slash_adjust(cwd);
slash_adjust(cwd);
#endif
rettv->vval.v_string = vim_strsave(cwd);
}
xfree(cwd);
rettv->vval.v_string = vim_strsave(cwd);
}
xfree(cwd);
if (curwin->w_localdir != NULL) {
scope = kCdScopeWindow;