sh: Don't check input for non-whitespace if history is disabled.
preadbuffer() maintained a flag whether there was any non-whitespace character. This flag is only useful when history is enabled (in that case, lines containing only whitespace are not added to history). Instead, check using strspn() when history is enabled. There is an approximate 2% speedup when running sh -c '. /etc/rc.subr; . /etc/defaults/rc.conf; source_rc_confs' with hot cache.
This commit is contained in:
parent
4707030025
commit
cac001aabe
@ -228,7 +228,6 @@ preadbuffer(void)
|
||||
{
|
||||
char *p, *q;
|
||||
int more;
|
||||
int something;
|
||||
char savec;
|
||||
|
||||
if (parsefile->strpush) {
|
||||
@ -252,24 +251,18 @@ preadbuffer(void)
|
||||
q = p = parsefile->buf + (parsenextc - parsefile->buf);
|
||||
|
||||
/* delete nul characters */
|
||||
something = 0;
|
||||
for (more = 1; more;) {
|
||||
switch (*p) {
|
||||
case '\0':
|
||||
p++; /* Skip nul */
|
||||
goto check;
|
||||
|
||||
case '\t':
|
||||
case ' ':
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
parsenleft = q - parsenextc;
|
||||
more = 0; /* Stop processing here */
|
||||
break;
|
||||
|
||||
default:
|
||||
something = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -288,7 +281,8 @@ preadbuffer(void)
|
||||
*q = '\0';
|
||||
|
||||
#ifndef NO_HISTORY
|
||||
if (parsefile->fd == 0 && hist && something) {
|
||||
if (parsefile->fd == 0 && hist &&
|
||||
parsenextc[strspn(parsenextc, " \t\n")] != '\0') {
|
||||
HistEvent he;
|
||||
INTOFF;
|
||||
history(hist, &he, whichprompt == 1 ? H_ENTER : H_ADD,
|
||||
|
Loading…
Reference in New Issue
Block a user