@@ -46,29 +46,22 @@ typedef struct _spl_fixedarray { /* {{{ */
46
46
/* }}} */
47
47
48
48
typedef struct _spl_fixedarray_object { /* {{{ */
49
- spl_fixedarray array ;
50
- zend_function * fptr_offset_get ;
51
- zend_function * fptr_offset_set ;
52
- zend_function * fptr_offset_has ;
53
- zend_function * fptr_offset_del ;
54
- zend_function * fptr_count ;
55
- int current ;
56
- int flags ;
57
- zend_object std ;
49
+ spl_fixedarray array ;
50
+ zend_function * fptr_offset_get ;
51
+ zend_function * fptr_offset_set ;
52
+ zend_function * fptr_offset_has ;
53
+ zend_function * fptr_offset_del ;
54
+ zend_function * fptr_count ;
55
+ zend_object std ;
58
56
} spl_fixedarray_object ;
59
57
/* }}} */
60
58
61
59
typedef struct _spl_fixedarray_it { /* {{{ */
62
- zend_user_iterator intern ;
60
+ zend_object_iterator intern ;
61
+ int current ;
63
62
} spl_fixedarray_it ;
64
63
/* }}} */
65
64
66
- #define SPL_FIXEDARRAY_OVERLOADED_REWIND 0x0001
67
- #define SPL_FIXEDARRAY_OVERLOADED_VALID 0x0002
68
- #define SPL_FIXEDARRAY_OVERLOADED_KEY 0x0004
69
- #define SPL_FIXEDARRAY_OVERLOADED_CURRENT 0x0008
70
- #define SPL_FIXEDARRAY_OVERLOADED_NEXT 0x0010
71
-
72
65
static inline spl_fixedarray_object * spl_fixed_array_from_obj (zend_object * obj ) /* {{{ */ {
73
66
return (spl_fixedarray_object * )((char * )(obj ) - XtOffsetOf (spl_fixedarray_object , std ));
74
67
}
@@ -201,23 +194,17 @@ static void spl_fixedarray_object_free_storage(zend_object *object) /* {{{ */
201
194
}
202
195
/* }}} */
203
196
204
- zend_object_iterator * spl_fixedarray_get_iterator (zend_class_entry * ce , zval * object , int by_ref );
205
-
206
197
static zend_object * spl_fixedarray_object_new_ex (zend_class_entry * class_type , zend_object * orig , int clone_orig ) /* {{{ */
207
198
{
208
199
spl_fixedarray_object * intern ;
209
200
zend_class_entry * parent = class_type ;
210
201
int inherited = 0 ;
211
- zend_class_iterator_funcs * funcs_ptr ;
212
202
213
203
intern = zend_object_alloc (sizeof (spl_fixedarray_object ), parent );
214
204
215
205
zend_object_std_init (& intern -> std , class_type );
216
206
object_properties_init (& intern -> std , class_type );
217
207
218
- intern -> current = 0 ;
219
- intern -> flags = 0 ;
220
-
221
208
if (orig && clone_orig ) {
222
209
spl_fixedarray_object * other = spl_fixed_array_from_obj (orig );
223
210
spl_fixedarray_init (& intern -> array , other -> array .size );
@@ -238,31 +225,7 @@ static zend_object *spl_fixedarray_object_new_ex(zend_class_entry *class_type, z
238
225
php_error_docref (NULL , E_COMPILE_ERROR , "Internal compiler error, Class is not child of SplFixedArray" );
239
226
}
240
227
241
- funcs_ptr = class_type -> iterator_funcs_ptr ;
242
- if (!funcs_ptr -> zf_current ) {
243
- funcs_ptr -> zf_rewind = zend_hash_str_find_ptr (& class_type -> function_table , "rewind" , sizeof ("rewind" ) - 1 );
244
- funcs_ptr -> zf_valid = zend_hash_str_find_ptr (& class_type -> function_table , "valid" , sizeof ("valid" ) - 1 );
245
- funcs_ptr -> zf_key = zend_hash_str_find_ptr (& class_type -> function_table , "key" , sizeof ("key" ) - 1 );
246
- funcs_ptr -> zf_current = zend_hash_str_find_ptr (& class_type -> function_table , "current" , sizeof ("current" ) - 1 );
247
- funcs_ptr -> zf_next = zend_hash_str_find_ptr (& class_type -> function_table , "next" , sizeof ("next" ) - 1 );
248
- }
249
228
if (inherited ) {
250
- if (funcs_ptr -> zf_rewind -> common .scope != parent ) {
251
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_REWIND ;
252
- }
253
- if (funcs_ptr -> zf_valid -> common .scope != parent ) {
254
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_VALID ;
255
- }
256
- if (funcs_ptr -> zf_key -> common .scope != parent ) {
257
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_KEY ;
258
- }
259
- if (funcs_ptr -> zf_current -> common .scope != parent ) {
260
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_CURRENT ;
261
- }
262
- if (funcs_ptr -> zf_next -> common .scope != parent ) {
263
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT ;
264
- }
265
-
266
229
intern -> fptr_offset_get = zend_hash_str_find_ptr (& class_type -> function_table , "offsetget" , sizeof ("offsetget" ) - 1 );
267
230
if (intern -> fptr_offset_get -> common .scope == parent ) {
268
231
intern -> fptr_offset_get = NULL ;
@@ -793,36 +756,36 @@ PHP_METHOD(SplFixedArray, offsetUnset)
793
756
794
757
} /* }}} */
795
758
796
- static void spl_fixedarray_it_dtor (zend_object_iterator * iter ) /* {{{ */
759
+ /* {{{ proto Iterator SplFixedArray::getIterator()
760
+ Create a new iterator from a SplFixedArray instance. */
761
+ PHP_METHOD (SplFixedArray , getIterator )
797
762
{
798
- spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
763
+ if (zend_parse_parameters_none () == FAILURE ) {
764
+ return ;
765
+ }
799
766
800
- zend_user_it_invalidate_current (iter );
801
- zval_ptr_dtor (& iterator -> intern .it .data );
767
+ zend_create_internal_iterator_zval (return_value , ZEND_THIS );
802
768
}
803
769
/* }}} */
804
770
805
- static void spl_fixedarray_it_rewind (zend_object_iterator * iter ) /* {{{ */
771
+ static void spl_fixedarray_it_dtor (zend_object_iterator * iter ) /* {{{ */
806
772
{
807
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
773
+ zval_ptr_dtor (& iter -> data );
774
+ }
775
+ /* }}} */
808
776
809
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_REWIND ) {
810
- zend_user_it_rewind (iter );
811
- } else {
812
- object -> current = 0 ;
813
- }
777
+ static void spl_fixedarray_it_rewind (zend_object_iterator * iter ) /* {{{ */
778
+ {
779
+ ((spl_fixedarray_it * )iter )-> current = 0 ;
814
780
}
815
781
/* }}} */
816
782
817
783
static int spl_fixedarray_it_valid (zend_object_iterator * iter ) /* {{{ */
818
784
{
819
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
785
+ spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
786
+ spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
820
787
821
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_VALID ) {
822
- return zend_user_it_valid (iter );
823
- }
824
-
825
- if (object -> current >= 0 && object -> current < object -> array .size ) {
788
+ if (iterator -> current >= 0 && iterator -> current < object -> array .size ) {
826
789
return SUCCESS ;
827
790
}
828
791
@@ -832,127 +795,29 @@ static int spl_fixedarray_it_valid(zend_object_iterator *iter) /* {{{ */
832
795
833
796
static zval * spl_fixedarray_it_get_current_data (zend_object_iterator * iter ) /* {{{ */
834
797
{
835
- zval zindex ;
836
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
837
-
838
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_CURRENT ) {
839
- return zend_user_it_get_current_data (iter );
840
- } else {
841
- zval * data ;
798
+ zval zindex , * data ;
799
+ spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
800
+ spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
842
801
843
- ZVAL_LONG (& zindex , object -> current );
802
+ ZVAL_LONG (& zindex , iterator -> current );
803
+ data = spl_fixedarray_object_read_dimension_helper (object , & zindex );
844
804
845
- data = spl_fixedarray_object_read_dimension_helper (object , & zindex );
846
-
847
- if (data == NULL ) {
848
- data = & EG (uninitialized_zval );
849
- }
850
- return data ;
805
+ if (data == NULL ) {
806
+ data = & EG (uninitialized_zval );
851
807
}
808
+ return data ;
852
809
}
853
810
/* }}} */
854
811
855
812
static void spl_fixedarray_it_get_current_key (zend_object_iterator * iter , zval * key ) /* {{{ */
856
813
{
857
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
858
-
859
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_KEY ) {
860
- zend_user_it_get_current_key (iter , key );
861
- } else {
862
- ZVAL_LONG (key , object -> current );
863
- }
814
+ ZVAL_LONG (key , ((spl_fixedarray_it * )iter )-> current );
864
815
}
865
816
/* }}} */
866
817
867
818
static void spl_fixedarray_it_move_forward (zend_object_iterator * iter ) /* {{{ */
868
819
{
869
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
870
-
871
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_NEXT ) {
872
- zend_user_it_move_forward (iter );
873
- } else {
874
- zend_user_it_invalidate_current (iter );
875
- object -> current ++ ;
876
- }
877
- }
878
- /* }}} */
879
-
880
- /* {{{ proto int SplFixedArray::key()
881
- Return current array key */
882
- PHP_METHOD (SplFixedArray , key )
883
- {
884
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
885
-
886
- if (zend_parse_parameters_none () == FAILURE ) {
887
- RETURN_THROWS ();
888
- }
889
-
890
- RETURN_LONG (intern -> current );
891
- }
892
- /* }}} */
893
-
894
- /* {{{ proto void SplFixedArray::next()
895
- Move to next entry */
896
- PHP_METHOD (SplFixedArray , next )
897
- {
898
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
899
-
900
- if (zend_parse_parameters_none () == FAILURE ) {
901
- RETURN_THROWS ();
902
- }
903
-
904
- intern -> current ++ ;
905
- }
906
- /* }}} */
907
-
908
- /* {{{ proto bool SplFixedArray::valid()
909
- Check whether the datastructure contains more entries */
910
- PHP_METHOD (SplFixedArray , valid )
911
- {
912
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
913
-
914
- if (zend_parse_parameters_none () == FAILURE ) {
915
- RETURN_THROWS ();
916
- }
917
-
918
- RETURN_BOOL (intern -> current >= 0 && intern -> current < intern -> array .size );
919
- }
920
- /* }}} */
921
-
922
- /* {{{ proto void SplFixedArray::rewind()
923
- Rewind the datastructure back to the start */
924
- PHP_METHOD (SplFixedArray , rewind )
925
- {
926
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
927
-
928
- if (zend_parse_parameters_none () == FAILURE ) {
929
- RETURN_THROWS ();
930
- }
931
-
932
- intern -> current = 0 ;
933
- }
934
- /* }}} */
935
-
936
- /* {{{ proto mixed|NULL SplFixedArray::current()
937
- Return current datastructure entry */
938
- PHP_METHOD (SplFixedArray , current )
939
- {
940
- zval zindex , * value ;
941
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
942
-
943
- if (zend_parse_parameters_none () == FAILURE ) {
944
- RETURN_THROWS ();
945
- }
946
-
947
- ZVAL_LONG (& zindex , intern -> current );
948
-
949
- value = spl_fixedarray_object_read_dimension_helper (intern , & zindex );
950
-
951
- if (value ) {
952
- ZVAL_COPY_DEREF (return_value , value );
953
- } else {
954
- RETURN_NULL ();
955
- }
820
+ ((spl_fixedarray_it * )iter )-> current ++ ;
956
821
}
957
822
/* }}} */
958
823
@@ -980,12 +845,10 @@ zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *ob
980
845
981
846
zend_iterator_init ((zend_object_iterator * )iterator );
982
847
983
- ZVAL_OBJ_COPY (& iterator -> intern .it .data , Z_OBJ_P (object ));
984
- iterator -> intern .it .funcs = & spl_fixedarray_it_funcs ;
985
- iterator -> intern .ce = ce ;
986
- ZVAL_UNDEF (& iterator -> intern .value );
848
+ ZVAL_OBJ_COPY (& iterator -> intern .data , Z_OBJ_P (object ));
849
+ iterator -> intern .funcs = & spl_fixedarray_it_funcs ;
987
850
988
- return & iterator -> intern . it ;
851
+ return & iterator -> intern ;
989
852
}
990
853
/* }}} */
991
854
@@ -1007,7 +870,7 @@ PHP_MINIT_FUNCTION(spl_fixedarray)
1007
870
spl_handler_SplFixedArray .dtor_obj = zend_objects_destroy_object ;
1008
871
spl_handler_SplFixedArray .free_obj = spl_fixedarray_object_free_storage ;
1009
872
1010
- REGISTER_SPL_IMPLEMENTS (SplFixedArray , Iterator );
873
+ REGISTER_SPL_IMPLEMENTS (SplFixedArray , Aggregate );
1011
874
REGISTER_SPL_IMPLEMENTS (SplFixedArray , ArrayAccess );
1012
875
REGISTER_SPL_IMPLEMENTS (SplFixedArray , Countable );
1013
876
0 commit comments