RE: [PHP-DEV] PHP 5.1
| From: | Jared Williams | Date: | Tue, 07 Jun 2005 15:18:23 +0000 |
| Subject: | RE: [PHP-DEV] PHP 5.1 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-16521@lists.php.net to get a copy of this message | ||
>
> > As for my own example, many state machines make extensive
> use of goto
> > to avoid recursive calls.
>
> Goto is not required for that. State machines such as the
> following
>
> state1:
> ...
>
> goto state99;
>
> state99:
> ...
>
> goto state2;
>
> done:
>
> can easily be rewritten as
>
> while (!end_condition) {
> switch (state) {
> case 1:
>
> state = 99;
> break;
>
> case 99:
>
> state = 2;
> break;
> }
> }
>
> - Sascha
Last time I looked (which was a while ago so may have been since improved) PHP performed a linear
search of case values, so took n/2
comparisons (where n is number of cases) on average to find the correct block to execute in a switch
statement, wheras using goto
doesn't have to perform any.
Jared