@@ -1804,11 +1804,48 @@ ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2 TSR
1804
1804
1805
1805
static int protocol_check_function_implementation (void * function_entry TSRMLS_DC , int num_args , va_list args , zend_hash_key * hash_key );
1806
1806
1807
+ static void protocol_cache_dtor (void * data ) /* {{{ */
1808
+ {
1809
+ zend_hash_destroy ((HashTable * ) data );
1810
+ }
1811
+ /* }}} */
1812
+
1807
1813
ZEND_API zend_bool protocol_check_function (zend_class_entry * instance_ce , zend_class_entry * ce TSRMLS_DC ) /* {{{ */
1808
1814
{
1809
1815
zend_bool result = 1 ;
1816
+ HashTable * cache_bucket = NULL ;
1817
+ zend_bool * cache_result = NULL ;
1818
+
1819
+ if (!instance_ce -> protocol_cache ) {
1820
+ HashTable * * cache_bucket_ext = NULL ;
1821
+
1822
+ if (!EG (protocol_cache )) {
1823
+ EG (protocol_cache ) = (HashTable * ) malloc (sizeof (HashTable ));
1824
+ zend_hash_init (EG (protocol_cache ), 16 , NULL , protocol_cache_dtor , 1 );
1825
+ }
1826
+
1827
+ if (zend_hash_find (EG (protocol_cache ), instance_ce -> name , instance_ce -> name_length , (void * * ) & cache_bucket_ext ) == FAILURE ) {
1828
+ cache_bucket = (HashTable * ) malloc (sizeof (HashTable ));
1829
+ zend_hash_init (cache_bucket , 16 , NULL , NULL , 1 );
1830
+ zend_hash_add (EG (protocol_cache ), instance_ce -> name , instance_ce -> name_length , (void * ) & cache_bucket , sizeof (void * ), NULL );
1831
+ } else {
1832
+ cache_bucket = * cache_bucket_ext ;
1833
+ }
1834
+ instance_ce -> protocol_cache = cache_bucket ;
1835
+ } else {
1836
+ cache_bucket = instance_ce -> protocol_cache ;
1837
+ }
1838
+
1839
+ if (zend_hash_find (cache_bucket , ce -> name , ce -> name_length , (void * * ) & cache_result ) != FAILURE ) {
1840
+ return * cache_result ;
1841
+ }
1842
+
1843
+ if (0 == instanceof_function (instance_ce , ce )) {
1844
+ /* Short-circuit if types match */
1845
+ zend_hash_apply_with_arguments (& (ce -> function_table ), protocol_check_function_implementation , 2 , instance_ce , & result );
1846
+ }
1810
1847
1811
- zend_hash_apply_with_arguments ( & ( ce -> function_table ), protocol_check_function_implementation , 2 , instance_ce , & result );
1848
+ zend_hash_add ( cache_bucket , ce -> name , ce -> name_length , ( void * ) & result , sizeof ( zend_bool ), NULL );
1812
1849
1813
1850
return result ;
1814
1851
}
0 commit comments