@@ -56,13 +56,9 @@ typedef struct _spl_fixedarray_object { /* {{{ */
56
56
zend_function * fptr_offset_set ;
57
57
zend_function * fptr_offset_has ;
58
58
zend_function * fptr_offset_del ;
59
- zend_function * fptr_it_next ;
60
- zend_function * fptr_it_rewind ;
61
- zend_function * fptr_it_current ;
62
- zend_function * fptr_it_key ;
63
- zend_function * fptr_it_valid ;
64
59
zend_function * fptr_count ;
65
60
int current ;
61
+ int flags ;
66
62
zend_class_entry * ce_get_iterator ;
67
63
} spl_fixedarray_object ;
68
64
/* }}} */
@@ -73,6 +69,12 @@ typedef struct _spl_fixedarray_it { /* {{{ */
73
69
} spl_fixedarray_it ;
74
70
/* }}} */
75
71
72
+ #define SPL_FIXEDARRAY_OVERLOADED_REWIND 0x0001
73
+ #define SPL_FIXEDARRAY_OVERLOADED_VALID 0x0002
74
+ #define SPL_FIXEDARRAY_OVERLOADED_KEY 0x0004
75
+ #define SPL_FIXEDARRAY_OVERLOADED_CURRENT 0x0008
76
+ #define SPL_FIXEDARRAY_OVERLOADED_NEXT 0x0010
77
+
76
78
static void spl_fixedarray_init (spl_fixedarray * array , long size TSRMLS_DC ) /* {{{ */
77
79
{
78
80
if (size > 0 ) {
@@ -209,6 +211,7 @@ static zend_object_value spl_fixedarray_object_new_ex(zend_class_entry *class_ty
209
211
zend_hash_copy (intern -> std .properties , & class_type -> default_properties , (copy_ctor_func_t ) zval_add_ref , (void * ) & tmp , sizeof (zval * ));
210
212
211
213
intern -> current = 0 ;
214
+ intern -> flags = 0 ;
212
215
213
216
if (orig && clone_orig ) {
214
217
spl_fixedarray_object * other = (spl_fixedarray_object * )zend_object_store_get_object (orig TSRMLS_CC );
@@ -222,6 +225,7 @@ static zend_object_value spl_fixedarray_object_new_ex(zend_class_entry *class_ty
222
225
while (parent ) {
223
226
if (parent == spl_ce_SplFixedArray ) {
224
227
retval .handlers = & spl_handler_SplFixedArray ;
228
+ class_type -> get_iterator = spl_fixedarray_get_iterator ;
225
229
break ;
226
230
}
227
231
@@ -234,7 +238,30 @@ static zend_object_value spl_fixedarray_object_new_ex(zend_class_entry *class_ty
234
238
if (!parent ) { /* this must never happen */
235
239
php_error_docref (NULL TSRMLS_CC , E_COMPILE_ERROR , "Internal compiler error, Class is not child of SplFixedArray" );
236
240
}
241
+ if (!class_type -> iterator_funcs .zf_current ) {
242
+ zend_hash_find (& class_type -> function_table , "rewind" , sizeof ("rewind" ), (void * * ) & class_type -> iterator_funcs .zf_rewind );
243
+ zend_hash_find (& class_type -> function_table , "valid" , sizeof ("valid" ), (void * * ) & class_type -> iterator_funcs .zf_valid );
244
+ zend_hash_find (& class_type -> function_table , "key" , sizeof ("key" ), (void * * ) & class_type -> iterator_funcs .zf_key );
245
+ zend_hash_find (& class_type -> function_table , "current" , sizeof ("current" ), (void * * ) & class_type -> iterator_funcs .zf_current );
246
+ zend_hash_find (& class_type -> function_table , "next" , sizeof ("next" ), (void * * ) & class_type -> iterator_funcs .zf_next );
247
+ }
237
248
if (inherited ) {
249
+ if (class_type -> iterator_funcs .zf_rewind -> common .scope != parent ) {
250
+ intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_REWIND ;
251
+ }
252
+ if (class_type -> iterator_funcs .zf_valid -> common .scope != parent ) {
253
+ intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_VALID ;
254
+ }
255
+ if (class_type -> iterator_funcs .zf_key -> common .scope != parent ) {
256
+ intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_KEY ;
257
+ }
258
+ if (class_type -> iterator_funcs .zf_current -> common .scope != parent ) {
259
+ intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_CURRENT ;
260
+ }
261
+ if (class_type -> iterator_funcs .zf_next -> common .scope != parent ) {
262
+ intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT ;
263
+ }
264
+
238
265
zend_hash_find (& class_type -> function_table , "offsetget" , sizeof ("offsetget" ), (void * * ) & intern -> fptr_offset_get );
239
266
if (intern -> fptr_offset_get -> common .scope == parent ) {
240
267
intern -> fptr_offset_get = NULL ;
@@ -251,26 +278,6 @@ static zend_object_value spl_fixedarray_object_new_ex(zend_class_entry *class_ty
251
278
if (intern -> fptr_offset_del -> common .scope == parent ) {
252
279
intern -> fptr_offset_del = NULL ;
253
280
}
254
- zend_hash_find (& class_type -> function_table , "next" , sizeof ("next" ), (void * * ) & intern -> fptr_it_next );
255
- if (intern -> fptr_it_next -> common .scope == parent ) {
256
- intern -> fptr_it_next = NULL ;
257
- }
258
- zend_hash_find (& class_type -> function_table , "rewind" , sizeof ("rewind" ), (void * * ) & intern -> fptr_it_rewind );
259
- if (intern -> fptr_it_rewind -> common .scope == parent ) {
260
- intern -> fptr_it_rewind = NULL ;
261
- }
262
- zend_hash_find (& class_type -> function_table , "current" , sizeof ("current" ), (void * * ) & intern -> fptr_it_current );
263
- if (intern -> fptr_it_current -> common .scope == parent ) {
264
- intern -> fptr_it_current = NULL ;
265
- }
266
- zend_hash_find (& class_type -> function_table , "key" , sizeof ("key" ), (void * * ) & intern -> fptr_it_key );
267
- if (intern -> fptr_it_key -> common .scope == parent ) {
268
- intern -> fptr_it_key = NULL ;
269
- }
270
- zend_hash_find (& class_type -> function_table , "valid" , sizeof ("valid" ), (void * * ) & intern -> fptr_it_valid );
271
- if (intern -> fptr_it_valid -> common .scope == parent ) {
272
- intern -> fptr_it_valid = NULL ;
273
- }
274
281
zend_hash_find (& class_type -> function_table , "count" , sizeof ("count" ), (void * * ) & intern -> fptr_count );
275
282
if (intern -> fptr_count -> common .scope == parent ) {
276
283
intern -> fptr_count = NULL ;
@@ -822,31 +829,22 @@ static void spl_fixedarray_it_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{
822
829
{
823
830
spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
824
831
spl_fixedarray_object * intern = iterator -> object ;
825
- zval * object = (zval * )& iterator -> intern .it .data ;
826
832
827
- if (intern -> fptr_it_rewind ) {
828
- zend_call_method_with_0_params (& object , intern -> std .ce , & intern -> fptr_it_rewind , "rewind" , NULL );
833
+ if (intern -> flags & SPL_FIXEDARRAY_OVERLOADED_REWIND ) {
834
+ zend_user_it_rewind (iter TSRMLS_CC );
835
+ } else {
836
+ iterator -> object -> current = 0 ;
829
837
}
830
- iterator -> object -> current = 0 ;
831
838
}
832
839
/* }}} */
833
840
834
841
static int spl_fixedarray_it_valid (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
835
842
{
836
843
spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
837
844
spl_fixedarray_object * intern = iterator -> object ;
838
- zval * object = (zval * )& iterator -> intern .it .data ;
839
845
840
- if (intern -> fptr_it_valid ) {
841
- zval * rv ;
842
- zend_call_method_with_0_params (& object , intern -> std .ce , & intern -> fptr_it_valid , "valid" , & rv );
843
- if (rv ) {
844
- zval_ptr_dtor (& intern -> retval );
845
- MAKE_STD_ZVAL (intern -> retval );
846
- ZVAL_ZVAL (intern -> retval , rv , 1 , 1 );
847
- return zend_is_true (intern -> retval ) ? SUCCESS : FAILURE ;
848
- }
849
- return FAILURE ;
846
+ if (intern -> flags & SPL_FIXEDARRAY_OVERLOADED_VALID ) {
847
+ return zend_user_it_valid (iter TSRMLS_CC );
850
848
}
851
849
852
850
if (iterator -> object -> current >= 0 && iterator -> object -> array && iterator -> object -> current < iterator -> object -> array -> size ) {
@@ -859,76 +857,53 @@ static int spl_fixedarray_it_valid(zend_object_iterator *iter TSRMLS_DC) /* {{{
859
857
860
858
static void spl_fixedarray_it_get_current_data (zend_object_iterator * iter , zval * * * data TSRMLS_DC ) /* {{{ */
861
859
{
862
- zval * zindex ;
860
+ zval * zindex ;
863
861
spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
864
862
spl_fixedarray_object * intern = iterator -> object ;
865
- zval * object = (zval * )& iterator -> intern .it .data ;
866
863
867
- if (intern -> fptr_it_current ) {
868
- zval * rv ;
869
- zend_call_method_with_0_params (& object , intern -> std .ce , & intern -> fptr_it_current , "current" , & rv );
870
- if (rv ) {
871
- zval_ptr_dtor (& intern -> retval );
872
- MAKE_STD_ZVAL (intern -> retval );
873
- ZVAL_ZVAL (intern -> retval , rv , 1 , 1 );
874
- * data = & intern -> retval ;
875
- return ;
876
- }
877
- * data = NULL ;
878
- return ;
879
- }
864
+ if (intern -> flags & SPL_FIXEDARRAY_OVERLOADED_CURRENT ) {
865
+ zend_user_it_get_current_data (iter , data TSRMLS_CC );
866
+ } else {
867
+ ALLOC_INIT_ZVAL (zindex );
868
+ ZVAL_LONG (zindex , iterator -> object -> current );
880
869
881
- ALLOC_INIT_ZVAL (zindex );
882
- ZVAL_LONG (zindex , iterator -> object -> current );
870
+ * data = spl_fixedarray_object_read_dimension_helper (intern , zindex TSRMLS_CC );
883
871
884
- * data = spl_fixedarray_object_read_dimension_helper (intern , zindex TSRMLS_CC );
872
+ if (* data == NULL ) {
873
+ * data = & EG (uninitialized_zval_ptr );
874
+ }
885
875
886
- if (* data == NULL ) {
887
- * data = & EG (uninitialized_zval_ptr );
876
+ zval_ptr_dtor (& zindex );
888
877
}
889
-
890
- zval_ptr_dtor (& zindex );
891
878
}
892
879
/* }}} */
893
880
894
881
static int spl_fixedarray_it_get_current_key (zend_object_iterator * iter , char * * str_key , uint * str_key_len , ulong * int_key TSRMLS_DC ) /* {{{ */
895
882
{
896
883
spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
897
884
spl_fixedarray_object * intern = iterator -> object ;
898
- zval * object = (zval * )& iterator -> intern .it .data ;
899
885
900
- if (intern -> fptr_it_key ) {
901
- zval * rv ;
902
- zend_call_method_with_0_params (& object , intern -> std .ce , & intern -> fptr_it_key , "key" , & rv );
903
- if (rv ) {
904
- zval_ptr_dtor (& intern -> retval );
905
- MAKE_STD_ZVAL (intern -> retval );
906
- ZVAL_ZVAL (intern -> retval , rv , 1 , 1 );
907
- convert_to_long (intern -> retval );
908
- * int_key = (ulong ) Z_LVAL_P (intern -> retval );
909
- }
910
- * int_key = (ulong ) 0 ;
886
+ if (intern -> flags & SPL_FIXEDARRAY_OVERLOADED_KEY ) {
887
+ return zend_user_it_get_current_key (iter , str_key , str_key_len , int_key TSRMLS_CC );
911
888
} else {
912
889
* int_key = (ulong ) iterator -> object -> current ;
890
+ return HASH_KEY_IS_LONG ;
913
891
}
914
892
915
- return HASH_KEY_IS_LONG ;
916
893
}
917
894
/* }}} */
918
895
919
896
static void spl_fixedarray_it_move_forward (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
920
897
{
921
898
spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
922
899
spl_fixedarray_object * intern = iterator -> object ;
923
- zval * object = (zval * )& iterator -> intern .it .data ;
924
900
925
- if (intern -> fptr_it_next ) {
926
- zend_call_method_with_0_params (& object , intern -> std .ce , & intern -> fptr_it_next , "next" , NULL );
901
+ if (intern -> flags & SPL_FIXEDARRAY_OVERLOADED_NEXT ) {
902
+ zend_user_it_move_forward (iter TSRMLS_CC );
903
+ } else {
904
+ zend_user_it_invalidate_current (iter TSRMLS_CC );
905
+ iterator -> object -> current ++ ;
927
906
}
928
-
929
- zend_user_it_invalidate_current (iter TSRMLS_CC );
930
-
931
- iterator -> object -> current ++ ;
932
907
}
933
908
/* }}} */
934
909
0 commit comments