#include "../../cmm/dispatch.h" #include #include struct base1 { virtual ~base1() {} virtual void foo() {} }; struct derived1_1 : base1 { virtual void foo() {} }; struct derived1_2 : base1 { virtual void foo() {} }; struct base2 : cmm_small_integer_typeid { virtual ~base2() {} virtual void foo() {} }; struct derived2_1 : base2 { virtual void foo() {} }; struct derived2_2 : base2 { virtual void foo() {} }; void fn1( virtual base1& a, virtual base1& b); void fn2( virtual base2& a, virtual base2& b); void fn1_( static derived1_1& /*a*/, static derived1_1& /*b*/) {} void fn1_( static derived1_1& /*a*/, static derived1_2& /*b*/) {} void fn1_( static derived1_2& /*a*/, static derived1_1& /*b*/) {} void fn1_( static derived1_2& /*a*/, static derived1_2& /*b*/) {} void fn2_( static base2&, static base2&) {} void fn2_( static base2&, static derived2_1&) {} void fn2_( static base2&, static derived2_2&) {} void fn2_( static derived2_1&, static base2&) {} void fn2_( static derived2_1&, static derived2_1&) {} void fn2_( static derived2_1&, static derived2_2&) {} void fn2_( static derived2_2&, static base2&) {} void fn2_( static derived2_2&, static derived2_1&) {} void fn2_( static derived2_2&, static derived2_2&) {} int main() { try { derived1_1 d1_1; derived1_2 d1_2; base2 b2; derived2_1 d2_1; derived2_2 d2_2; //fn1( d1_1, d1_1); //fn1( d1_1, d1_2); //fn1( d1_2, d1_1); //fn1( d1_2, d1_2); /*fn2( b2, b2); fn2( b2, d2_1); fn2( b2, d2_2); fn2( d2_1, b2); fn2( d2_1, d2_1); fn2( d2_1, d2_2); fn2( d2_2, b2); fn2( d2_2, d2_1); fn2( d2_2, d2_2);*/ cmm_virtualfn& virtualfn1 = cmm_get_virtualfn( "3fn22_1_5base21_5base2"); // ensure that the log-N cache contains lots of entries by looking up for many combinations of types. #define CALL( a, b) { const void* params[]={ &a, &b}; const std::type_info* types[] = { &typeid( a), &typeid( b)};\ cmm_lookup( virtualfn1, params, types); } CALL( b2, b2); CALL( b2, d2_1); CALL( b2, d2_2); CALL( d2_1, b2); CALL( d2_1, d2_1); CALL( d2_1, d2_2); CALL( d2_2, b2); CALL( d2_2, d2_1); CALL( d2_2, d2_2); #undef CALL std::cerr << "have called fn2 with all combinations\n"; int num_its; clock_t t; const void* params[] = { &d2_1, &d2_2}; const std::type_info* types[] = { &typeid( d2_1), &typeid( d2_2)}; const int ids[] = { d2_1.cmm_get_small_integer(), d2_2.cmm_get_small_integer() }; cmm_fnptr fn = cmm_lookup_nocache( virtualfn1, params, types); num_its = 100*1000; if ( cmm_lookup_nocache( virtualfn1, params, NULL) != fn) std::cerr << "cmm_lookup_nocache gave different fn\n"; t = clock(); for ( int i=0; i