cvs: php4 /ext/wddx wddx.c

From: Date: Fri, 16 Jun 2000 14:11:01 +0000
Subject: cvs: php4 /ext/wddx wddx.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-311@lists.php.net to get a copy of this message
thies Fri Jun 16 07:11:01 2000 EDT Modified files: /php4/ext/wddx wddx.c Log: @- Changed WDDX to serialize arrays as structs only if needed. (Thies) Index: php4/ext/wddx/wddx.c diff -u php4/ext/wddx/wddx.c:1.37 php4/ext/wddx/wddx.c:1.38 --- php4/ext/wddx/wddx.c:1.37 Fri Jun 9 06:50:39 2000 +++ php4/ext/wddx/wddx.c Fri Jun 16 07:11:01 2000 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: wddx.c,v 1.37 2000/06/09 13:50:39 andrei Exp $ */ +/* $Id: wddx.c,v 1.38 2000/06/16 14:11:01 thies Exp $ */ #include "php.h" #include "php_wddx.h" @@ -385,21 +385,52 @@ { zval **ent; char *key; + int is_struct = 0, ent_type; ulong idx; HashTable *target_hash; char tmp_buf[WDDX_BUF_LEN]; target_hash = HASH_OF(var); - php_wddx_add_chunk_static(packet, WDDX_STRUCT_S); /* If variable is an object, always use struct and serialize its classname */ if (var->type == IS_OBJECT) { + php_wddx_add_chunk_static(packet, WDDX_STRUCT_S); sprintf(tmp_buf, WDDX_VAR_S, PHP_CLASS_NAME_VAR); php_wddx_add_chunk(packet, tmp_buf); php_wddx_add_chunk_static(packet, WDDX_STRING_S); php_wddx_add_chunk_ex(packet, var->value.obj.ce->name, var->value.obj.ce->name_length); php_wddx_add_chunk_static(packet, WDDX_STRING_E); php_wddx_add_chunk_static(packet, WDDX_VAR_E); + is_struct = 1; + } else { + int ind = 0,type; + + for (zend_hash_internal_pointer_reset(target_hash); + zend_hash_get_current_data(target_hash, (void**)&ent) == SUCCESS; + zend_hash_move_forward(target_hash)) { + + type = zend_hash_get_current_key(target_hash, &key, &idx); + + if (type == HASH_KEY_IS_STRING) { + is_struct = 1; + efree(key); + break; + } + + if (idx != ind) { + is_struct = 1; + break; + } + + ind++; + } + + if (is_struct) { + php_wddx_add_chunk_static(packet, WDDX_STRUCT_S); + } else { + sprintf(tmp_buf, WDDX_ARRAY_S, zend_hash_num_elements(target_hash)); + php_wddx_add_chunk(packet, tmp_buf); + } } for (zend_hash_internal_pointer_reset(target_hash); @@ -408,16 +439,25 @@ if (*ent == var) continue; - if (zend_hash_get_current_key(target_hash, &key, &idx) == HASH_KEY_IS_STRING) { - php_wddx_serialize_var(packet, *ent, key); - efree(key); - } else { - sprintf(tmp_buf, "%ld", idx); - php_wddx_serialize_var(packet, *ent, tmp_buf); - } + if (is_struct) { + ent_type = zend_hash_get_current_key(target_hash, &key, &idx); + + if (ent_type == HASH_KEY_IS_STRING) { + php_wddx_serialize_var(packet, *ent, key); + efree(key); + } else { + sprintf(tmp_buf, "%ld", idx); + php_wddx_serialize_var(packet, *ent, tmp_buf); + } + } else + php_wddx_serialize_var(packet, *ent, NULL); } - php_wddx_add_chunk_static(packet, WDDX_STRUCT_E); + if (is_struct) { + php_wddx_add_chunk_static(packet, WDDX_STRUCT_E); + } else { + php_wddx_add_chunk_static(packet, WDDX_ARRAY_E); + } } /* }}} */

« previous php.cvs (#311) next »