aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/file_search.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/file_search.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/file_search.c')
-rw-r--r--src/nvim/file_search.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index d31021b3ef..1884dd49c5 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1667,14 +1667,19 @@ int vim_chdirfile(char_u *fname, CdCause cause)
NameBuff[0] = NUL;
}
- if (os_chdir(dir) == 0) {
- if (cause != kCdCauseOther && pathcmp(dir, (char *)NameBuff, -1) != 0) {
- do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
- }
- } else {
+ if (pathcmp(dir, (char *)NameBuff, -1) == 0) {
+ // nothing to do
+ return OK;
+ }
+
+ if (os_chdir(dir) != 0) {
return FAIL;
}
+ if (cause != kCdCauseOther) {
+ do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
+ }
+
return OK;
}