@@ -420,10 +420,8 @@ static struct IDispatchExVtbl php_dispatch_vtbl = {
420
420
* dispatch ids */
421
421
static void generate_dispids (php_dispatchex * disp )
422
422
{
423
- HashPosition pos ;
424
423
zend_string * name = NULL ;
425
- zval * tmp , tmp2 ;
426
- int keytype ;
424
+ zval tmp ;
427
425
zend_long pid ;
428
426
429
427
if (disp -> dispid_to_name == NULL ) {
@@ -435,71 +433,38 @@ static void generate_dispids(php_dispatchex *disp)
435
433
436
434
/* properties */
437
435
if (Z_OBJPROP (disp -> object )) {
438
- zend_hash_internal_pointer_reset_ex (Z_OBJPROP (disp -> object ), & pos );
439
- while (HASH_KEY_NON_EXISTENT != (keytype =
440
- zend_hash_get_current_key_ex (Z_OBJPROP (disp -> object ), & name ,
441
- & pid , & pos ))) {
442
- char namebuf [32 ];
443
- if (keytype == HASH_KEY_IS_LONG ) {
444
- snprintf (namebuf , sizeof (namebuf ), ZEND_ULONG_FMT , pid );
445
- name = zend_string_init (namebuf , strlen (namebuf ), 0 );
446
- } else {
447
- zend_string_addref (name );
448
- }
449
-
450
- zend_hash_move_forward_ex (Z_OBJPROP (disp -> object ), & pos );
436
+ ZEND_HASH_FOREACH_STR_KEY (Z_OBJPROP (disp -> object ), name ) {
437
+ ZEND_ASSERT (name );
451
438
452
- /* Find the existing id */
453
- if ((tmp = zend_hash_find (disp -> name_to_dispid , name )) != NULL ) {
454
- zend_string_release_ex (name , 0 );
439
+ /* Check ID exists */
440
+ if (!zend_hash_exists (disp -> name_to_dispid , name )) {
455
441
continue ;
456
442
}
457
443
458
444
/* add the mappings */
459
- ZVAL_STR_COPY (& tmp2 , name );
460
- zend_hash_next_index_insert (disp -> dispid_to_name , & tmp2 );
461
- pid = zend_hash_next_free_element (disp -> dispid_to_name ) - 1 ;
462
-
463
- ZVAL_LONG (& tmp2 , pid );
464
- zend_hash_update (disp -> name_to_dispid , name , & tmp2 );
445
+ ZVAL_STR_COPY (& tmp , name );
446
+ pid = zend_hash_next_free_element (disp -> dispid_to_name );
447
+ zend_hash_index_update (disp -> dispid_to_name , pid , & tmp );
465
448
466
- zend_string_release_ex (name , 0 );
467
- }
449
+ ZVAL_LONG (& tmp , pid );
450
+ zend_hash_update (disp -> name_to_dispid , name , & tmp );
451
+ } ZEND_HASH_FOREACH_END ();
468
452
}
469
453
470
454
/* functions */
471
455
if (Z_OBJCE (disp -> object )) {
472
- zend_hash_internal_pointer_reset_ex (& Z_OBJCE (disp -> object )-> function_table , & pos );
473
- while (HASH_KEY_NON_EXISTENT != (keytype =
474
- zend_hash_get_current_key_ex (& Z_OBJCE (disp -> object )-> function_table ,
475
- & name , & pid , & pos ))) {
476
-
477
- char namebuf [32 ];
478
- if (keytype == HASH_KEY_IS_LONG ) {
479
- snprintf (namebuf , sizeof (namebuf ), ZEND_ULONG_FMT , pid );
480
- name = zend_string_init (namebuf , strlen (namebuf ), 0 );
481
- } else {
482
- zend_string_addref (name );
483
- }
456
+ ZEND_HASH_FOREACH_STR_KEY (& Z_OBJCE (disp -> object )-> function_table , name ) {
457
+ ZEND_ASSERT (name );
484
458
485
- zend_hash_move_forward_ex (& Z_OBJCE (disp -> object )-> function_table , & pos );
486
-
487
- /* Find the existing id */
488
- if ((tmp = zend_hash_find (disp -> name_to_dispid , name )) != NULL ) {
489
- zend_string_release_ex (name , 0 );
459
+ /* Check ID exists */
460
+ if (!zend_hash_exists (disp -> name_to_dispid , name )) {
490
461
continue ;
491
462
}
492
463
493
464
/* add the mappings */
494
- ZVAL_STR_COPY (& tmp2 , name );
495
- zend_hash_next_index_insert (disp -> dispid_to_name , & tmp2 );
496
- pid = zend_hash_next_free_element (disp -> dispid_to_name ) - 1 ;
497
-
498
- ZVAL_LONG (& tmp2 , pid );
499
- zend_hash_update (disp -> name_to_dispid , name , & tmp2 );
500
-
501
- zend_string_release_ex (name , 0 );
502
- }
465
+ ZVAL_LONG (& tmp , pid );
466
+ zend_hash_update (disp -> name_to_dispid , name , & tmp );
467
+ } ZEND_HASH_FOREACH_END ();
503
468
}
504
469
}
505
470
@@ -540,15 +505,9 @@ static void disp_destructor(php_dispatchex *disp)
540
505
CoTaskMemFree (disp );
541
506
}
542
507
543
- PHP_COM_DOTNET_API IDispatch * php_com_wrapper_export_as_sink (zval * val , GUID * sinkid ,
544
- HashTable * id_to_name )
508
+ PHP_COM_DOTNET_API IDispatch * php_com_wrapper_export_as_sink (zval * val , GUID * sinkid , HashTable * id_to_name )
545
509
{
546
510
php_dispatchex * disp = disp_constructor (val );
547
- HashPosition pos ;
548
- zend_string * name = NULL ;
549
- zval tmp , * ntmp ;
550
- int keytype ;
551
- zend_ulong pid ;
552
511
553
512
disp -> dispid_to_name = id_to_name ;
554
513
@@ -558,20 +517,16 @@ PHP_COM_DOTNET_API IDispatch *php_com_wrapper_export_as_sink(zval *val, GUID *si
558
517
ALLOC_HASHTABLE (disp -> name_to_dispid );
559
518
zend_hash_init (disp -> name_to_dispid , 0 , NULL , ZVAL_PTR_DTOR , 0 );
560
519
561
- zend_hash_internal_pointer_reset_ex (id_to_name , & pos );
562
- while (HASH_KEY_NON_EXISTENT != (keytype =
563
- zend_hash_get_current_key_ex (id_to_name , & name , & pid , & pos ))) {
564
-
565
- if (keytype == HASH_KEY_IS_LONG ) {
566
-
567
- ntmp = zend_hash_get_current_data_ex (id_to_name , & pos );
568
-
569
- ZVAL_LONG (& tmp , pid );
570
- zend_hash_update (disp -> name_to_dispid , Z_STR_P (ntmp ), & tmp );
571
- }
572
-
573
- zend_hash_move_forward_ex (id_to_name , & pos );
574
- }
520
+ ZEND_ASSERT (zend_array_is_list (id_to_name ));
521
+ zend_ulong pid ;
522
+ zval * value ;
523
+ ZEND_HASH_FOREACH_NUM_KEY_VAL (id_to_name , pid , value ) {
524
+ ZEND_ASSERT (Z_TYPE_P (value ) == IS_STRING );
525
+
526
+ zval tmp ;
527
+ ZVAL_LONG (& tmp , pid );
528
+ zend_hash_update (disp -> name_to_dispid , Z_STR_P (value ), & tmp );
529
+ } ZEND_HASH_FOREACH_END ();
575
530
576
531
return (IDispatch * )disp ;
577
532
}
0 commit comments