Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab77829

Browse files
committed
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.
1 parent 8b6b2d3 commit ab77829

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

bin/sh/input.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ preadbuffer(void)
228228
{
229229
char *p, *q;
230230
int more;
231-
int something;
232231
char savec;
233232

234233
if (parsefile->strpush) {
@@ -252,24 +251,18 @@ preadbuffer(void)
252251
q = p = parsefile->buf + (parsenextc - parsefile->buf);
253252

254253
/* delete nul characters */
255-
something = 0;
256254
for (more = 1; more;) {
257255
switch (*p) {
258256
case '\0':
259257
p++; /* Skip nul */
260258
goto check;
261259

262-
case '\t':
263-
case ' ':
264-
break;
265-
266260
case '\n':
267261
parsenleft = q - parsenextc;
268262
more = 0; /* Stop processing here */
269263
break;
270264

271265
default:
272-
something = 1;
273266
break;
274267
}
275268

@@ -288,7 +281,8 @@ preadbuffer(void)
288281
*q = '\0';
289282

290283
#ifndef NO_HISTORY
291-
if (parsefile->fd == 0 && hist && something) {
284+
if (parsefile->fd == 0 && hist &&
285+
parsenextc[strspn(parsenextc, " \t\n")] != '\0') {
292286
HistEvent he;
293287
INTOFF;
294288
history(hist, &he, whichprompt == 1 ? H_ENTER : H_ADD,

0 commit comments

Comments
 (0)