Remove two-iteration loop from expand_filename

This commit is contained in:
Pavel Platto
2014-04-28 16:32:47 +03:00
committed by Thiago de Arruda
parent 1a946ad05f
commit 97f02bb609

View File

@@ -3605,7 +3605,6 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
char_u *repl; char_u *repl;
int srclen; int srclen;
char_u *p; char_u *p;
int n;
int escaped; int escaped;
/* Skip a regexp pattern for ":vimgrep[add] pat file..." */ /* Skip a regexp pattern for ":vimgrep[add] pat file..." */
@@ -3718,13 +3717,30 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
* Don't do this with ":r !command" or ":w !command". * Don't do this with ":r !command" or ":w !command".
*/ */
if ((eap->argt & NOSPC) && !eap->usefilter) { if ((eap->argt & NOSPC) && !eap->usefilter) {
// Replace environment variables.
if (has_wildcards) {
/* /*
* May do this twice: * May expand environment variables. This
* 1. Replace environment variables. * can be done much faster with expand_env() than with
* 2. Replace any other wildcards, remove backslashes. * something else (e.g., calling a shell).
* After expanding environment variables, check again
* if there are still wildcards present.
*/ */
for (n = 1; n <= 2; ++n) { if (vim_strchr(eap->arg, '$') != NULL
if (n == 2) { || vim_strchr(eap->arg, '~') != NULL) {
expand_env_esc(eap->arg, NameBuff, MAXPATHL,
TRUE, TRUE, NULL);
has_wildcards = mch_has_wildcard(NameBuff);
p = NameBuff;
} else
p = NULL;
if (p != NULL) {
(void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
p, cmdlinep);
}
}
// Replace any other wildcards, remove backslashes.
#ifdef UNIX #ifdef UNIX
/* /*
* Only for Unix we check for more than one file name. * Only for Unix we check for more than one file name.
@@ -3751,30 +3767,12 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
* For Unix, when wildcards are expanded, this is * For Unix, when wildcards are expanded, this is
* done by ExpandOne() below. * done by ExpandOne() below.
*/ */
#if defined(UNIX) #ifdef UNIX
if (!has_wildcards) if (!has_wildcards)
#endif #endif
backslash_halve(eap->arg); backslash_halve(eap->arg);
}
if (has_wildcards) { if (has_wildcards) {
if (n == 1) {
/*
* First loop: May expand environment variables. This
* can be done much faster with expand_env() than with
* something else (e.g., calling a shell).
* After expanding environment variables, check again
* if there are still wildcards present.
*/
if (vim_strchr(eap->arg, '$') != NULL
|| vim_strchr(eap->arg, '~') != NULL) {
expand_env_esc(eap->arg, NameBuff, MAXPATHL,
TRUE, TRUE, NULL);
has_wildcards = mch_has_wildcard(NameBuff);
p = NameBuff;
} else
p = NULL;
} else { /* n == 2 */
expand_T xpc; expand_T xpc;
int options = WILD_LIST_NOTFOUND|WILD_ADD_SLASH; int options = WILD_LIST_NOTFOUND|WILD_ADD_SLASH;
@@ -3786,16 +3784,13 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
options, WILD_EXPAND_FREE); options, WILD_EXPAND_FREE);
if (p == NULL) if (p == NULL)
return FAIL; return FAIL;
}
if (p != NULL) { if (p != NULL) {
(void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
p, cmdlinep); p, cmdlinep);
if (n == 2) /* p came from ExpandOne() */
vim_free(p); vim_free(p);
} }
} }
} }
}
return OK; return OK;
} }