]> granicus.if.org Git - php/commitdiff
Remove unnecessary get_hash_table return value checks
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Oct 2018 13:06:11 +0000 (15:06 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Oct 2018 13:06:11 +0000 (15:06 +0200)
An ArrayObject always has a valid backing hashtable, this function
can never return NULL.

ext/spl/spl_array.c

index e2b3ee410858ed9645fa7caa5b3ed3f961373720..02e297fa1fd7135b346eb416d34c358d28094306 100644 (file)
@@ -697,23 +697,6 @@ static int spl_array_has_dimension(zval *object, zval *offset, int check_empty)
        return spl_array_has_dimension_ex(1, object, offset, check_empty);
 } /* }}} */
 
-/* {{{ spl_array_object_verify_pos_ex */
-static inline int spl_array_object_verify_pos_ex(spl_array_object *object, HashTable *ht, const char *msg_prefix)
-{
-       if (!ht) {
-               php_error_docref(NULL, E_NOTICE, "%sArray was modified outside object and is no longer an array", msg_prefix);
-               return FAILURE;
-       }
-
-       return SUCCESS;
-} /* }}} */
-
-/* {{{ spl_array_object_verify_pos */
-static inline int spl_array_object_verify_pos(spl_array_object *object, HashTable *ht)
-{
-       return spl_array_object_verify_pos_ex(object, ht, "");
-} /* }}} */
-
 /* {{{ proto bool ArrayObject::offsetExists(mixed $index)
        proto bool ArrayIterator::offsetExists(mixed $index)
    Returns whether the requested $index exists. */
@@ -756,12 +739,6 @@ SPL_METHOD(Array, offsetSet)
 void spl_array_iterator_append(zval *object, zval *append_value) /* {{{ */
 {
        spl_array_object *intern = Z_SPLARRAY_P(object);
-       HashTable *aht = spl_array_get_hash_table(intern);
-
-       if (!aht) {
-               php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
-               return;
-       }
 
        if (spl_array_is_object(intern)) {
                zend_throw_error(NULL, "Cannot append properties to objects, use %s::offsetSet() instead", ZSTR_VAL(Z_OBJCE_P(object)->name));
@@ -1036,10 +1013,6 @@ static int spl_array_it_valid(zend_object_iterator *iter) /* {{{ */
        if (object->ar_flags & SPL_ARRAY_OVERLOADED_VALID) {
                return zend_user_it_valid(iter);
        } else {
-               if (spl_array_object_verify_pos_ex(object, aht, "ArrayIterator::valid(): ") == FAILURE) {
-                       return FAILURE;
-               }
-
                return zend_hash_has_more_elements_ex(aht, spl_array_get_pos_ptr(aht, object));
        }
 }
@@ -1070,11 +1043,7 @@ static void spl_array_it_get_current_key(zend_object_iterator *iter, zval *key)
        if (object->ar_flags & SPL_ARRAY_OVERLOADED_KEY) {
                zend_user_it_get_current_key(iter, key);
        } else {
-               if (spl_array_object_verify_pos_ex(object, aht, "ArrayIterator::current(): ") == FAILURE) {
-                       ZVAL_NULL(key);
-               } else {
-                       zend_hash_get_current_key_zval_ex(aht, key, spl_array_get_pos_ptr(aht, object));
-               }
+               zend_hash_get_current_key_zval_ex(aht, key, spl_array_get_pos_ptr(aht, object));
        }
 }
 /* }}} */
@@ -1088,11 +1057,6 @@ static void spl_array_it_move_forward(zend_object_iterator *iter) /* {{{ */
                zend_user_it_move_forward(iter);
        } else {
                zend_user_it_invalidate_current(iter);
-               if (!aht) {
-                       php_error_docref(NULL, E_NOTICE, "ArrayIterator::current(): Array was modified outside object and is no longer an array");
-                       return;
-               }
-
                spl_array_next_ex(object, aht);
        }
 }
@@ -1102,11 +1066,6 @@ static void spl_array_rewind(spl_array_object *intern) /* {{{ */
 {
        HashTable *aht = spl_array_get_hash_table(intern);
 
-       if (!aht) {
-               php_error_docref(NULL, E_NOTICE, "ArrayIterator::rewind(): Array was modified outside object and is no longer an array");
-               return;
-       }
-
        if (intern->ht_iter == (uint32_t)-1) {
                spl_array_get_pos_ptr(aht, intern);
        } else {
@@ -1356,17 +1315,11 @@ SPL_METHOD(Array, getIterator)
 {
        zval *object = getThis();
        spl_array_object *intern = Z_SPLARRAY_P(object);
-       HashTable *aht = spl_array_get_hash_table(intern);
 
        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
 
-       if (!aht) {
-               php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
-               return;
-       }
-
        ZVAL_OBJ(return_value, spl_array_object_new_ex(intern->ce_get_iterator, object, 0));
 }
 /* }}} */
@@ -1400,11 +1353,6 @@ SPL_METHOD(Array, seek)
                return;
        }
 
-       if (!aht) {
-               php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
-               return;
-       }
-
        opos = position;
 
        if (position >= 0) { /* negative values are not supported */
@@ -1425,12 +1373,6 @@ static int spl_array_object_count_elements_helper(spl_array_object *intern, zend
        HashTable *aht = spl_array_get_hash_table(intern);
        HashPosition pos, *pos_ptr;
 
-       if (!aht) {
-               php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
-               *count = 0;
-               return FAILURE;
-       }
-
        if (spl_array_is_object(intern)) {
                /* We need to store the 'pos' since we'll modify it in the functions
                 * we're going to call and which do not support 'pos' as parameter. */
@@ -1584,10 +1526,6 @@ SPL_METHOD(Array, current)
                return;
        }
 
-       if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
-               return;
-       }
-
        if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
                return;
        }
@@ -1617,10 +1555,6 @@ void spl_array_iterator_key(zval *object, zval *return_value) /* {{{ */
        spl_array_object *intern = Z_SPLARRAY_P(object);
        HashTable *aht = spl_array_get_hash_table(intern);
 
-       if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
-               return;
-       }
-
        zend_hash_get_current_key_zval_ex(aht, return_value, spl_array_get_pos_ptr(aht, intern));
 }
 /* }}} */
@@ -1637,10 +1571,6 @@ SPL_METHOD(Array, next)
                return;
        }
 
-       if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
-               return;
-       }
-
        spl_array_next_ex(intern, aht);
 }
 /* }}} */
@@ -1657,11 +1587,7 @@ SPL_METHOD(Array, valid)
                return;
        }
 
-       if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
-               RETURN_FALSE;
-       } else {
-               RETURN_BOOL(zend_hash_has_more_elements_ex(aht, spl_array_get_pos_ptr(aht, intern)) == SUCCESS);
-       }
+       RETURN_BOOL(zend_hash_has_more_elements_ex(aht, spl_array_get_pos_ptr(aht, intern)) == SUCCESS);
 }
 /* }}} */
 
@@ -1677,10 +1603,6 @@ SPL_METHOD(Array, hasChildren)
                return;
        }
 
-       if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
-               RETURN_FALSE;
-       }
-
        if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
                RETURN_FALSE;
        }
@@ -1706,10 +1628,6 @@ SPL_METHOD(Array, getChildren)
                return;
        }
 
-       if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
-               return;
-       }
-
        if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
                return;
        }
@@ -1741,7 +1659,6 @@ SPL_METHOD(Array, serialize)
 {
        zval *object = getThis();
        spl_array_object *intern = Z_SPLARRAY_P(object);
-       HashTable *aht = spl_array_get_hash_table(intern);
        zval members, flags;
        php_serialize_data_t var_hash;
        smart_str buf = {0};
@@ -1750,11 +1667,6 @@ SPL_METHOD(Array, serialize)
                return;
        }
 
-       if (!aht) {
-               php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
-               return;
-       }
-
        PHP_VAR_SERIALIZE_INIT(var_hash);
 
        ZVAL_LONG(&flags, (intern->ar_flags & SPL_ARRAY_CLONE_MASK));