Re: [PHP4BETA] getParametersEx again....
| From: | Andi Gutmans | Date: | Tue, 14 Sep 1999 16:12:27 +0000 |
| Subject: | Re: [PHP4BETA] getParametersEx again.... | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-4436@lists.php.net to get a copy of this message | ||
Yeah that looks OK.
getParametersEx() is MUCH faster than getParameters() and it should really be used when possible. However, it's use isn't completely trivial.
First of all, you have to make sure you don't change the value if the reference count is greater than 1, for example automatic calling of convert_to_long() and friends, is not a good idea.
However, Zeev did write some macro's which make this a lot easier.
Check out zend_operators.c the zendi_convert* macro's. I think they should be probably exported and maybe the "Ex" API can be improved to make things easier, but these macro's allow you to safely convert values which have reference counts by using a new zval (pval) when necessary.
In any case, I'm sure Zeev will also have something to say on this issue. I personally feel that the performance gain is so big that it's worth starting to move relatively quick functions to this new API, so that the API doesn't become a bottleneck. For example, strlen() will almost always be passed a string, thus the current implementation is relatively slow because getParameters() duplicates the string everytime, instead of only creating a new copy when the passed value is not a string and needs to be converted. Maybe if we move these macro's into a .h file Zeev and I can convert a few functions like strlen() so that you can get a good idea of what to do.
I hope this issue isn't too confusing :)
Andi
At 02:58 PM 9/14/99 +0200, Thies C. Arntzen wrote:
just playing around.... PHP_FUNCTION(count) {--- Andi Gutmans <andi@zend.com> http://www.zend.com/pval **array; HashTable *target_hash;if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { WRONG_PARAM_COUNT; }target_hash = HASH_OF(*array); if (!target_hash) { if ((*array)->type == IS_STRING && (*array)->value.str.val==undefined_variable_string) { RETURN_LONG(0); } else { RETURN_LONG(1); } }RETURN_LONG(zend_hash_num_elements(target_hash));} is this the "right" way of doing it? i believe that 'cause of the double refrencing in zvals (old mac-programmers would call it a "handle") this should work in all cases - and its faster than before. tc PS: this count implementation is always "fast" 'cause it *NEVER* copies the parameters (getParameters would copy!). -- PHP 4 Beta