Re: Calling symbol table patch
| From: | Andrei Zmievski | Date: | Mon, 20 Nov 2000 21:34:13 +0000 |
| Subject: | Re: Calling symbol table patch | ||
| References: | 1 2 3 4 5 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-38694@lists.php.net to get a copy of this message | ||
On Mon, 20 Nov 2000, Zeev Suraski wrote:
> Well, a stack push is a considerable slowdown. How much it slows things
> down exactly obviously depends on your script...
Oh, come on.
ZEND_API inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)
{
if (stack->top >= stack->max) { /* we need to allocate more memory */
stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max
*= 2 )));
stack->top_element = stack->elements+stack->top;
}
stack->top++;
*(stack->top_element++) = ptr;
}
Most of the time, stack->top is less than stack->max (because max = 64
on initialization), so all you are executing is the last two statements.
I don't think your argument is very strong as far as performance is
concerned.
> I think that the Right Way to do it would actually be a function that
> returns the current symbol table. Such a function can be implemented
> without slowing down or modifying anything in the engine, and then you
> could write:
>
> $tpl->batch_assign('foo', 'bar', 'color1',
> get_active_symtable())
>
> It's a bit more to type, no doubt, but I think it's more correct that
> way... Perhaps one day we'll have macros in PHP :)
>
> What I don't like about the function is that it appears to be hacky - it
> defeats a basic scope protection rule in structured/OO programming...
Yes, it does, but the only way around it is what you described up above
and it doesn't really look that appealing. If it was C/C++, I could
write a macro or something else, but with PHP, we don't have that. So,
I'm not sure what the solution is.
-Andrei
What's hard, in hacking as in fiction,
is not the writing, it's deciding what to write.
-- Neal Stephenson