lkml.org 
[lkml]   [2014]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] lib: string.c: A speed optimized for strncpy
Hi

Yes, it can be faster, even if it is as you say, probably a difference
depending on the size of the count.
And even greater need to test this on a variety of hardware :-/

But I try to do my test with the memset variant to.

Kind regards
Rickard Strandqvist


2014-10-05 17:36 GMT+02:00 Joe Perches <joe@perches.com>:
> 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);
> }
>


\
 
 \ /
  Last update: 2014-10-05 18:41    [W:0.062 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site