From owner-svn-src-head@freebsd.org Tue May 16 21:54:52 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AFEEED70AF3; Tue, 16 May 2017 21:54:52 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8B3ADD35; Tue, 16 May 2017 21:54:52 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4GLspSX050919; Tue, 16 May 2017 21:54:51 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4GLspGF050916; Tue, 16 May 2017 21:54:51 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201705162154.v4GLspGF050916@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Tue, 16 May 2017 21:54:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318385 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 May 2017 21:54:52 -0000 Author: jilles Date: Tue May 16 21:54:51 2017 New Revision: 318385 URL: https://svnweb.freebsd.org/changeset/base/318385 Log: sh: Simplify output buffering. Similarly to how STPUTC was changed, change struct output to store the pointer just past the end of the available space instead of the size of the available space, so after writing a character it is only necessary to increment a pointer and not to decrement a counter. Modified: head/bin/sh/eval.c head/bin/sh/output.c head/bin/sh/output.h Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Tue May 16 21:50:29 2017 (r318384) +++ head/bin/sh/eval.c Tue May 16 21:54:51 2017 (r318385) @@ -1080,8 +1080,8 @@ evalcommand(union node *cmd, int flags, #endif mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH; if (flags == EV_BACKCMD) { - memout.nleft = 0; memout.nextc = memout.buf; + memout.bufend = memout.buf; memout.bufsize = 64; mode |= REDIR_BACKQ; } @@ -1134,8 +1134,11 @@ cmddone: exitshell(exitstatus); if (flags == EV_BACKCMD) { backcmd->buf = memout.buf; - backcmd->nleft = memout.nextc - memout.buf; + backcmd->nleft = memout.buf != NULL ? + memout.nextc - memout.buf : 0; memout.buf = NULL; + memout.nextc = NULL; + memout.bufend = NULL; } if (cmdentry.u.index != EXECCMD) popredir(); Modified: head/bin/sh/output.c ============================================================================== --- head/bin/sh/output.c Tue May 16 21:50:29 2017 (r318384) +++ head/bin/sh/output.c Tue May 16 21:54:51 2017 (r318385) @@ -71,9 +71,9 @@ __FBSDID("$FreeBSD$"); static int doformat_wr(void *, const char *, int); -struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0}; -struct output errout = {NULL, 0, NULL, 256, 2, 0}; -struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0}; +struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0}; +struct output errout = {NULL, NULL, NULL, 256, 2, 0}; +struct output memout = {NULL, NULL, NULL, 0, MEM_OUT, 0}; struct output *out1 = &output; struct output *out2 = &errout; @@ -214,20 +214,19 @@ emptyoutbuf(struct output *dest) INTOFF; dest->buf = ckmalloc(dest->bufsize); dest->nextc = dest->buf; - dest->nleft = dest->bufsize; + dest->bufend = dest->buf + dest->bufsize; INTON; } else if (dest->fd == MEM_OUT) { - offset = dest->bufsize; + offset = dest->nextc - dest->buf; INTOFF; dest->bufsize <<= 1; dest->buf = ckrealloc(dest->buf, dest->bufsize); - dest->nleft = dest->bufsize - offset; + dest->bufend = dest->buf + dest->bufsize; dest->nextc = dest->buf + offset; INTON; } else { flushout(dest); } - dest->nleft--; } @@ -248,7 +247,6 @@ flushout(struct output *dest) if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0) dest->flags |= OUTPUT_ERR; dest->nextc = dest->buf; - dest->nleft = dest->bufsize; } @@ -258,8 +256,9 @@ freestdout(void) INTOFF; if (output.buf) { ckfree(output.buf); + output.nextc = NULL; output.buf = NULL; - output.nleft = 0; + output.bufend = NULL; } INTON; } Modified: head/bin/sh/output.h ============================================================================== --- head/bin/sh/output.h Tue May 16 21:50:29 2017 (r318384) +++ head/bin/sh/output.h Tue May 16 21:54:51 2017 (r318385) @@ -40,7 +40,7 @@ struct output { char *nextc; - int nleft; + char *bufend; char *buf; int bufsize; short fd; @@ -75,7 +75,7 @@ void fmtstr(char *, int, const char *, . void doformat(struct output *, const char *, va_list) __printflike(2, 0); int xwrite(int, const char *, int); -#define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) +#define outc(c, file) ((file)->nextc == (file)->bufend ? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) #define out1c(c) outc(c, out1); #define out2c(c) outcslow(c, out2);