Re: [PHP4BETA] getParametersEx again - lets make PHP4 faster....

From: Date: Wed, 15 Sep 1999 14:42:38 +0000
Subject: Re: [PHP4BETA] getParametersEx again - lets make PHP4 faster....
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-4482@lists.php.net to get a copy of this message
zeev, right now we would have to add a *lot* of SEPARATE_ZVAL into the current modules, so that if somebody calls a function by reference it won't change the parameters. $i_am_an_int = 1; echo strlen(&$i_am_an_int); will output "1" *AND* convert $i_am_an_int to a string! so we'd have to insert a SEPARATE_ZVAL in the strlen function. i believe that it would be worthwise to rethink this and come up with something better and more efficient. right now SEPARATE_ZVAL i needed 'cause we use first_arg_allow (& friends) to make things faster by default for certain functions - we couln't do it for sizeof() 'cause sizeof("hallo") is valid / sizeof(&"hallo") is NOT - on the other hand that means that sizeof($largearray) will be *FAR* slower that sizeof(&$largearray) - but why should a scripter always use call-by-reference? so - why not start to change module-by-module to the new getParametersEx API before PHP4b3? - i believe the speed impact will be noticed! regards, tc one sugeestion: PHP_FUNCTION(strlen) { pval **str; int freeme; int length; char *a; if (ARG_COUNT(ht) != 1 || getParametersEx(1, &str) == FAILURE) { WRONG_PARAM_COUNT; } a = string_val(*str,&freeme,&length); RETVAL_LONG(length); if (freeme) efree(a); } static char *string_val(zval *op,int *freeme,int *lenght) { char *str; ELS_FETCH(); if (length) *length = 0; *freeme = 0; switch (op->type) { case IS_STRING: if (length) *length = op->value.str.len; return op->value.str.val; case IS_BOOL: if (op->value.lval) { if (length) *length = 1; return "1"; } else { return empty_string; } case IS_LONG: str = (char *) emalloc(MAX_LENGTH_OF_LONG + 1); if (length) *length = zend_sprintf(str, "%ld", op->value.lval); /* SAFE */ *freeme = 1; return str; case IS_DOUBLE: str = (char *) emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1); if (length) *length = zend_sprintf(str, "%.*G", (int) EG(precision), op->value.dval); /* SAFE */ *freeme = 1; return str; case IS_ARRAY: if (length) *length = sizeof("Array")-1; return "Array"; case IS_OBJECT: if (length) *length = sizeof("Object")-1; return "Object"; default: return empty_string; } } On Tue, 14 Sep 1999, Zeev Suraski wrote: > At 20:28 14/09/1999 , Andi Gutmans wrote: > >At 08:01 PM 9/14/99 +0200, Zeev Suraski wrote: > >All I intend to add is something along the lines of: > > > >>#define convert_to_long_ex(pz) \ > >> if ((*pz)->type != IS_LONG) { > >> SEPARATE_ZVAL(pz); > >> convert_to_long(*pz); > >> } > > > >That doesn't fix the problem I was talking about. If you pass an integer > >value to strlen() you don't want it to be seperated and converted to a > >string, you'd want a copy of it as a string. Similar to the API Thies > >mentioned. > > Hmm, I don't follow you here. > Separated and converted to a string == a copy of it as a string > > See my other letter as to the pros and cons of using each method... I > think that overall going with my approach is cleaner and much less prone to > errors. > > Zeev > -- > Zeev Suraski <zeev@zend.com> http://www.zend.com/ > For a PGP public key, finger bourbon@netvision.net.il > > > -- > PHP 4 Beta > > Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!" Digital Collections Phone +49 40 235350 Fax +49 40 23535180 Hammerbrookstr. 93 20097 Hamburg / Germany

« previous php.version4 (#4482) next »