Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Dec 2013 15:52:19 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r259946 - head/bin/sh
Message-ID:  <201312271552.rBRFqJNw099869@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Fri Dec 27 15:52:18 2013
New Revision: 259946
URL: http://svnweb.freebsd.org/changeset/base/259946

Log:
  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.

Modified:
  head/bin/sh/input.c

Modified: head/bin/sh/input.c
==============================================================================
--- head/bin/sh/input.c	Fri Dec 27 15:44:16 2013	(r259945)
+++ head/bin/sh/input.c	Fri Dec 27 15:52:18 2013	(r259946)
@@ -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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312271552.rBRFqJNw099869>