Re: [ZEND-ENGINE-CVS] cvs: Zend / zend.c zend_execute_API.c zend_globals.h

From: Date: Sat, 12 Oct 2002 19:22:11 +0000
Subject: Re: [ZEND-ENGINE-CVS] cvs: Zend / zend.c zend_execute_API.c zend_globals.h
References: 1 2  Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-504@lists.php.net to get a copy of this message
On October 12, 2002 10:59 am, Andi Gutmans wrote: > At 09:21 AM 10/11/2002 -0400, Ilia A. wrote: > >On October 11, 2002 03:12 am, Andi Gutmans wrote: > > > I understood that earlier. I was just curious if instead of: > > > convert_to_string(expr_copy); > > > > > > /* locale handling */ > > > if (EG(float_separator)[0] != '.') { > > > char *p = expr_copy->value.str.val; > > > if ((p = strchr(p, '.'))) { > > > *p = EG(float_separator)[0]; > > > } > > > } > > > > > > we could have something like: > > > > > > char foo[100]; > > > locale_sprintf(foo, ....); > > > expr_copy->value.str.val = strdup(foo); > > > > > > It's a bit sucky to have the EG(float_separator) and the strchr(). > > > If you guys think I'm exaggerating let me know :) > > > >Never hurts to try, let me come up with code that'll emulate your > > suggestion. If it works faster then by all means lets use that. However, > > I do not believe it would be faster in this case. > > Okay let us know what you come up with. In any case, I'm sure it'll be > sexier :) Heh :). Allright, here is what I've tried. First I've tried to see if perphaps there is a better approach to finding the decimal point then strchr(). The alternative is to use log10 or log10 like function. That did not work out as well as I hoped and strchr() was still way faster. Then I've tried using php_sprintf_appenddouble(), which is PHP own sprintf() implementation that allows specification of a decimal_point (yes I know I shouldn't use php_* functions inside Zend code, but for the sake of testing it was faster then writing my own). That too was slower, then native sprintf() + strchr(). The only solution I can propose at this point is adding zend_locale_sprintf() function that'll simply move the code from zend.c to zend_operators.c. Suggested patch is attached. Ilia

Index: zend.c =================================================================== RCS file: /repository/Zend/zend.c,v retrieving revision 1.160 diff -u -r1.160 zend.c --- zend.c 10 Oct 2002 22:36:01 -0000 1.160 +++ zend.c 12 Oct 2002 18:54:41 -0000 @@ -124,8 +124,6 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) { - TSRMLS_FETCH(); - if (expr->type==IS_STRING) { *use_copy = 0; return; @@ -159,15 +157,7 @@ case IS_DOUBLE: *expr_copy = *expr; zval_copy_ctor(expr_copy); - convert_to_string(expr_copy); - - /* locale handling */ - if (EG(float_separator)[0] != '.') { - char *p = expr_copy->value.str.val; - if ((p = strchr(p, '.'))) { - *p = EG(float_separator)[0]; - } - } + zend_locale_sprintf(expr_copy); break; default: *expr_copy = *expr; Index: zend_operators.c =================================================================== RCS file: /repository/Zend/zend_operators.c,v retrieving revision 1.127 diff -u -r1.127 zend_operators.c --- zend_operators.c 9 Oct 2002 14:17:53 -0000 1.127 +++ zend_operators.c 12 Oct 2002 18:54:45 -0000 @@ -1734,3 +1734,21 @@ } zend_compare_symbol_tables(result, Z_OBJPROP_P(o1), Z_OBJPROP_P(o2) TSRMLS_CC); } + +ZEND_API void zend_locale_sprintf(zval *op ZEND_FILE_LINE_DC) +{ + double dval = op->value.dval; + + TSRMLS_FETCH(); + + op->value.str.val = (char *) emalloc_rel(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1); + sprintf(op->value.str.val, "%.*G", (int) EG(precision), dval); + op->value.str.len = strlen(op->value.str.val); + + if (EG(float_separator)[0] != '.') { + char *p = op->value.str.val; + if ((p = strchr(p, '.'))) { + *p = EG(float_separator)[0]; + } + } +} \ No newline at end of file Index: zend_operators.h =================================================================== RCS file: /repository/Zend/zend_operators.h,v retrieving revision 1.54 diff -u -r1.54 zend_operators.h --- zend_operators.h 9 Oct 2002 14:17:53 -0000 1.54 +++ zend_operators.h 12 Oct 2002 18:54:46 -0000 @@ -185,6 +185,8 @@ ZEND_API int zend_atoi(const char *str, int str_len); +ZEND_API void zend_locale_sprintf(zval *op ZEND_FILE_LINE_DC); + #define convert_to_ex_master(ppzv, lower_type, upper_type) \ if ((*ppzv)->type!=IS_##upper_type) { \ if (!(*ppzv)->is_ref) { \
« previous php.zend-engine.cvs (#504) next »