From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 1D0BC3858C39; Mon, 6 Feb 2023 20:14:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D0BC3858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675714452; bh=WAvNgP3H9fTpr38I5ZELEte3qJzevnkJv2tJO5LVE5Q=; h=From:To:Subject:Date:From; b=wS6Cc/TtBlz2SqPNG9t/8+w6dtrsyIOxgclixwwCrSoyptg2mJ+FGlLrqwWgeCb4n A0fr5gC8hNxPrzZLcNA3MhW/qspPOIgPUJMiIQMBYzMj5usw2YkakynM14GUfuQalm 3bLx1boHT+0csWOhaVRvvn4ZmuVG4R950oXMPC/g= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc] string: Improve generic strrchr with memrchr and strlen X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/master X-Git-Oldrev: 9d4fa7a1ca9154e814b7ede8d48186832bdbebe6 X-Git-Newrev: 167f6230af97690985ccbc9b3026a7c32ec2d6e9 Message-Id: <20230206201412.1D0BC3858C39@sourceware.org> Date: Mon, 6 Feb 2023 20:14:12 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=167f6230af97690985ccbc9b3026a7c32ec2d6e9 commit 167f6230af97690985ccbc9b3026a7c32ec2d6e9 Author: Adhemerval Zanella Date: Thu Feb 2 13:44:13 2023 -0300 string: Improve generic strrchr with memrchr and strlen Now that both strlen and memrchr have word vectorized implementation, it should be faster to implement strrchr based on memrchr over the string length instead of calling strchr on a loop. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Diff: --- string/strrchr.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/string/strrchr.c b/string/strrchr.c index 3c6e715d3b..7b76dea4e0 100644 --- a/string/strrchr.c +++ b/string/strrchr.c @@ -27,23 +27,7 @@ char * STRRCHR (const char *s, int c) { - const char *found, *p; - - c = (unsigned char) c; - - /* Since strchr is fast, we use it rather than the obvious loop. */ - - if (c == '\0') - return strchr (s, '\0'); - - found = NULL; - while ((p = strchr (s, c)) != NULL) - { - found = p; - s = p + 1; - } - - return (char *) found; + return __memrchr (s, c, strlen (s) + 1); } #ifdef weak_alias