summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-12-27 15:52:18 +0000
committerjilles <jilles@FreeBSD.org>2013-12-27 15:52:18 +0000
commitab778292cf6106002b1414f219def70d15349478 (patch)
treec5b5239b2231d2f328ae5ee7c334f647dbfdf8ba /bin/sh
parent8b6b2d3d8496d46a93fc4e85bb15252cc5b500c9 (diff)
downloadFreeBSD-src-ab778292cf6106002b1414f219def70d15349478.zip
FreeBSD-src-ab778292cf6106002b1414f219def70d15349478.tar.gz
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.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/input.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/bin/sh/input.c b/bin/sh/input.c
index e46095d..e527d36 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,
OpenPOWER on IntegriCloud