@@ -119,36 +119,12 @@ ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_fun
119
119
}
120
120
/* }}} */
121
121
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
-
127
122
/* 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
- /* }}} */
146
123
147
124
/* {{{ zend_user_it_new_iterator */
148
125
ZEND_API void zend_user_it_new_iterator (zend_class_entry * ce , zval * object , zval * retval )
149
126
{
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 );
152
128
}
153
129
/* }}} */
154
130
@@ -183,10 +159,8 @@ ZEND_API int zend_user_it_valid(zend_object_iterator *_iter)
183
159
zval * object = & iter -> it .data ;
184
160
zval more ;
185
161
int result ;
186
- zend_class_entry * ce = iter -> ce ;
187
- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
188
162
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 );
190
164
result = i_zend_is_true (& more );
191
165
zval_ptr_dtor (& more );
192
166
return result ? SUCCESS : FAILURE ;
@@ -202,10 +176,7 @@ ZEND_API zval *zend_user_it_get_current_data(zend_object_iterator *_iter)
202
176
zval * object = & iter -> it .data ;
203
177
204
178
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 );
209
180
}
210
181
return & iter -> value ;
211
182
}
@@ -217,10 +188,8 @@ ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *ke
217
188
zend_user_iterator * iter = (zend_user_iterator * )_iter ;
218
189
zval * object = & iter -> it .data ;
219
190
zval retval ;
220
- zend_class_entry * ce = iter -> ce ;
221
- zend_class_iterator_funcs * iterator_funcs_ptr = zend_get_iterator_funcs_ptr (ce );
222
191
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 );
224
193
225
194
if (Z_TYPE (retval ) != IS_UNDEF ) {
226
195
ZVAL_ZVAL (key , & retval , 1 , 1 );
@@ -239,11 +208,9 @@ ZEND_API void zend_user_it_move_forward(zend_object_iterator *_iter)
239
208
{
240
209
zend_user_iterator * iter = (zend_user_iterator * )_iter ;
241
210
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 );
244
211
245
212
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 );
247
214
}
248
215
/* }}} */
249
216
@@ -252,11 +219,9 @@ ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter)
252
219
{
253
220
zend_user_iterator * iter = (zend_user_iterator * )_iter ;
254
221
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 );
257
222
258
223
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 );
260
225
}
261
226
/* }}} */
262
227
@@ -347,7 +312,6 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
347
312
{
348
313
uint32_t i ;
349
314
int t = -1 ;
350
- zend_class_iterator_funcs * iterator_funcs_ptr ;
351
315
352
316
if (class_type -> get_iterator ) {
353
317
if (class_type -> type == ZEND_INTERNAL_CLASS ) {
@@ -376,40 +340,24 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
376
340
}
377
341
}
378
342
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 ;
386
345
} 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 ));
393
347
} 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 );
402
353
}
403
- iterator_funcs_ptr -> zf_new_iterator = zend_hash_str_find_ptr (& class_type -> function_table , "getiterator" , sizeof ("getiterator" ) - 1 );
404
354
return SUCCESS ;
405
355
}
406
356
/* }}} */
407
357
408
358
/* {{{ zend_implement_iterator */
409
359
static int zend_implement_iterator (zend_class_entry * interface , zend_class_entry * class_type )
410
360
{
411
- zend_class_iterator_funcs * iterator_funcs_ptr ;
412
-
413
361
if (class_type -> get_iterator && class_type -> get_iterator != zend_user_it_get_iterator ) {
414
362
if (class_type -> type == ZEND_INTERNAL_CLASS ) {
415
363
/* 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
426
374
}
427
375
}
428
376
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 ;
440
383
} 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 ));
447
385
} 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 );
456
395
}
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 );
462
396
return SUCCESS ;
463
397
}
464
398
/* }}} */
0 commit comments