[asterisk-dev] Wanted: Missing CPU Cycles... Reward!

Steve Murphy murf at digium.com
Wed Oct 31 19:46:26 CDT 2007


On Wed, 2007-10-31 at 18:05 +0100, Vadim Lebedev wrote:

> ...
> Well the following is obviously MUUCH faster than the original:
> 
> static void pbx_substitute_variables(char *passdata, int datalen,
> struct ast_channel *c, struct ast_exten *e)
> {
> 
>         /* No variables or expressions in e->data, so why scan it? */
>         if (e->data && !strchr(e->data, '$'))
>                 ast_copy_string(passdata, e->data, datalen);
>                 return;
>         }
>         
>         *passdata = 0;
>         pbx_substitute_variables_helper(c, e->data, passdata, datalen
> - 1);
> }
> 
> 
> Original:
> static void pbx_substitute_variables(char *passdata, int datalen,
> struct ast_channel *c, struct ast_exten *e)
> {
>         memset(passdata, 0, datalen);
> 
>         /* No variables or expressions in e->data, so why scan it? */
>         if (e->data && !strchr(e->data, '$') && !strstr(e->data,"${")
> && !strstr(e->data,"$[") && !strstr(e->data,"$(")) {
>                 ast_copy_string(passdata, e->data, datalen);
>                 return;
>         }
> 
>         pbx_substitute_variables_helper(c, e->data, passdata, datalen
> - 1);
> }
> 
> 


Oh, and yes, I forgot to mention *passdata = 0; vs memset(passdata, 0,
datalen);
Considering that the passdata buffer is 8192 bytes long, just writing 1
byte vs. 8192 bytes WOULD be a huge savings in time. 

BUT, you can't do that. pbx_substitute_variables_helper will not work.
It depends on passdata being nulled out, and it will fail to work
correctly if you go that route.

murf


-- 
Steve Murphy
Software Developer
Digium
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20071031/73b85d69/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3227 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20071031/73b85d69/attachment.bin 


More information about the asterisk-dev mailing list