From: Dmitry Stogov Date: Fri, 19 Jan 2018 10:14:15 +0000 (+0300) Subject: Avoid useless duplication X-Git-Tag: php-7.3.0alpha1~575 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f349f3ab82965c2be784627e6ab2ed73093b708;p=php Avoid useless duplication --- diff --git a/Zend/zend.c b/Zend/zend.c index ba84f84def..f42a987542 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -732,8 +732,9 @@ static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */ { zval globals; + /* IS_TYPE_COPYABLE, but with ref-counter 1 and not IS_TYPE_REFCOUNTED */ ZVAL_ARR(&globals, &EG(symbol_table)); - Z_TYPE_INFO_P(&globals) = IS_ARRAY; + Z_TYPE_FLAGS_P(&globals) = IS_TYPE_COPYABLE; ZVAL_NEW_REF(&globals, &globals); zend_hash_update(&EG(symbol_table), name, &globals); return 0; diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index f98f11106b..01001f2da7 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1118,9 +1118,13 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar } if (Z_TYPE_P(array) == IS_ARRAY) { - //??? TODO: try to avoid array duplication zval_ptr_dtor(&intern->array); - ZVAL_DUP(&intern->array, array); + if (Z_REFCOUNT_P(array) == 1) { + ZVAL_COPY(&intern->array, array); + } else { + //??? TODO: try to avoid array duplication + ZVAL_ARR(&intern->array, zend_array_dup(Z_ARR_P(array))); + } } else { if (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject || Z_OBJ_HT_P(array) == &spl_handler_ArrayIterator) { zval_ptr_dtor(&intern->array);