From: Joe Perches <joe@perches.com>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Grant Likely <grant.likely@linaro.org>,
Andrew Morton <akpm@linux-foundation.org>,
Andi Kleen <ak@linux.intel.com>,
Dan Carpenter <dan.carpenter@oracle.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib: string.c: A speed optimized for strncpy
Date: Sun, 05 Oct 2014 08:36:32 -0700 [thread overview]
Message-ID: <1412523392.2916.3.camel@joe-AO725> (raw)
In-Reply-To: <1412515757-19689-2-git-send-email-rickard_strandqvist@spectrumdigital.se>
On Sun, 2014-10-05 at 15:29 +0200, Rickard Strandqvist wrote:
> This variant is in my tests about 7-10% faster, and also think
> it is perhaps even clearer code than before.
[]
> diff --git a/lib/string.c b/lib/string.c
[]
> @@ -123,12 +123,12 @@ char *strncpy(char *dest, const char *src, size_t count)
> {
> char *tmp = dest;
>
> - while (count) {
> - if ((*tmp = *src) != 0)
> - src++;
> - tmp++;
> - count--;
> - }
> + while (count && (*tmp++ = *src++))
> + --count;
> +
> + while (count--)
> + *tmp++ = '\0';
Perhaps it could be faster to use memset.
It might depend on the value of count.
{
while (count && (*tmp++ = *src++))
count--;
if (count > 0)
memset(tmp, 0, count);
}
next prev parent reply other threads:[~2014-10-05 15:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-05 13:29 Rickard Strandqvist
2014-10-05 13:29 ` Rickard Strandqvist
2014-10-05 15:36 ` Joe Perches [this message]
2014-10-05 16:01 ` Rickard Strandqvist
2014-10-15 11:27 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1412523392.2916.3.camel@joe-AO725 \
--to=joe@perches.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=grant.likely@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rickard_strandqvist@spectrumdigital.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®