@@ -66,14 +66,9 @@ typedef struct _spl_ptr_llist_element {
66
66
zval data ;
67
67
} spl_ptr_llist_element ;
68
68
69
- typedef void (* spl_ptr_llist_dtor_func )(spl_ptr_llist_element * );
70
- typedef void (* spl_ptr_llist_ctor_func )(spl_ptr_llist_element * );
71
-
72
69
typedef struct _spl_ptr_llist {
73
- spl_ptr_llist_element * head ;
74
- spl_ptr_llist_element * tail ;
75
- spl_ptr_llist_dtor_func dtor ;
76
- spl_ptr_llist_ctor_func ctor ;
70
+ spl_ptr_llist_element * head ;
71
+ spl_ptr_llist_element * tail ;
77
72
int count ;
78
73
} spl_ptr_llist ;
79
74
@@ -109,31 +104,13 @@ static inline spl_dllist_object *spl_dllist_from_obj(zend_object *obj) /* {{{ */
109
104
110
105
#define Z_SPLDLLIST_P (zv ) spl_dllist_from_obj(Z_OBJ_P((zv)))
111
106
112
- /* {{{ spl_ptr_llist */
113
- static void spl_ptr_llist_zval_dtor (spl_ptr_llist_element * elem ) { /* {{{ */
114
- if (!Z_ISUNDEF (elem -> data )) {
115
- zval_ptr_dtor (& elem -> data );
116
- ZVAL_UNDEF (& elem -> data );
117
- }
118
- }
119
- /* }}} */
120
-
121
- static void spl_ptr_llist_zval_ctor (spl_ptr_llist_element * elem ) { /* {{{ */
122
- if (Z_REFCOUNTED (elem -> data )) {
123
- Z_ADDREF (elem -> data );
124
- }
125
- }
126
- /* }}} */
127
-
128
- static spl_ptr_llist * spl_ptr_llist_init (spl_ptr_llist_ctor_func ctor , spl_ptr_llist_dtor_func dtor ) /* {{{ */
107
+ static spl_ptr_llist * spl_ptr_llist_init () /* {{{ */
129
108
{
130
109
spl_ptr_llist * llist = emalloc (sizeof (spl_ptr_llist ));
131
110
132
111
llist -> head = NULL ;
133
112
llist -> tail = NULL ;
134
113
llist -> count = 0 ;
135
- llist -> dtor = dtor ;
136
- llist -> ctor = ctor ;
137
114
138
115
return llist ;
139
116
}
@@ -147,14 +124,11 @@ static zend_long spl_ptr_llist_count(spl_ptr_llist *llist) /* {{{ */
147
124
148
125
static void spl_ptr_llist_destroy (spl_ptr_llist * llist ) /* {{{ */
149
126
{
150
- spl_ptr_llist_element * current = llist -> head , * next ;
151
- spl_ptr_llist_dtor_func dtor = llist -> dtor ;
127
+ spl_ptr_llist_element * current = llist -> head , * next ;
152
128
153
129
while (current ) {
154
130
next = current -> next ;
155
- if (dtor ) {
156
- dtor (current );
157
- }
131
+ zval_ptr_dtor (& current -> data );
158
132
SPL_LLIST_DELREF (current );
159
133
current = next ;
160
134
}
@@ -206,9 +180,7 @@ static void spl_ptr_llist_unshift(spl_ptr_llist *llist, zval *data) /* {{{ */
206
180
llist -> head = elem ;
207
181
llist -> count ++ ;
208
182
209
- if (llist -> ctor ) {
210
- llist -> ctor (elem );
211
- }
183
+ Z_TRY_ADDREF (elem -> data );
212
184
}
213
185
/* }}} */
214
186
@@ -230,9 +202,7 @@ static void spl_ptr_llist_push(spl_ptr_llist *llist, zval *data) /* {{{ */
230
202
llist -> tail = elem ;
231
203
llist -> count ++ ;
232
204
233
- if (llist -> ctor ) {
234
- llist -> ctor (elem );
235
- }
205
+ Z_TRY_ADDREF (elem -> data );
236
206
}
237
207
/* }}} */
238
208
@@ -253,14 +223,10 @@ static void spl_ptr_llist_pop(spl_ptr_llist *llist, zval *ret) /* {{{ */
253
223
254
224
llist -> tail = tail -> prev ;
255
225
llist -> count -- ;
256
- ZVAL_COPY (ret , & tail -> data );
226
+ ZVAL_COPY_VALUE (ret , & tail -> data );
227
+ ZVAL_UNDEF (& tail -> data );
257
228
258
229
tail -> prev = NULL ;
259
- if (llist -> dtor ) {
260
- llist -> dtor (tail );
261
- }
262
-
263
- ZVAL_UNDEF (& tail -> data );
264
230
265
231
SPL_LLIST_DELREF (tail );
266
232
}
@@ -307,13 +273,10 @@ static void spl_ptr_llist_shift(spl_ptr_llist *llist, zval *ret) /* {{{ */
307
273
308
274
llist -> head = head -> next ;
309
275
llist -> count -- ;
310
- ZVAL_COPY (ret , & head -> data );
276
+ ZVAL_COPY_VALUE (ret , & head -> data );
277
+ ZVAL_UNDEF (& head -> data );
311
278
312
279
head -> next = NULL ;
313
- if (llist -> dtor ) {
314
- llist -> dtor (head );
315
- }
316
- ZVAL_UNDEF (& head -> data );
317
280
318
281
SPL_LLIST_DELREF (head );
319
282
}
@@ -322,17 +285,9 @@ static void spl_ptr_llist_shift(spl_ptr_llist *llist, zval *ret) /* {{{ */
322
285
static void spl_ptr_llist_copy (spl_ptr_llist * from , spl_ptr_llist * to ) /* {{{ */
323
286
{
324
287
spl_ptr_llist_element * current = from -> head , * next ;
325
- //??? spl_ptr_llist_ctor_func ctor = from->ctor;
326
288
327
289
while (current ) {
328
290
next = current -> next ;
329
-
330
- /*??? FIXME
331
- if (ctor) {
332
- ctor(current);
333
- }
334
- */
335
-
336
291
spl_ptr_llist_push (to , & current -> data );
337
292
current = next ;
338
293
}
@@ -378,7 +333,7 @@ static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zend_
378
333
intern -> ce_get_iterator = other -> ce_get_iterator ;
379
334
380
335
if (clone_orig ) {
381
- intern -> llist = ( spl_ptr_llist * ) spl_ptr_llist_init (other -> llist -> ctor , other -> llist -> dtor );
336
+ intern -> llist = spl_ptr_llist_init ();
382
337
spl_ptr_llist_copy (other -> llist , intern -> llist );
383
338
intern -> traverse_pointer = intern -> llist -> head ;
384
339
SPL_LLIST_CHECK_ADDREF (intern -> traverse_pointer );
@@ -390,7 +345,7 @@ static zend_object *spl_dllist_object_new_ex(zend_class_entry *class_type, zend_
390
345
391
346
intern -> flags = other -> flags ;
392
347
} else {
393
- intern -> llist = ( spl_ptr_llist * ) spl_ptr_llist_init (spl_ptr_llist_zval_ctor , spl_ptr_llist_zval_dtor );
348
+ intern -> llist = spl_ptr_llist_init ();
394
349
intern -> traverse_pointer = intern -> llist -> head ;
395
350
SPL_LLIST_CHECK_ADDREF (intern -> traverse_pointer );
396
351
}
@@ -789,20 +744,10 @@ PHP_METHOD(SplDoublyLinkedList, offsetSet)
789
744
element = spl_ptr_llist_offset (intern -> llist , index , intern -> flags & SPL_DLLIST_IT_LIFO );
790
745
791
746
if (element != NULL ) {
792
- /* call dtor on the old element as in spl_ptr_llist_pop */
793
- if (intern -> llist -> dtor ) {
794
- intern -> llist -> dtor (element );
795
- }
796
-
797
747
/* the element is replaced, delref the old one as in
798
748
* SplDoublyLinkedList::pop() */
799
749
zval_ptr_dtor (& element -> data );
800
- ZVAL_COPY_VALUE (& element -> data , value );
801
-
802
- /* new element, call ctor as in spl_ptr_llist_push */
803
- if (intern -> llist -> ctor ) {
804
- intern -> llist -> ctor (element );
805
- }
750
+ ZVAL_COPY (& element -> data , value );
806
751
} else {
807
752
zval_ptr_dtor (value );
808
753
zend_argument_error (spl_ce_OutOfRangeException , 1 , "is an invalid offset" );
@@ -855,16 +800,13 @@ PHP_METHOD(SplDoublyLinkedList, offsetUnset)
855
800
/* finally, delete the element */
856
801
llist -> count -- ;
857
802
858
- if (llist -> dtor ) {
859
- llist -> dtor (element );
860
- }
803
+ zval_ptr_dtor (& element -> data );
804
+ ZVAL_UNDEF (& element -> data );
861
805
862
806
if (intern -> traverse_pointer == element ) {
863
807
SPL_LLIST_DELREF (element );
864
808
intern -> traverse_pointer = NULL ;
865
809
}
866
- zval_ptr_dtor (& element -> data );
867
- ZVAL_UNDEF (& element -> data );
868
810
869
811
SPL_LLIST_DELREF (element );
870
812
} else {
@@ -1274,9 +1216,7 @@ PHP_METHOD(SplDoublyLinkedList, add)
1274
1216
1275
1217
intern -> llist -> count ++ ;
1276
1218
1277
- if (intern -> llist -> ctor ) {
1278
- intern -> llist -> ctor (elem );
1279
- }
1219
+ Z_TRY_ADDREF (elem -> data );
1280
1220
}
1281
1221
} /* }}} */
1282
1222
0 commit comments