@@ -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 );
@@ -236,31 +223,7 @@ static zend_object *spl_fixedarray_object_new_ex(zend_class_entry *class_type, z
236
223
237
224
ZEND_ASSERT (parent );
238
225
239
- funcs_ptr = class_type -> iterator_funcs_ptr ;
240
- if (!funcs_ptr -> zf_current ) {
241
- funcs_ptr -> zf_rewind = zend_hash_str_find_ptr (& class_type -> function_table , "rewind" , sizeof ("rewind" ) - 1 );
242
- funcs_ptr -> zf_valid = zend_hash_str_find_ptr (& class_type -> function_table , "valid" , sizeof ("valid" ) - 1 );
243
- funcs_ptr -> zf_key = zend_hash_str_find_ptr (& class_type -> function_table , "key" , sizeof ("key" ) - 1 );
244
- funcs_ptr -> zf_current = zend_hash_str_find_ptr (& class_type -> function_table , "current" , sizeof ("current" ) - 1 );
245
- funcs_ptr -> zf_next = zend_hash_str_find_ptr (& class_type -> function_table , "next" , sizeof ("next" ) - 1 );
246
- }
247
226
if (inherited ) {
248
- if (funcs_ptr -> zf_rewind -> common .scope != parent ) {
249
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_REWIND ;
250
- }
251
- if (funcs_ptr -> zf_valid -> common .scope != parent ) {
252
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_VALID ;
253
- }
254
- if (funcs_ptr -> zf_key -> common .scope != parent ) {
255
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_KEY ;
256
- }
257
- if (funcs_ptr -> zf_current -> common .scope != parent ) {
258
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_CURRENT ;
259
- }
260
- if (funcs_ptr -> zf_next -> common .scope != parent ) {
261
- intern -> flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT ;
262
- }
263
-
264
227
intern -> fptr_offset_get = zend_hash_str_find_ptr (& class_type -> function_table , "offsetget" , sizeof ("offsetget" ) - 1 );
265
228
if (intern -> fptr_offset_get -> common .scope == parent ) {
266
229
intern -> fptr_offset_get = NULL ;
@@ -780,36 +743,35 @@ PHP_METHOD(SplFixedArray, offsetUnset)
780
743
781
744
} /* }}} */
782
745
783
- static void spl_fixedarray_it_dtor (zend_object_iterator * iter ) /* {{{ */
746
+ /* {{{ Create a new iterator from a SplFixedArray instance. */
747
+ PHP_METHOD (SplFixedArray , getIterator )
784
748
{
785
- spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
749
+ if (zend_parse_parameters_none () == FAILURE ) {
750
+ return ;
751
+ }
786
752
787
- zend_user_it_invalidate_current (iter );
788
- zval_ptr_dtor (& iterator -> intern .it .data );
753
+ zend_create_internal_iterator_zval (return_value , ZEND_THIS );
789
754
}
790
755
/* }}} */
791
756
792
- static void spl_fixedarray_it_rewind (zend_object_iterator * iter ) /* {{{ */
757
+ static void spl_fixedarray_it_dtor (zend_object_iterator * iter ) /* {{{ */
793
758
{
794
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
759
+ zval_ptr_dtor (& iter -> data );
760
+ }
761
+ /* }}} */
795
762
796
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_REWIND ) {
797
- zend_user_it_rewind (iter );
798
- } else {
799
- object -> current = 0 ;
800
- }
763
+ static void spl_fixedarray_it_rewind (zend_object_iterator * iter ) /* {{{ */
764
+ {
765
+ ((spl_fixedarray_it * )iter )-> current = 0 ;
801
766
}
802
767
/* }}} */
803
768
804
769
static int spl_fixedarray_it_valid (zend_object_iterator * iter ) /* {{{ */
805
770
{
806
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
771
+ spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
772
+ spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
807
773
808
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_VALID ) {
809
- return zend_user_it_valid (iter );
810
- }
811
-
812
- if (object -> current >= 0 && object -> current < object -> array .size ) {
774
+ if (iterator -> current >= 0 && iterator -> current < object -> array .size ) {
813
775
return SUCCESS ;
814
776
}
815
777
@@ -819,122 +781,29 @@ static int spl_fixedarray_it_valid(zend_object_iterator *iter) /* {{{ */
819
781
820
782
static zval * spl_fixedarray_it_get_current_data (zend_object_iterator * iter ) /* {{{ */
821
783
{
822
- zval zindex ;
823
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
824
-
825
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_CURRENT ) {
826
- return zend_user_it_get_current_data (iter );
827
- } else {
828
- zval * data ;
784
+ zval zindex , * data ;
785
+ spl_fixedarray_it * iterator = (spl_fixedarray_it * )iter ;
786
+ spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
829
787
830
- ZVAL_LONG (& zindex , object -> current );
788
+ ZVAL_LONG (& zindex , iterator -> current );
789
+ data = spl_fixedarray_object_read_dimension_helper (object , & zindex );
831
790
832
- data = spl_fixedarray_object_read_dimension_helper (object , & zindex );
833
-
834
- if (data == NULL ) {
835
- data = & EG (uninitialized_zval );
836
- }
837
- return data ;
791
+ if (data == NULL ) {
792
+ data = & EG (uninitialized_zval );
838
793
}
794
+ return data ;
839
795
}
840
796
/* }}} */
841
797
842
798
static void spl_fixedarray_it_get_current_key (zend_object_iterator * iter , zval * key ) /* {{{ */
843
799
{
844
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
845
-
846
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_KEY ) {
847
- zend_user_it_get_current_key (iter , key );
848
- } else {
849
- ZVAL_LONG (key , object -> current );
850
- }
800
+ ZVAL_LONG (key , ((spl_fixedarray_it * )iter )-> current );
851
801
}
852
802
/* }}} */
853
803
854
804
static void spl_fixedarray_it_move_forward (zend_object_iterator * iter ) /* {{{ */
855
805
{
856
- spl_fixedarray_object * object = Z_SPLFIXEDARRAY_P (& iter -> data );
857
-
858
- if (object -> flags & SPL_FIXEDARRAY_OVERLOADED_NEXT ) {
859
- zend_user_it_move_forward (iter );
860
- } else {
861
- zend_user_it_invalidate_current (iter );
862
- object -> current ++ ;
863
- }
864
- }
865
- /* }}} */
866
-
867
- /* {{{ Return current array key */
868
- PHP_METHOD (SplFixedArray , key )
869
- {
870
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
871
-
872
- if (zend_parse_parameters_none () == FAILURE ) {
873
- RETURN_THROWS ();
874
- }
875
-
876
- RETURN_LONG (intern -> current );
877
- }
878
- /* }}} */
879
-
880
- /* {{{ Move to next entry */
881
- PHP_METHOD (SplFixedArray , next )
882
- {
883
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
884
-
885
- if (zend_parse_parameters_none () == FAILURE ) {
886
- RETURN_THROWS ();
887
- }
888
-
889
- intern -> current ++ ;
890
- }
891
- /* }}} */
892
-
893
- /* {{{ Check whether the datastructure contains more entries */
894
- PHP_METHOD (SplFixedArray , valid )
895
- {
896
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
897
-
898
- if (zend_parse_parameters_none () == FAILURE ) {
899
- RETURN_THROWS ();
900
- }
901
-
902
- RETURN_BOOL (intern -> current >= 0 && intern -> current < intern -> array .size );
903
- }
904
- /* }}} */
905
-
906
- /* {{{ Rewind the datastructure back to the start */
907
- PHP_METHOD (SplFixedArray , rewind )
908
- {
909
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
910
-
911
- if (zend_parse_parameters_none () == FAILURE ) {
912
- RETURN_THROWS ();
913
- }
914
-
915
- intern -> current = 0 ;
916
- }
917
- /* }}} */
918
-
919
- /* {{{ Return current datastructure entry */
920
- PHP_METHOD (SplFixedArray , current )
921
- {
922
- zval zindex , * value ;
923
- spl_fixedarray_object * intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
924
-
925
- if (zend_parse_parameters_none () == FAILURE ) {
926
- RETURN_THROWS ();
927
- }
928
-
929
- ZVAL_LONG (& zindex , intern -> current );
930
-
931
- value = spl_fixedarray_object_read_dimension_helper (intern , & zindex );
932
-
933
- if (value ) {
934
- ZVAL_COPY_DEREF (return_value , value );
935
- } else {
936
- RETURN_NULL ();
937
- }
806
+ ((spl_fixedarray_it * )iter )-> current ++ ;
938
807
}
939
808
/* }}} */
940
809
@@ -963,12 +832,10 @@ zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *ob
963
832
964
833
zend_iterator_init ((zend_object_iterator * )iterator );
965
834
966
- ZVAL_OBJ_COPY (& iterator -> intern .it .data , Z_OBJ_P (object ));
967
- iterator -> intern .it .funcs = & spl_fixedarray_it_funcs ;
968
- iterator -> intern .ce = ce ;
969
- ZVAL_UNDEF (& iterator -> intern .value );
835
+ ZVAL_OBJ_COPY (& iterator -> intern .data , Z_OBJ_P (object ));
836
+ iterator -> intern .funcs = & spl_fixedarray_it_funcs ;
970
837
971
- return & iterator -> intern . it ;
838
+ return & iterator -> intern ;
972
839
}
973
840
/* }}} */
974
841
@@ -990,7 +857,7 @@ PHP_MINIT_FUNCTION(spl_fixedarray)
990
857
spl_handler_SplFixedArray .dtor_obj = zend_objects_destroy_object ;
991
858
spl_handler_SplFixedArray .free_obj = spl_fixedarray_object_free_storage ;
992
859
993
- REGISTER_SPL_IMPLEMENTS (SplFixedArray , Iterator );
860
+ REGISTER_SPL_IMPLEMENTS (SplFixedArray , Aggregate );
994
861
REGISTER_SPL_IMPLEMENTS (SplFixedArray , ArrayAccess );
995
862
REGISTER_SPL_IMPLEMENTS (SplFixedArray , Countable );
996
863
0 commit comments