From owner-svn-src-all@freebsd.org Thu Nov 19 00:02:13 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4E25E475B15; Thu, 19 Nov 2020 00:02:13 +0000 (UTC) (envelope-from emaste@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cc0Gs1bbdz4qZC; Thu, 19 Nov 2020 00:02:13 +0000 (UTC) (envelope-from emaste@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 29AE41A5E9; Thu, 19 Nov 2020 00:02:13 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AJ02D9K064718; Thu, 19 Nov 2020 00:02:13 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AJ02DJ3064717; Thu, 19 Nov 2020 00:02:13 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <202011190002.0AJ02DJ3064717@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 19 Nov 2020 00:02:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367822 - head/lib/libc/string X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: head/lib/libc/string X-SVN-Commit-Revision: 367822 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 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: Thu, 19 Nov 2020 00:02:13 -0000 Author: emaste Date: Thu Nov 19 00:02:12 2020 New Revision: 367822 URL: https://svnweb.freebsd.org/changeset/base/367822 Log: libc: optimize memmem two-way bad character shift first, the condition (mem && k < p) is redundant, because mem being nonzero implies the needle is periodic with period exactly p, in which case any byte that appears in the needle must appear in the last p bytes of the needle, bounding the shift (k) by p. second, the whole point of replacing the shift k by mem (=l-p) is to prevent shifting by less than mem when discarding the memory on shift, in which case linear time could not be guaranteed. but as written, the check also replaced shifts greater than mem by mem, reducing the benefit of the shift. there is no possible benefit to this reduction of the shift; since mem is being cleared, the full shift is valid and more optimal. so only replace the shift by mem when it would be less than mem. musl commits: 8f5a820d147da36bcdbddd201b35d293699dacd8 122d67f846cb0be2c9e1c3880db9eb9545bbe38c Obtained from: musl MFC after: 2 weeks Modified: head/lib/libc/string/memmem.c Modified: head/lib/libc/string/memmem.c ============================================================================== --- head/lib/libc/string/memmem.c Wed Nov 18 22:01:34 2020 (r367821) +++ head/lib/libc/string/memmem.c Thu Nov 19 00:02:12 2020 (r367822) @@ -153,8 +153,8 @@ twoway_memmem(const unsigned char *h, const unsigned c if (BITOP(byteset, h[l - 1], &)) { k = l - shift[h[l - 1]]; if (k) { - if (mem0 && mem && k < p) - k = l - p; + if (k < mem) + k = mem; h += k; mem = 0; continue;