From cac001aabe03a91b6480d797498787bdb280fa02 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Fri, 27 Dec 2013 15:52:18 +0000 Subject: [PATCH] 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. --- bin/sh/input.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/bin/sh/input.c b/bin/sh/input.c index e46095d5ed5..e527d36c995 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -228,7 +228,6 @@ preadbuffer(void) { char *p, *q; int more; - int something; char savec; if (parsefile->strpush) { @@ -252,24 +251,18 @@ again: 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 @@ check: *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,