summaryrefslogtreecommitdiff
path: root/ext/spl
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2018-03-22 02:41:49 +0300
committerDmitry Stogov <dmitry@zend.com>2018-03-22 02:41:49 +0300
commitd7f2dc4ec651628e10213625db6aee3559e214a9 (patch)
tree1f5a570cf9c6d101c4e59f9ab0b6ce61abc9339c /ext/spl
parent88b42338b324c50cc9d2f145df949e4e2cc82ae7 (diff)
downloadphp-git-d7f2dc4ec651628e10213625db6aee3559e214a9.tar.gz
Improve HashTable iterators handling:
- Avoid iterators check/update on each HashTable update opration - Keep position equal (or above) nNumUsed instead of HT_INVALID_IDX - Fixed iterators handling in array_unshift()
Diffstat (limited to 'ext/spl')
-rw-r--r--ext/spl/spl_array.c4
-rw-r--r--ext/spl/spl_observer.c2
2 files changed, 3 insertions, 3 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index d0a1f68215..3135f82f81 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -134,7 +134,7 @@ static int spl_array_skip_protected(spl_array_object *intern, HashTable *aht);
static zend_never_inline void spl_array_create_ht_iter(HashTable *ht, spl_array_object* intern) /* {{{ */
{
- intern->ht_iter = zend_hash_iterator_add(ht, ht->nInternalPointer);
+ intern->ht_iter = zend_hash_iterator_add(ht, zend_hash_get_current_pos(ht));
zend_hash_internal_pointer_reset_ex(ht, &EG(ht_iterators)[intern->ht_iter].pos);
spl_array_skip_protected(intern, ht);
}
@@ -1419,7 +1419,7 @@ static int spl_array_object_count_elements_helper(spl_array_object *intern, zend
pos = *pos_ptr;
*count = 0;
spl_array_rewind(intern);
- while (*pos_ptr != HT_INVALID_IDX && spl_array_next(intern) == SUCCESS) {
+ while (*pos_ptr < aht->nNumUsed && spl_array_next(intern) == SUCCESS) {
(*count)++;
}
*pos_ptr = pos;
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index 295f7765d2..1c3911a25e 100644
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -234,7 +234,7 @@ static zend_object *spl_object_storage_new_ex(zend_class_entry *class_type, zval
intern = emalloc(sizeof(spl_SplObjectStorage) + zend_object_properties_size(parent));
memset(intern, 0, sizeof(spl_SplObjectStorage) - sizeof(zval));
- intern->pos = HT_INVALID_IDX;
+ intern->pos = 0;
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);