]> granicus.if.org Git - php/commitdiff
Use new zend_hash API
authorDmitry Stogov <dmitry@zend.com>
Mon, 26 May 2014 20:38:58 +0000 (00:38 +0400)
committerDmitry Stogov <dmitry@zend.com>
Mon, 26 May 2014 20:38:58 +0000 (00:38 +0400)
Zend/zend_API.c
Zend/zend_builtin_functions.c
Zend/zend_execute.c
Zend/zend_list.c
Zend/zend_operators.c

index 01cdefcc133971a0749ecfeb6e5904fe5f563cfb..2bafa8586a7fb1d802a4fbae319298fdf08144a4 100644 (file)
@@ -1095,31 +1095,25 @@ ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC) /* {{{ */
 }
 /* }}} */
 
-static int zend_merge_property(zval *value TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
-{
-       /* which name should a numeric property have ? */
-       if (hash_key->key) {
-               zval *obj = va_arg(args, zval *);
-               zend_object_handlers *obj_ht = va_arg(args, zend_object_handlers *);
-               zval member;
-
-               ZVAL_STR(&member, STR_COPY(hash_key->key));
-               obj_ht->write_property(obj, &member, value, -1 TSRMLS_CC);
-               zval_ptr_dtor(&member);
-       }
-       return ZEND_HASH_APPLY_KEEP;
-}
-/* }}} */
-
 /* This function should be called after the constructor has been called
  * because it may call __set from the uninitialized object otherwise. */
 ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC) /* {{{ */
 {
        const zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj);
        zend_class_entry *old_scope = EG(scope);
+       zend_string *key;
+       zval *value;
 
        EG(scope) = Z_OBJCE_P(obj);
-       zend_hash_apply_with_arguments(properties TSRMLS_CC, zend_merge_property, 2, obj, obj_ht);
+       ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, value) {
+               if (key) {
+                       zval member;
+
+                       ZVAL_STR(&member, STR_COPY(key));
+                       obj_ht->write_property(obj, &member, value, -1 TSRMLS_CC);
+                       zval_ptr_dtor(&member);
+               }
+       } ZEND_HASH_FOREACH_END();
        EG(scope) = old_scope;
 
        if (destroy_ht) {
index e8e4c54e9cf0a9c531f0e0a2492d76cb46ab9f7d..cbbdd1e681b9ab87370b4f7ac8ac3997a43a5581 100644 (file)
@@ -582,7 +582,6 @@ ZEND_FUNCTION(each)
 {
        zval *array, *entry, tmp;
        ulong num_key;
-       zval *inserted_pointer;
        HashTable *target_hash;
        zend_string *key;
 
@@ -609,7 +608,8 @@ ZEND_FUNCTION(each)
                }
                break;
        }
-       array_init(return_value);
+       array_init_size(return_value, 4);
+       zend_hash_real_init(Z_ARRVAL_P(return_value), 0);
 
        /* add value elements */
        if (Z_ISREF_P(entry)) {
@@ -620,17 +620,18 @@ ZEND_FUNCTION(each)
                if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
                if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
        }
-       zend_hash_index_update(Z_ARRVAL_P(return_value), 1, entry);
+       zend_hash_index_add_new(Z_ARRVAL_P(return_value), 1, entry);
        zend_hash_str_add_new(Z_ARRVAL_P(return_value), "value", sizeof("value")-1, entry);
 
        /* add the key elements */
        if (zend_hash_get_current_key(target_hash, &key, &num_key, 0) == HASH_KEY_IS_STRING) {
-               inserted_pointer = add_get_index_str(return_value, 0, STR_COPY(key));
+               ZVAL_STR(&tmp, STR_COPY(key));
+               if (Z_REFCOUNTED(tmp)) Z_ADDREF(tmp);
        } else {
-               inserted_pointer = add_get_index_long(return_value, 0, num_key);
+               ZVAL_LONG(&tmp, num_key);
        }
-       zend_hash_str_add_new(Z_ARRVAL_P(return_value), "key", sizeof("key")-1, inserted_pointer);
-       if (Z_REFCOUNTED_P(inserted_pointer)) Z_ADDREF_P(inserted_pointer);
+       zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp);
+       zend_hash_str_add_new(Z_ARRVAL_P(return_value), "key", sizeof("key")-1, &tmp);
        zend_hash_move_forward(target_hash);
 }
 /* }}} */
index b360e6d75b17ab105beb571eb7cee5b15d967648..e0653f9b631be6bafaaa9ba103967d328d586b00 100644 (file)
@@ -1035,7 +1035,7 @@ num_index:
                                        zend_error(E_NOTICE,"Undefined offset: %ld", hval);
                                        /* break missing intentionally */
                                case BP_VAR_W:
-                                       retval = zend_hash_index_update(ht, hval, &EG(uninitialized_zval));
+                                       retval = zend_hash_index_add_new(ht, hval, &EG(uninitialized_zval));
                                        break;
                        }
                }
index fdd7ba86df954e67372c5c05584060768c9c903d..bb340ae4903496281875f26ba2287fd4ebf64b88 100644 (file)
@@ -41,7 +41,7 @@ ZEND_API zval *zend_list_insert(void *ptr, int type TSRMLS_DC)
                index = 1;
        }
        ZVAL_NEW_RES(&zv, index, ptr, type);
-       return zend_hash_index_update(&EG(regular_list), index, &zv);
+       return zend_hash_index_add_new(&EG(regular_list), index, &zv);
 }
 
 ZEND_API int _zend_list_delete(zend_resource *res TSRMLS_DC)
index 72ac9fca1ff97137ad4445a5c52da282fd40353e..393920237c6b06ed804252df89b58568292501ba 100644 (file)
@@ -650,7 +650,7 @@ static void convert_scalar_to_array(zval *op TSRMLS_DC) /* {{{ */
 
        ZVAL_NEW_ARR(op);
        zend_hash_init(Z_ARRVAL_P(op), 8, NULL, ZVAL_PTR_DTOR, 0);
-       zend_hash_index_update(Z_ARRVAL_P(op), 0, &entry);
+       zend_hash_index_add_new(Z_ARRVAL_P(op), 0, &entry);
 }
 /* }}} */