[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1412523392.2916.3.camel@joe-AO725>
Date: Sun, 05 Oct 2014 08:36:32 -0700
From: Joe Perches <joe@...ches.com>
To: Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>
Cc: Grant Likely <grant.likely@...aro.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Andi Kleen <ak@...ux.intel.com>,
Dan Carpenter <dan.carpenter@...cle.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] lib: string.c: A speed optimized for strncpy
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);
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists