From nobody Thu Oct 21 22:31:32 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 030EB1813440; Thu, 21 Oct 2021 22:31:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Hb2Jh6hvYz4fFx; Thu, 21 Oct 2021 22:31:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C6E1723343; Thu, 21 Oct 2021 22:31:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19LMVWj5018758; Thu, 21 Oct 2021 22:31:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19LMVWff018757; Thu, 21 Oct 2021 22:31:32 GMT (envelope-from git) Date: Thu, 21 Oct 2021 22:31:32 GMT Message-Id: <202110212231.19LMVWff018757@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: fa226878a553 - stable/13 - sbuf(9): Microoptimize sbuf_put_byte() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fa226878a5532e79acb373e1201f92e0114428e6 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=fa226878a5532e79acb373e1201f92e0114428e6 commit fa226878a5532e79acb373e1201f92e0114428e6 Author: Alexander Motin AuthorDate: 2021-10-05 18:42:47 +0000 Commit: Alexander Motin CommitDate: 2021-10-21 22:24:29 +0000 sbuf(9): Microoptimize sbuf_put_byte() This function is actively used by sbuf_vprintf(), so this simple inlining in half reduces time of kern.geom.confxml generation. MFC after: 2 weeks Sponsored by: iXsystem, Inc. (cherry picked from commit 7835b2cb4a1ae57f403739a2f1076ec7188f18c9) --- sys/kern/subr_sbuf.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sys/kern/subr_sbuf.c b/sys/kern/subr_sbuf.c index b7f135e81206..6c533f36c82e 100644 --- a/sys/kern/subr_sbuf.c +++ b/sys/kern/subr_sbuf.c @@ -480,7 +480,26 @@ static void sbuf_put_byte(struct sbuf *s, char c) { - sbuf_put_bytes(s, &c, 1); + assert_sbuf_integrity(s); + assert_sbuf_state(s, 0); + + if (__predict_false(s->s_error != 0)) + return; + if (__predict_false(SBUF_FREESPACE(s) <= 0)) { + /* + * If there is a drain, use it, otherwise extend the + * buffer. + */ + if (s->s_drain_func != NULL) + (void)sbuf_drain(s); + else if (sbuf_extend(s, 1) < 0) + s->s_error = ENOMEM; + if (s->s_error != 0) + return; + } + s->s_buf[s->s_len++] = c; + if (SBUF_ISSECTION(s)) + s->s_sect_len++; } /* @@ -623,7 +642,7 @@ static void sbuf_putc_func(int c, void *arg) { - if (c != '\0') + if (__predict_true(c != '\0')) sbuf_put_byte(arg, c); }