lkml.org 
[lkml]   [2003]   [Apr]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [TRIVIAL] kstrdup
At 20:29 18/04/2003, Richard B. Johnson wrote:
> > > A lot of persons who are unfamiliar with tools other than 'C' think
> > > that strcpy() is made like this:
> > >
> > > while(*dsp++ = *src++)
> > > ;
> >
> > In fact, that's basically the kernel's non-arch-specific implementation :)
> >
> > Jeff
>
>Yep. Naive code looks so 'simple', must be "optimum", no? ;^).


Well, actually on ARM at least it is optimal, given the likely short length
of strings. To do any better at all you have to assume stringlength of many
tens of words, which is unlikely. For comparison, this is what armcc
produces for the above code:

strdup PROC
|L1.0|
000000 e4d12001 LDRB a3,[a2],#1 ;1
000004 e4c02001 STRB a3,[a1],#1 ;1
000008 e3520000 CMP a3,#0 ;1
00000c 1afffffb BNE |L1.0| ;1
000010 e1a0f00e MOV pc,lr ;1

AFAICT there is no better solution.

Ruth

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:34    [from the cache]
©2003-2011 Jasper Spaans