Skip to content

Commit 6991780

Browse files
committed
Optimized FE_RESET and FE_FETCH
1 parent a7bfd00 commit 6991780

File tree

6 files changed

+496
-310
lines changed

6 files changed

+496
-310
lines changed

Zend/zend_hash.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,58 +1489,6 @@ ZEND_API zend_bool zend_hash_index_exists(const HashTable *ht, zend_ulong h)
14891489
}
14901490

14911491

1492-
ZEND_API zend_bool zend_hash_get_pointer(const HashTable *ht, HashPointer *ptr)
1493-
{
1494-
ptr->pos = ht->nInternalPointer;
1495-
ptr->ht = (HashTable*)ht;
1496-
if (ht->nInternalPointer != INVALID_IDX) {
1497-
ptr->h = ht->arData[ht->nInternalPointer].h;
1498-
return 1;
1499-
} else {
1500-
ptr->h = 0;
1501-
return 0;
1502-
}
1503-
}
1504-
1505-
ZEND_API zend_bool zend_hash_set_pointer(HashTable *ht, const HashPointer *ptr)
1506-
{
1507-
uint32_t idx;
1508-
1509-
if (ptr->pos == INVALID_IDX) {
1510-
ht->nInternalPointer = INVALID_IDX;
1511-
} else if (ptr->ht != ht) {
1512-
IS_CONSISTENT(ht);
1513-
for (idx = 0; idx < ht->nNumUsed; idx++) {
1514-
if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) {
1515-
ht->nInternalPointer = idx;
1516-
return 0;
1517-
}
1518-
}
1519-
idx = INVALID_IDX;
1520-
return 0;
1521-
} else if (ht->nInternalPointer != ptr->pos) {
1522-
IS_CONSISTENT(ht);
1523-
if (ht->u.flags & HASH_FLAG_PACKED) {
1524-
if (ptr->h < ht->nNumUsed &&
1525-
Z_TYPE(ht->arData[ptr->h].val) != IS_UNDEF) {
1526-
ht->nInternalPointer = ptr->h;
1527-
return 1;
1528-
}
1529-
} else {
1530-
idx = ht->arHash[ptr->h & ht->nTableMask];
1531-
while (idx != INVALID_IDX) {
1532-
if (ht->arData[idx].h == ptr->h && idx == ptr->pos) {
1533-
ht->nInternalPointer = idx;
1534-
return 1;
1535-
}
1536-
idx = Z_NEXT(ht->arData[idx].val);
1537-
}
1538-
}
1539-
return 0;
1540-
}
1541-
return 1;
1542-
}
1543-
15441492
ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos)
15451493
{
15461494
uint32_t idx;

Zend/zend_hash.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ typedef struct _HashPointer {
177177
zend_ulong h;
178178
} HashPointer;
179179

180-
ZEND_API zend_bool zend_hash_get_pointer(const HashTable *ht, HashPointer *ptr);
181-
ZEND_API zend_bool zend_hash_set_pointer(HashTable *ht, const HashPointer *ptr);
182-
183180
#define zend_hash_has_more_elements(ht) \
184181
zend_hash_has_more_elements_ex(ht, &(ht)->nInternalPointer)
185182
#define zend_hash_move_forward(ht) \

Zend/zend_iterators.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,13 @@ ZEND_API void zend_iterator_dtor(zend_object_iterator *iter TSRMLS_DC)
8484
zend_objects_store_del(&iter->std TSRMLS_CC);
8585
}
8686

87-
ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(
88-
zval *array_ptr, zend_object_iterator **iter TSRMLS_DC)
87+
ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr TSRMLS_DC)
8988
{
90-
switch (Z_TYPE_P(array_ptr)) {
91-
case IS_OBJECT:
92-
if (Z_OBJ_HT_P(array_ptr) == &iterator_object_handlers) {
93-
*iter = (zend_object_iterator *)Z_OBJ_P(array_ptr);
94-
return ZEND_ITER_OBJECT;
95-
}
96-
if (Z_OBJPROP_P(array_ptr)) {
97-
return ZEND_ITER_PLAIN_OBJECT;
98-
}
99-
return ZEND_ITER_INVALID;
100-
101-
case IS_ARRAY:
102-
if (Z_ARRVAL_P(array_ptr)) {
103-
return ZEND_ITER_PLAIN_ARRAY;
104-
}
105-
return ZEND_ITER_INVALID;
106-
107-
default:
108-
return ZEND_ITER_INVALID;
89+
if (Z_TYPE_P(array_ptr) &&
90+
Z_OBJ_HT_P(array_ptr) == &iterator_object_handlers) {
91+
return (zend_object_iterator *)Z_OBJ_P(array_ptr);
10992
}
93+
return NULL;
11094
}
11195

11296
/*

Zend/zend_iterators.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,9 @@ typedef struct _zend_class_iterator_funcs {
7171
union _zend_function *zf_rewind;
7272
} zend_class_iterator_funcs;
7373

74-
enum zend_object_iterator_kind {
75-
ZEND_ITER_INVALID,
76-
ZEND_ITER_PLAIN_ARRAY,
77-
ZEND_ITER_PLAIN_OBJECT,
78-
ZEND_ITER_OBJECT
79-
};
80-
8174
BEGIN_EXTERN_C()
8275
/* given a zval, returns stuff that can be used to iterate it. */
83-
ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(zval *array_ptr, zend_object_iterator **iter TSRMLS_DC);
76+
ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr TSRMLS_DC);
8477

8578
/* given an iterator, wrap it up as a zval for use by the engine opcodes */
8679
ZEND_API void zend_iterator_init(zend_object_iterator *iter TSRMLS_DC);

0 commit comments

Comments
 (0)