[Asterisk-Dev] [RFC] strncpy -> ast_copy_string

Steve Underwood steveu at coppice.org
Sun May 1 19:42:21 MST 2005


Kevin P. Fleming wrote:

> Steve Kann wrote:
>
>> You can at least do a simple processor-independent optimization of 
>> this, by copying long int-sized chunks of the string separately; 
>> here's a sample of this:
>>
>> http://www.koders.com/c/fid75DA39E03FCB2787FB2897C252B0A28F3D177937.aspx
>
>
> There's some serious voodoo going on there :-)

For block copies it is messy, but easy to understand. You need to handle 
0 to 3 bytes to get yourself aligned (0 to 7 on a 64 bit machine). Then 
you copy words. Then you need to deal with the last 0 to 3 bytes (or 0 
to 7 bytes) at the end. For short strings the messy bits make this an 
overall loser. For long strings it is quite a big win.

For strings its some messier still, as along the way any byte could be 
the terminating null. It is still doing the same basic thing, though - 
get aligned then work in words.

Regards,
Steve



More information about the asterisk-dev mailing list