@@ -632,6 +632,18 @@ PHPAPI zend_long php_count_recursive(HashTable *ht) /* {{{ */
632632}
633633/* }}} */
634634
635+ /* Consumes `zv` */
636+ static zend_always_inline zend_long php_get_long (zval * zv )
637+ {
638+ if (EXPECTED (Z_TYPE_P (zv ) == IS_LONG )) {
639+ return Z_LVAL_P (zv );
640+ } else {
641+ zend_long ret = zval_get_long_func (zv , false);
642+ zval_ptr_dtor (zv );
643+ return ret ;
644+ }
645+ }
646+
635647/* {{{ Count the number of elements in a variable (usually an array) */
636648PHP_FUNCTION (count )
637649{
@@ -677,8 +689,7 @@ PHP_FUNCTION(count)
677689 zend_function * count_fn = zend_hash_find_ptr (& zobj -> ce -> function_table , ZSTR_KNOWN (ZEND_STR_COUNT ));
678690 zend_call_known_instance_method_with_0_params (count_fn , zobj , & retval );
679691 if (Z_TYPE (retval ) != IS_UNDEF ) {
680- RETVAL_LONG (zval_get_long (& retval ));
681- zval_ptr_dtor (& retval );
692+ RETVAL_LONG (php_get_long (& retval ));
682693 }
683694 return ;
684695 }
@@ -811,20 +822,14 @@ static inline int php_array_user_compare_unstable(Bucket *f, Bucket *s) /* {{{ *
811822{
812823 zval args [2 ];
813824 zval retval ;
814- bool call_failed ;
815825
816- ZVAL_COPY (& args [0 ], & f -> val );
817- ZVAL_COPY (& args [1 ], & s -> val );
826+ ZVAL_COPY_VALUE (& args [0 ], & f -> val );
827+ ZVAL_COPY_VALUE (& args [1 ], & s -> val );
818828
819829 BG (user_compare_fci ).param_count = 2 ;
820830 BG (user_compare_fci ).params = args ;
821831 BG (user_compare_fci ).retval = & retval ;
822- call_failed = zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache )) == FAILURE || Z_TYPE (retval ) == IS_UNDEF ;
823- zval_ptr_dtor (& args [1 ]);
824- zval_ptr_dtor (& args [0 ]);
825- if (UNEXPECTED (call_failed )) {
826- return 0 ;
827- }
832+ zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache ));
828833
829834 if (UNEXPECTED (Z_TYPE (retval ) == IS_FALSE || Z_TYPE (retval ) == IS_TRUE )) {
830835 if (!ARRAYG (compare_deprecation_thrown )) {
@@ -836,23 +841,16 @@ static inline int php_array_user_compare_unstable(Bucket *f, Bucket *s) /* {{{ *
836841
837842 if (Z_TYPE (retval ) == IS_FALSE ) {
838843 /* Retry with swapped operands. */
839- ZVAL_COPY (& args [0 ], & s -> val );
840- ZVAL_COPY (& args [1 ], & f -> val );
841- call_failed = zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache )) == FAILURE || Z_TYPE (retval ) == IS_UNDEF ;
842- zval_ptr_dtor (& args [1 ]);
843- zval_ptr_dtor (& args [0 ]);
844- if (call_failed ) {
845- return 0 ;
846- }
844+ ZVAL_COPY_VALUE (& args [0 ], & s -> val );
845+ ZVAL_COPY_VALUE (& args [1 ], & f -> val );
846+ zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache ));
847847
848- zend_long ret = zval_get_long (& retval );
849- zval_ptr_dtor (& retval );
848+ zend_long ret = php_get_long (& retval );
850849 return - ZEND_NORMALIZE_BOOL (ret );
851850 }
852851 }
853852
854- zend_long ret = zval_get_long (& retval );
855- zval_ptr_dtor (& retval );
853+ zend_long ret = php_get_long (& retval );
856854 return ZEND_NORMALIZE_BOOL (ret );
857855}
858856/* }}} */
@@ -929,28 +927,22 @@ static inline int php_array_user_key_compare_unstable(Bucket *f, Bucket *s) /* {
929927{
930928 zval args [2 ];
931929 zval retval ;
932- bool call_failed ;
933930
934931 if (f -> key == NULL ) {
935932 ZVAL_LONG (& args [0 ], f -> h );
936933 } else {
937- ZVAL_STR_COPY (& args [0 ], f -> key );
934+ ZVAL_STR (& args [0 ], f -> key );
938935 }
939936 if (s -> key == NULL ) {
940937 ZVAL_LONG (& args [1 ], s -> h );
941938 } else {
942- ZVAL_STR_COPY (& args [1 ], s -> key );
939+ ZVAL_STR (& args [1 ], s -> key );
943940 }
944941
945942 BG (user_compare_fci ).param_count = 2 ;
946943 BG (user_compare_fci ).params = args ;
947944 BG (user_compare_fci ).retval = & retval ;
948- call_failed = zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache )) == FAILURE || Z_TYPE (retval ) == IS_UNDEF ;
949- zval_ptr_dtor (& args [1 ]);
950- zval_ptr_dtor (& args [0 ]);
951- if (UNEXPECTED (call_failed )) {
952- return 0 ;
953- }
945+ zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache ));
954946
955947 if (UNEXPECTED (Z_TYPE (retval ) == IS_FALSE || Z_TYPE (retval ) == IS_TRUE )) {
956948 if (!ARRAYG (compare_deprecation_thrown )) {
@@ -965,29 +957,22 @@ static inline int php_array_user_key_compare_unstable(Bucket *f, Bucket *s) /* {
965957 if (s -> key == NULL ) {
966958 ZVAL_LONG (& args [0 ], s -> h );
967959 } else {
968- ZVAL_STR_COPY (& args [0 ], s -> key );
960+ ZVAL_STR (& args [0 ], s -> key );
969961 }
970962 if (f -> key == NULL ) {
971963 ZVAL_LONG (& args [1 ], f -> h );
972964 } else {
973- ZVAL_STR_COPY (& args [1 ], f -> key );
965+ ZVAL_STR (& args [1 ], f -> key );
974966 }
975967
976- call_failed = zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache )) == FAILURE || Z_TYPE (retval ) == IS_UNDEF ;
977- zval_ptr_dtor (& args [1 ]);
978- zval_ptr_dtor (& args [0 ]);
979- if (call_failed ) {
980- return 0 ;
981- }
968+ zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache ));
982969
983- zend_long ret = zval_get_long (& retval );
984- zval_ptr_dtor (& retval );
970+ zend_long ret = php_get_long (& retval );
985971 return - ZEND_NORMALIZE_BOOL (ret );
986972 }
987973 }
988974
989- zend_long result = zval_get_long (& retval );
990- zval_ptr_dtor (& retval );
975+ zend_long result = php_get_long (& retval );
991976 return ZEND_NORMALIZE_BOOL (result );
992977}
993978/* }}} */
@@ -5065,13 +5050,9 @@ static int zval_user_compare(zval *a, zval *b) /* {{{ */
50655050 BG (user_compare_fci ).params = args ;
50665051 BG (user_compare_fci ).retval = & retval ;
50675052
5068- if (zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache )) == SUCCESS && Z_TYPE (retval ) != IS_UNDEF ) {
5069- zend_long ret = zval_get_long (& retval );
5070- zval_ptr_dtor (& retval );
5071- return ZEND_NORMALIZE_BOOL (ret );
5072- } else {
5073- return 0 ;
5074- }
5053+ zend_call_function (& BG (user_compare_fci ), & BG (user_compare_fci_cache ));
5054+ zend_long ret = php_get_long (& retval );
5055+ return ZEND_NORMALIZE_BOOL (ret );
50755056}
50765057/* }}} */
50775058
0 commit comments