<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.14.3">
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#ffffff">
On Wed, 2007-10-31 at 18:05 +0100, Vadim Lebedev wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
...<BR>
Well the following is obviously MUUCH faster than the original:<BR>
<BR>
static void pbx_substitute_variables(char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e)<BR>
{<BR>
<BR>
/* No variables or expressions in e->data, so why scan it? */<BR>
if (e->data && !strchr(e->data, '$'))<BR>
ast_copy_string(passdata, e->data, datalen);<BR>
return;<BR>
}<BR>
<BR>
*passdata = 0;<BR>
pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);<BR>
}<BR>
<BR>
<BR>
Original:<BR>
static void pbx_substitute_variables(char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e)<BR>
{<BR>
memset(passdata, 0, datalen);<BR>
<BR>
/* No variables or expressions in e->data, so why scan it? */<BR>
if (e->data && !strchr(e->data, '$') && !strstr(e->data,"${") && !strstr(e->data,"$[") && !strstr(e->data,"$(")) {<BR>
ast_copy_string(passdata, e->data, datalen);<BR>
return;<BR>
}<BR>
<BR>
pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);<BR>
}<BR>
<BR>
<BR>
</BLOCKQUOTE>
<BR>
Oh, and yes, I forgot to mention *passdata = 0; vs memset(passdata, 0, datalen);<BR>
Considering that the passdata buffer is 8192 bytes long, just writing 1 byte vs. 8192 bytes WOULD be a huge savings in time. <BR>
<BR>
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.<BR>
<BR>
murf<BR>
<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>
--
Steve Murphy
Software Developer
Digium
</PRE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>