Re: [TRIVIAL] kstrdup

From: Ruth Ivimey-Cook (Ruth.Ivimey-Cook@ivimey.org)
Date: Sat Apr 19 2003 - 15:16:41 EST


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/



This archive was generated by hypermail 2b29 : Wed Apr 23 2003 - 22:00:26 EST