Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2(PHP_5_3) / zend_API.c

[email protected] (Marcus Boerger)
Newsgroups php.zend-engine.cvs
Message-ID <[email protected]>
Hello Stanislav,

Monday, November 24, 2008, 7:10:12 PM, you wrote:

> stas            Mon Nov 24 18:10:12 2008 UTC

>   Modified files:              (Branch: PHP_5_3)
>     /ZendEngine2        zend_API.c 
>   Log:
>   add object-compatible array modes
>   
>   
> http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_API.c?r1=1.296.2.27.2.34.2.55&r2=1.296.2.27.2.34.2.56&diff_format=u
> Index: ZendEngine2/zend_API.c
> diff -u ZendEngine2/zend_API.c:1.296.2.27.2.34.2.55
> ZendEngine2/zend_API.c:1.296.2.27.2.34.2.56
> --- ZendEngine2/zend_API.c:1.296.2.27.2.34.2.55       Tue Nov  4 15:58:49 2008
> +++ ZendEngine2/zend_API.c      Mon Nov 24 18:10:12 2008
> @@ -18,7 +18,7 @@
>    
> +----------------------------------------------------------------------+
>  */
>  
> -/* $Id: zend_API.c,v 1.296.2.27.2.34.2.55 2008/11/04 15:58:49 helly Exp $ */
> +/* $Id: zend_API.c,v 1.296.2.27.2.34.2.56 2008/11/24 18:10:12 stas Exp $ */
>  
>  #include "zend.h"
>  #include "zend_execute.h"
> @@ -295,7 +295,7 @@
>  {
>         char *spec_walk = *spec;
>         char c = *spec_walk++;
> -       int return_null = 0;
> +       int return_null = 0, obj_array = 0;
>  
>         /* scan through modifiers */
>         while (1) {
> @@ -451,7 +451,8 @@
>                                 }
>                         }
>                         break;
> -
> +               case 'A':
> +                               obj_array = 1;

You do not need this. Since in both case a/A and h/H you only test
it once you can at the same time check the case variable. That way
eliminating the need for the additional assignment that now always
happens. If you were winning any kind of maintenance I'd agree but
imo you only slow the code down and make it harder to read because
it got longer.

>                 case 'a':
>                         {
>                                 zval **p = va_arg(*va, zval **);
> @@ -459,14 +460,15 @@
>                                         *p = NULL;
>                                         break;
>                                 }
> -                               if (Z_TYPE_PP(arg) == IS_ARRAY) {
> +                               if (Z_TYPE_PP(arg) == IS_ARRAY ||
> (Z_TYPE_PP(arg) == IS_OBJECT && obj_array != 0)) {
>                                         *p = *arg;
>                                 } else {
>                                         return "array";
>                                 }
>                         }
>                         break;
> -
> +               case 'H':
> +                               obj_array = 1;
>                 case 'h':
>                         {
>                                 HashTable **p = va_arg(*va, HashTable **);
> @@ -476,6 +478,11 @@
>                                 }
>                                 if (Z_TYPE_PP(arg) == IS_ARRAY) {
>                                         *p = Z_ARRVAL_PP(arg);
> +                               } else if(obj_array && Z_TYPE_PP(arg) == IS_OBJECT) {
> +                                       *p = HASH_OF(*arg);
> +                                       if(*p == NULL) {
> +                                               return "array";
> +                                       }
>                                 } else {
>                                         return "array";
>                                 }
> @@ -670,7 +677,8 @@
>                         case 'o': case 'O':
>                         case 'z': case 'Z':
>                         case 'C': case 'h':
> -                       case 'f':
> +                       case 'f': case 'A':
> +                       case 'H':
>                                 max_num_args++;
>                                 break;
>  






Best regards,
 Marcus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.