Skip to content

Commit 5659035

Browse files
committed
Remove unnecessary get_hash_table return value checks
An ArrayObject always has a valid backing hashtable, this function can never return NULL.
1 parent a27f772 commit 5659035

File tree

1 file changed

+2
-90
lines changed

1 file changed

+2
-90
lines changed

ext/spl/spl_array.c

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -697,23 +697,6 @@ static int spl_array_has_dimension(zval *object, zval *offset, int check_empty)
697697
return spl_array_has_dimension_ex(1, object, offset, check_empty);
698698
} /* }}} */
699699

700-
/* {{{ spl_array_object_verify_pos_ex */
701-
static inline int spl_array_object_verify_pos_ex(spl_array_object *object, HashTable *ht, const char *msg_prefix)
702-
{
703-
if (!ht) {
704-
php_error_docref(NULL, E_NOTICE, "%sArray was modified outside object and is no longer an array", msg_prefix);
705-
return FAILURE;
706-
}
707-
708-
return SUCCESS;
709-
} /* }}} */
710-
711-
/* {{{ spl_array_object_verify_pos */
712-
static inline int spl_array_object_verify_pos(spl_array_object *object, HashTable *ht)
713-
{
714-
return spl_array_object_verify_pos_ex(object, ht, "");
715-
} /* }}} */
716-
717700
/* {{{ proto bool ArrayObject::offsetExists(mixed $index)
718701
proto bool ArrayIterator::offsetExists(mixed $index)
719702
Returns whether the requested $index exists. */
@@ -756,12 +739,6 @@ SPL_METHOD(Array, offsetSet)
756739
void spl_array_iterator_append(zval *object, zval *append_value) /* {{{ */
757740
{
758741
spl_array_object *intern = Z_SPLARRAY_P(object);
759-
HashTable *aht = spl_array_get_hash_table(intern);
760-
761-
if (!aht) {
762-
php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
763-
return;
764-
}
765742

766743
if (spl_array_is_object(intern)) {
767744
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) /* {{{ */
10361013
if (object->ar_flags & SPL_ARRAY_OVERLOADED_VALID) {
10371014
return zend_user_it_valid(iter);
10381015
} else {
1039-
if (spl_array_object_verify_pos_ex(object, aht, "ArrayIterator::valid(): ") == FAILURE) {
1040-
return FAILURE;
1041-
}
1042-
10431016
return zend_hash_has_more_elements_ex(aht, spl_array_get_pos_ptr(aht, object));
10441017
}
10451018
}
@@ -1070,11 +1043,7 @@ static void spl_array_it_get_current_key(zend_object_iterator *iter, zval *key)
10701043
if (object->ar_flags & SPL_ARRAY_OVERLOADED_KEY) {
10711044
zend_user_it_get_current_key(iter, key);
10721045
} else {
1073-
if (spl_array_object_verify_pos_ex(object, aht, "ArrayIterator::current(): ") == FAILURE) {
1074-
ZVAL_NULL(key);
1075-
} else {
1076-
zend_hash_get_current_key_zval_ex(aht, key, spl_array_get_pos_ptr(aht, object));
1077-
}
1046+
zend_hash_get_current_key_zval_ex(aht, key, spl_array_get_pos_ptr(aht, object));
10781047
}
10791048
}
10801049
/* }}} */
@@ -1088,11 +1057,6 @@ static void spl_array_it_move_forward(zend_object_iterator *iter) /* {{{ */
10881057
zend_user_it_move_forward(iter);
10891058
} else {
10901059
zend_user_it_invalidate_current(iter);
1091-
if (!aht) {
1092-
php_error_docref(NULL, E_NOTICE, "ArrayIterator::current(): Array was modified outside object and is no longer an array");
1093-
return;
1094-
}
1095-
10961060
spl_array_next_ex(object, aht);
10971061
}
10981062
}
@@ -1102,11 +1066,6 @@ static void spl_array_rewind(spl_array_object *intern) /* {{{ */
11021066
{
11031067
HashTable *aht = spl_array_get_hash_table(intern);
11041068

1105-
if (!aht) {
1106-
php_error_docref(NULL, E_NOTICE, "ArrayIterator::rewind(): Array was modified outside object and is no longer an array");
1107-
return;
1108-
}
1109-
11101069
if (intern->ht_iter == (uint32_t)-1) {
11111070
spl_array_get_pos_ptr(aht, intern);
11121071
} else {
@@ -1356,17 +1315,11 @@ SPL_METHOD(Array, getIterator)
13561315
{
13571316
zval *object = getThis();
13581317
spl_array_object *intern = Z_SPLARRAY_P(object);
1359-
HashTable *aht = spl_array_get_hash_table(intern);
13601318

13611319
if (zend_parse_parameters_none() == FAILURE) {
13621320
return;
13631321
}
13641322

1365-
if (!aht) {
1366-
php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
1367-
return;
1368-
}
1369-
13701323
ZVAL_OBJ(return_value, spl_array_object_new_ex(intern->ce_get_iterator, object, 0));
13711324
}
13721325
/* }}} */
@@ -1400,11 +1353,6 @@ SPL_METHOD(Array, seek)
14001353
return;
14011354
}
14021355

1403-
if (!aht) {
1404-
php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
1405-
return;
1406-
}
1407-
14081356
opos = position;
14091357

14101358
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
14251373
HashTable *aht = spl_array_get_hash_table(intern);
14261374
HashPosition pos, *pos_ptr;
14271375

1428-
if (!aht) {
1429-
php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
1430-
*count = 0;
1431-
return FAILURE;
1432-
}
1433-
14341376
if (spl_array_is_object(intern)) {
14351377
/* We need to store the 'pos' since we'll modify it in the functions
14361378
* we're going to call and which do not support 'pos' as parameter. */
@@ -1584,10 +1526,6 @@ SPL_METHOD(Array, current)
15841526
return;
15851527
}
15861528

1587-
if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
1588-
return;
1589-
}
1590-
15911529
if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
15921530
return;
15931531
}
@@ -1617,10 +1555,6 @@ void spl_array_iterator_key(zval *object, zval *return_value) /* {{{ */
16171555
spl_array_object *intern = Z_SPLARRAY_P(object);
16181556
HashTable *aht = spl_array_get_hash_table(intern);
16191557

1620-
if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
1621-
return;
1622-
}
1623-
16241558
zend_hash_get_current_key_zval_ex(aht, return_value, spl_array_get_pos_ptr(aht, intern));
16251559
}
16261560
/* }}} */
@@ -1637,10 +1571,6 @@ SPL_METHOD(Array, next)
16371571
return;
16381572
}
16391573

1640-
if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
1641-
return;
1642-
}
1643-
16441574
spl_array_next_ex(intern, aht);
16451575
}
16461576
/* }}} */
@@ -1657,11 +1587,7 @@ SPL_METHOD(Array, valid)
16571587
return;
16581588
}
16591589

1660-
if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
1661-
RETURN_FALSE;
1662-
} else {
1663-
RETURN_BOOL(zend_hash_has_more_elements_ex(aht, spl_array_get_pos_ptr(aht, intern)) == SUCCESS);
1664-
}
1590+
RETURN_BOOL(zend_hash_has_more_elements_ex(aht, spl_array_get_pos_ptr(aht, intern)) == SUCCESS);
16651591
}
16661592
/* }}} */
16671593

@@ -1677,10 +1603,6 @@ SPL_METHOD(Array, hasChildren)
16771603
return;
16781604
}
16791605

1680-
if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
1681-
RETURN_FALSE;
1682-
}
1683-
16841606
if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
16851607
RETURN_FALSE;
16861608
}
@@ -1706,10 +1628,6 @@ SPL_METHOD(Array, getChildren)
17061628
return;
17071629
}
17081630

1709-
if (spl_array_object_verify_pos(intern, aht) == FAILURE) {
1710-
return;
1711-
}
1712-
17131631
if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
17141632
return;
17151633
}
@@ -1741,7 +1659,6 @@ SPL_METHOD(Array, serialize)
17411659
{
17421660
zval *object = getThis();
17431661
spl_array_object *intern = Z_SPLARRAY_P(object);
1744-
HashTable *aht = spl_array_get_hash_table(intern);
17451662
zval members, flags;
17461663
php_serialize_data_t var_hash;
17471664
smart_str buf = {0};
@@ -1750,11 +1667,6 @@ SPL_METHOD(Array, serialize)
17501667
return;
17511668
}
17521669

1753-
if (!aht) {
1754-
php_error_docref(NULL, E_NOTICE, "Array was modified outside object and is no longer an array");
1755-
return;
1756-
}
1757-
17581670
PHP_VAR_SERIALIZE_INIT(var_hash);
17591671

17601672
ZVAL_LONG(&flags, (intern->ar_flags & SPL_ARRAY_CLONE_MASK));

0 commit comments

Comments
 (0)