@@ -119,36 +119,12 @@ ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_fun
119119}
120120/* }}} */
121121
122- typedef struct _zend_class_iterator_funcs_ptr {
123- zend_class_iterator_funcs * ptr ;
124- zend_class_iterator_funcs data ;
125- } zend_class_iterator_funcs_ptr ;
126-
127122/* iterator interface, c-level functions used by engine */
128- static zend_never_inline zend_class_iterator_funcs * zend_alloc_iterator_funcs_ptr (zend_class_entry * ce ) /* {{{ */
129- {
130- zend_class_iterator_funcs * ptr = zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs ));
131- memset (ptr , 0 , sizeof (zend_class_iterator_funcs ));
132- ZEND_MAP_PTR_SET (ce -> iterator_funcs_ptr , ptr );
133- return ptr ;
134- }
135- /* }}} */
136-
137- static zend_always_inline zend_class_iterator_funcs * zend_get_iterator_funcs_ptr (zend_class_entry * ce ) /* {{{ */
138- {
139- if (ZEND_MAP_PTR_GET (ce -> iterator_funcs_ptr )) {
140- return ZEND_MAP_PTR_GET (ce -> iterator_funcs_ptr );
141- } else {
142- return zend_alloc_iterator_funcs_ptr (ce );
143- }
144- }
145- /* }}} */
146123
147124/* {{{ zend_user_it_new_iterator */
148125ZEND_API void zend_user_it_new_iterator (zend_class_entry * ce , zval * object , zval * retval )
149126{
150- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
151- zend_call_method_with_0_params (object , ce , & iterator_funcs_ptr -> zf_new_iterator , "getiterator" , retval );
127+ zend_call_method_with_0_params (object , ce , & ce -> iterator_funcs_ptr -> zf_new_iterator , "getiterator" , retval );
152128}
153129/* }}} */
154130
@@ -183,10 +159,8 @@ ZEND_API int zend_user_it_valid(zend_object_iterator *_iter)
183159 zval * object = & iter -> it .data ;
184160 zval more ;
185161 int result ;
186- zend_class_entry * ce = iter -> ce ;
187- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
188162
189- zend_call_method_with_0_params (object , ce , & iterator_funcs_ptr -> zf_valid , "valid" , & more );
163+ zend_call_method_with_0_params (object , iter -> ce , & iter -> ce -> iterator_funcs_ptr -> zf_valid , "valid" , & more );
190164 result = i_zend_is_true (& more );
191165 zval_ptr_dtor (& more );
192166 return result ? SUCCESS : FAILURE ;
@@ -202,10 +176,7 @@ ZEND_API zval *zend_user_it_get_current_data(zend_object_iterator *_iter)
202176 zval * object = & iter -> it .data ;
203177
204178 if (Z_ISUNDEF (iter -> value )) {
205- zend_class_entry * ce = iter -> ce ;
206- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
207-
208- zend_call_method_with_0_params (object , ce , & iterator_funcs_ptr -> zf_current , "current" , & iter -> value );
179+ zend_call_method_with_0_params (object , iter -> ce , & iter -> ce -> iterator_funcs_ptr -> zf_current , "current" , & iter -> value );
209180 }
210181 return & iter -> value ;
211182}
@@ -217,10 +188,8 @@ ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *ke
217188 zend_user_iterator * iter = (zend_user_iterator * )_iter ;
218189 zval * object = & iter -> it .data ;
219190 zval retval ;
220- zend_class_entry * ce = iter -> ce ;
221- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
222191
223- zend_call_method_with_0_params (object , ce , & iterator_funcs_ptr -> zf_key , "key" , & retval );
192+ zend_call_method_with_0_params (object , iter -> ce , & iter -> ce -> iterator_funcs_ptr -> zf_key , "key" , & retval );
224193
225194 if (Z_TYPE (retval ) != IS_UNDEF ) {
226195 ZVAL_ZVAL (key , & retval , 1 , 1 );
@@ -239,11 +208,9 @@ ZEND_API void zend_user_it_move_forward(zend_object_iterator *_iter)
239208{
240209 zend_user_iterator * iter = (zend_user_iterator * )_iter ;
241210 zval * object = & iter -> it .data ;
242- zend_class_entry * ce = iter -> ce ;
243- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
244211
245212 zend_user_it_invalidate_current (_iter );
246- zend_call_method_with_0_params (object , ce , & iterator_funcs_ptr -> zf_next , "next" , NULL );
213+ zend_call_method_with_0_params (object , iter -> ce , & iter -> ce -> iterator_funcs_ptr -> zf_next , "next" , NULL );
247214}
248215/* }}} */
249216
@@ -252,11 +219,9 @@ ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter)
252219{
253220 zend_user_iterator * iter = (zend_user_iterator * )_iter ;
254221 zval * object = & iter -> it .data ;
255- zend_class_entry * ce = iter -> ce ;
256- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
257222
258223 zend_user_it_invalidate_current (_iter );
259- zend_call_method_with_0_params (object , ce , & iterator_funcs_ptr -> zf_rewind , "rewind" , NULL );
224+ zend_call_method_with_0_params (object , iter -> ce , & iter -> ce -> iterator_funcs_ptr -> zf_rewind , "rewind" , NULL );
260225}
261226/* }}} */
262227
@@ -347,7 +312,6 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
347312{
348313 uint32_t i ;
349314 int t = -1 ;
350- zend_class_iterator_funcs * iterator_funcs_ptr ;
351315
352316 if (class_type -> get_iterator ) {
353317 if (class_type -> type == ZEND_INTERNAL_CLASS ) {
@@ -376,40 +340,24 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
376340 }
377341 }
378342 class_type -> get_iterator = zend_user_it_get_new_iterator ;
379- if (ZEND_MAP_PTR (class_type -> iterator_funcs_ptr )) {
380- iterator_funcs_ptr = ZEND_MAP_PTR_GET (class_type -> iterator_funcs_ptr );
381- ZEND_ASSERT (iterator_funcs_ptr );
382- if (class_type -> type == ZEND_USER_CLASS ) {
383- iterator_funcs_ptr -> zf_new_iterator = NULL ;
384- return SUCCESS ;
385- }
343+ if (class_type -> iterator_funcs_ptr != NULL ) {
344+ class_type -> iterator_funcs_ptr -> zf_new_iterator = NULL ;
386345 } else if (class_type -> type == ZEND_INTERNAL_CLASS ) {
387- /* We can use pointer even in ZTS mode, because this structure is read-only */
388- zend_class_iterator_funcs_ptr * iterator_funcs_ptr_ptr =
389- calloc (1 , sizeof (zend_class_iterator_funcs_ptr ));
390- ZEND_MAP_PTR_INIT (class_type -> iterator_funcs_ptr , & iterator_funcs_ptr_ptr -> ptr );
391- iterator_funcs_ptr = & iterator_funcs_ptr_ptr -> data ;
392- iterator_funcs_ptr_ptr -> ptr = iterator_funcs_ptr ;
346+ class_type -> iterator_funcs_ptr = calloc (1 , sizeof (zend_class_iterator_funcs ));
393347 } else {
394- zend_class_iterator_funcs_ptr * iterator_funcs_ptr_ptr =
395- zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs_ptr ));
396- iterator_funcs_ptr_ptr -> ptr = & iterator_funcs_ptr_ptr -> data ;
397- ZEND_MAP_PTR_INIT (class_type -> iterator_funcs_ptr , & iterator_funcs_ptr_ptr -> ptr );
398- iterator_funcs_ptr = & iterator_funcs_ptr_ptr -> data ;
399- iterator_funcs_ptr_ptr -> ptr = iterator_funcs_ptr ;
400- memset (iterator_funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
401- return SUCCESS ;
348+ class_type -> iterator_funcs_ptr = zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs ));
349+ memset (class_type -> iterator_funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
350+ }
351+ if (class_type -> type == ZEND_INTERNAL_CLASS ) {
352+ class_type -> iterator_funcs_ptr -> zf_new_iterator = zend_hash_str_find_ptr (& class_type -> function_table , "getiterator" , sizeof ("getiterator" ) - 1 );
402353 }
403- iterator_funcs_ptr -> zf_new_iterator = zend_hash_str_find_ptr (& class_type -> function_table , "getiterator" , sizeof ("getiterator" ) - 1 );
404354 return SUCCESS ;
405355}
406356/* }}} */
407357
408358/* {{{ zend_implement_iterator */
409359static int zend_implement_iterator (zend_class_entry * interface , zend_class_entry * class_type )
410360{
411- zend_class_iterator_funcs * iterator_funcs_ptr ;
412-
413361 if (class_type -> get_iterator && class_type -> get_iterator != zend_user_it_get_iterator ) {
414362 if (class_type -> type == ZEND_INTERNAL_CLASS ) {
415363 /* inheritance ensures the class has the necessary userland methods */
@@ -426,39 +374,25 @@ static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry
426374 }
427375 }
428376 class_type -> get_iterator = zend_user_it_get_iterator ;
429- if (ZEND_MAP_PTR (class_type -> iterator_funcs_ptr )) {
430- iterator_funcs_ptr = ZEND_MAP_PTR_GET (class_type -> iterator_funcs_ptr );
431- ZEND_ASSERT (iterator_funcs_ptr );
432- if (class_type -> type == ZEND_USER_CLASS ) {
433- iterator_funcs_ptr -> zf_valid = NULL ;
434- iterator_funcs_ptr -> zf_current = NULL ;
435- iterator_funcs_ptr -> zf_key = NULL ;
436- iterator_funcs_ptr -> zf_next = NULL ;
437- iterator_funcs_ptr -> zf_rewind = NULL ;
438- return SUCCESS ;
439- }
377+ if (class_type -> iterator_funcs_ptr != NULL ) {
378+ class_type -> iterator_funcs_ptr -> zf_valid = NULL ;
379+ class_type -> iterator_funcs_ptr -> zf_current = NULL ;
380+ class_type -> iterator_funcs_ptr -> zf_key = NULL ;
381+ class_type -> iterator_funcs_ptr -> zf_next = NULL ;
382+ class_type -> iterator_funcs_ptr -> zf_rewind = NULL ;
440383 } else if (class_type -> type == ZEND_INTERNAL_CLASS ) {
441- /* We can use pointer even in ZTS mode, because this structure is read-only */
442- zend_class_iterator_funcs_ptr * iterator_funcs_ptr_ptr =
443- calloc (1 , sizeof (zend_class_iterator_funcs_ptr ));
444- ZEND_MAP_PTR_INIT (class_type -> iterator_funcs_ptr , & iterator_funcs_ptr_ptr -> ptr );
445- iterator_funcs_ptr = & iterator_funcs_ptr_ptr -> data ;
446- iterator_funcs_ptr_ptr -> ptr = iterator_funcs_ptr ;
384+ class_type -> iterator_funcs_ptr = calloc (1 , sizeof (zend_class_iterator_funcs ));
447385 } else {
448- zend_class_iterator_funcs_ptr * iterator_funcs_ptr_ptr =
449- zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs_ptr ));
450- iterator_funcs_ptr_ptr -> ptr = & iterator_funcs_ptr_ptr -> data ;
451- ZEND_MAP_PTR_INIT (class_type -> iterator_funcs_ptr , & iterator_funcs_ptr_ptr -> ptr );
452- iterator_funcs_ptr = & iterator_funcs_ptr_ptr -> data ;
453- iterator_funcs_ptr_ptr -> ptr = iterator_funcs_ptr ;
454- memset (iterator_funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
455- return SUCCESS ;
386+ class_type -> iterator_funcs_ptr = zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs ));
387+ memset (class_type -> iterator_funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
388+ }
389+ if (class_type -> type == ZEND_INTERNAL_CLASS ) {
390+ class_type -> iterator_funcs_ptr -> zf_rewind = zend_hash_str_find_ptr (& class_type -> function_table , "rewind" , sizeof ("rewind" ) - 1 );
391+ class_type -> iterator_funcs_ptr -> zf_valid = zend_hash_str_find_ptr (& class_type -> function_table , "valid" , sizeof ("valid" ) - 1 );
392+ class_type -> iterator_funcs_ptr -> zf_key = zend_hash_str_find_ptr (& class_type -> function_table , "key" , sizeof ("key" ) - 1 );
393+ class_type -> iterator_funcs_ptr -> zf_current = zend_hash_str_find_ptr (& class_type -> function_table , "current" , sizeof ("current" ) - 1 );
394+ class_type -> iterator_funcs_ptr -> zf_next = zend_hash_str_find_ptr (& class_type -> function_table , "next" , sizeof ("next" ) - 1 );
456395 }
457- iterator_funcs_ptr -> zf_rewind = zend_hash_str_find_ptr (& class_type -> function_table , "rewind" , sizeof ("rewind" ) - 1 );
458- iterator_funcs_ptr -> zf_valid = zend_hash_str_find_ptr (& class_type -> function_table , "valid" , sizeof ("valid" ) - 1 );
459- iterator_funcs_ptr -> zf_key = zend_hash_str_find_ptr (& class_type -> function_table , "key" , sizeof ("key" ) - 1 );
460- iterator_funcs_ptr -> zf_current = zend_hash_str_find_ptr (& class_type -> function_table , "current" , sizeof ("current" ) - 1 );
461- iterator_funcs_ptr -> zf_next = zend_hash_str_find_ptr (& class_type -> function_table , "next" , sizeof ("next" ) - 1 );
462396 return SUCCESS ;
463397}
464398/* }}} */
0 commit comments