From owner-svn-src-all@FreeBSD.ORG Sat Jan 17 05:38:15 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2AAB01065674; Sat, 17 Jan 2009 05:38:15 +0000 (UTC) (envelope-from das@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F283A8FC18; Sat, 17 Jan 2009 05:38:14 +0000 (UTC) (envelope-from das@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0H5cEWN028552; Sat, 17 Jan 2009 05:38:14 GMT (envelope-from das@svn.freebsd.org) Received: (from das@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0H5cEJZ028551; Sat, 17 Jan 2009 05:38:14 GMT (envelope-from das@svn.freebsd.org) Message-Id: <200901170538.n0H5cEJZ028551@svn.freebsd.org> From: David Schultz Date: Sat, 17 Jan 2009 05:38:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r187354 - head/lib/libc/stdio X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jan 2009 05:38:15 -0000 Author: das Date: Sat Jan 17 05:38:14 2009 New Revision: 187354 URL: http://svn.freebsd.org/changeset/base/187354 Log: Simplify printf's inlined output buffering routines. On amd64, this reduces the code size by about 10% and improves performance slightly. Modified: head/lib/libc/stdio/printfcommon.h Modified: head/lib/libc/stdio/printfcommon.h ============================================================================== --- head/lib/libc/stdio/printfcommon.h Sat Jan 17 02:54:27 2009 (r187353) +++ head/lib/libc/stdio/printfcommon.h Sat Jan 17 05:38:14 2009 (r187354) @@ -64,14 +64,13 @@ struct io_state { FILE *fp; struct __suio uio; /* output information: summary */ struct __siov iov[NIOV];/* ... and individual io vectors */ - struct __siov *iovp; /* pointer to next free slot in iov */ }; static inline void io_init(struct io_state *iop, FILE *fp) { - iop->uio.uio_iov = iop->iovp = iop->iov; + iop->uio.uio_iov = iop->iov; iop->uio.uio_resid = 0; iop->uio.uio_iovcnt = 0; iop->fp = fp; @@ -85,15 +84,13 @@ static inline int io_print(struct io_state *iop, const CHAR * __restrict ptr, int len) { - iop->iovp->iov_base = (char *)ptr; - iop->iovp->iov_len = len; + iop->iov[iop->uio.uio_iovcnt].iov_base = (char *)ptr; + iop->iov[iop->uio.uio_iovcnt].iov_len = len; iop->uio.uio_resid += len; - iop->iovp++; - if (++iop->uio.uio_iovcnt >= NIOV) { - iop->iovp = iop->iov; + if (++iop->uio.uio_iovcnt >= NIOV) return (__sprint(iop->fp, &iop->uio)); - } - return (0); + else + return (0); } /* @@ -114,14 +111,14 @@ static const CHAR zeroes[PADSIZE] = static inline int io_pad(struct io_state *iop, int howmany, const CHAR * __restrict with) { + int n; - while (howmany > PADSIZE) { - if (io_print(iop, with, PADSIZE)) + while (howmany > 0) { + n = (howmany >= PADSIZE) ? PADSIZE : howmany; + if (io_print(iop, with, n)) return (-1); - howmany -= PADSIZE; + howmany -= n; } - if (howmany > 0 && io_print(iop, with, howmany)) - return (-1); return (0); } @@ -138,16 +135,19 @@ io_printandpad(struct io_state *iop, con p_len = ep - p; if (p_len > len) p_len = len; - if (p_len > 0 && io_print(iop, p, p_len)) - return (-1); - return (io_pad(iop, len - (p_len > 0 ? p_len : 0), with)); + if (p_len > 0) { + if (io_print(iop, p, p_len)) + return (-1); + } else { + p_len = 0; + } + return (io_pad(iop, len - p_len, with)); } static inline int io_flush(struct io_state *iop) { - iop->iovp = iop->iov; return (__sprint(iop->fp, &iop->uio)); }