<!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>
In the branch <A HREF="http://svn.digium.com/svn/asterisk/team/murf/fast-ast3">http://svn.digium.com/svn/asterisk/team/murf/fast-ast3</A> I have tweaked the execution loop that runs instructions in the dialplan, to eliminate half the find_extension calls, and therefore run more efficiently. It results in a solid 9% speedup to trunk.<BR>
<BR>
What I did was this:<BR>
<BR>
                /* loop on priorities in this context/exten */<BR>
                while (ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {<BR>
                        found = 1;<BR>
                        if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {<BR>
                                /* Something bad happened, or a hangup has been requested. */<BR>
................<BR>
<BR>
to this:<BR>
<BR>
<BR>
                /* loop on priorities in this context/exten */<BR>
                while ( !(res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found))) {<BR>
                        if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {<BR>
...........<BR>
                        c->priority++;<BR>
                } /* end while - from here on we can use 'break' to go out */<BR>
                if (found && res) {<BR>
                        /* Something bad happened, or a hangup has been requested. */<BR>
<BR>
You see, exists_extension() and spawn_extension() are both really just front ends to extension_helper, and seems a waste <BR>
to call the same function twice in succession, when one can tell you everything you need to know!<BR>
<BR>
SO, I added the ptr to 'found' to the spawn_extension, and make spawn_extension set it. Then rearrange the flow so the same<BR>
stuff happens as did previously.<BR>
<BR>
If I'm shooting myself or really mucking things up, please let me know. It looks OK to me, and runs OK in my test system, but<BR>
this is at the very core of the PBX. Any other reviewers/testers who would like to make sure I'm not destroying something<BR>
would be welcome.<BR>
<BR>
As it is, the code executed between priority executions is cut in half, and now only one call to find_extension is done, which seems to<BR>
me more efficient.<BR>
<BR>
<BR>
murf<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>
--
Steve Murphy
Software Developer
Digium
</PRE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>