From: tho Date: Mon, 21 Nov 2011 16:16:08 +0000 (+0000) Subject: Packet: optimized Packet.is<> member by removing dynamic_cast X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=16c01d1d27fd418ed90da642c69391199f6e5dc7;p=senf.git Packet: optimized Packet.is<> member by removing dynamic_cast git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1827 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/Packet.cti b/senf/Packets/Packet.cti index a428565..80bb93a 100644 --- a/senf/Packets/Packet.cti +++ b/senf/Packets/Packet.cti @@ -59,7 +59,10 @@ template prefix_ bool senf::Packet::is() const { - return valid() && ptr()->is(); + // ensure that the template class is included in the corresponding object file when linking: + { static typename PacketInterpreter::factory_t _ ( + PacketInterpreter::factory()); (void) _;} + return valid() && typeId() == typeIdValue(); } template diff --git a/senf/Packets/PacketInterpreter.cti b/senf/Packets/PacketInterpreter.cti index bafdf9e..459580b 100644 --- a/senf/Packets/PacketInterpreter.cti +++ b/senf/Packets/PacketInterpreter.cti @@ -41,14 +41,6 @@ // Interpreter chain access template -prefix_ bool senf::PacketInterpreterBase::is() -{ - // ensure that the template argument is included in the corresponding object file when linking: - { static typename PacketInterpreter::factory_t _ (PacketInterpreter::factory()); (void) _;} - return dynamic_cast< PacketInterpreter* >(this); -} - -template prefix_ typename senf::PacketInterpreter::ptr senf::PacketInterpreterBase::as() { // ensure that the template argument is included in the corresponding object file when linking: diff --git a/senf/Packets/PacketInterpreter.hh b/senf/Packets/PacketInterpreter.hh index 953c187..5696bd2 100644 --- a/senf/Packets/PacketInterpreter.hh +++ b/senf/Packets/PacketInterpreter.hh @@ -153,7 +153,6 @@ namespace senf { template typename PacketInterpreter::ptr parseNextAs(); ptr parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range); - template bool is(); template typename PacketInterpreter::ptr as(); ptr append(ptr packet); diff --git a/senf/Packets/PacketInterpreter.test.cc b/senf/Packets/PacketInterpreter.test.cc index 51c0a91..0e47ea1 100644 --- a/senf/Packets/PacketInterpreter.test.cc +++ b/senf/Packets/PacketInterpreter.test.cc @@ -66,7 +66,6 @@ SENF_AUTO_UNIT_TEST(packetInterpreterBase) BOOST_CHECK( pi2 == pi3->prev() ); BOOST_CHECK( pi1 == pi2->prev() ); BOOST_CHECK( ! pi1->prev() ); - BOOST_CHECK( pi2->is() ); BOOST_CHECK( pi2->as() == pi2 ); BOOST_CHECK( pi2->parseNextAs(senf::PacketInterpreter::factory(), pi2->nextPacketRange()) ); BOOST_CHECK( pi2->typeId() == pi1->typeId() ); @@ -238,7 +237,6 @@ SENF_AUTO_UNIT_TEST(packetInterpreter_factory) BOOST_CHECK( ! senf::PacketInterpreterBase::no_factory() ); BOOST_REQUIRE( factory ); - BOOST_CHECK( factory->create()->is() ); BOOST_CHECK_EQUAL( factory->create()->data().size(), 8u ); BOOST_CHECK_EQUAL( factory->create(senf::noinit)->data().size(), 0u ); BOOST_CHECK_EQUAL( factory->create(size_type(12u))->data().size(), 12u ); @@ -251,7 +249,6 @@ SENF_AUTO_UNIT_TEST(packetInterpreter_factory) (senf::PacketInterpreter::create()); BOOST_CHECK_EQUAL( p->data().size(), 0u); - BOOST_CHECK( factory->createAfter(p)->is() ); BOOST_REQUIRE( p->next() ); BOOST_CHECK( ! p->next()->next() ); @@ -303,8 +300,6 @@ SENF_AUTO_UNIT_TEST(packetInterpreter_factory) (senf::PacketInterpreter::create(size_type(12u))); senf::PacketInterpreterBase::ptr p2 (p->parseNextAs(factory, p->nextPacketRange())); - BOOST_CHECK( p2->is() ); - BOOST_CHECK( ! p2->is() ); BOOST_CHECK_EQUAL( unsigned(boost::size(*p2->nextPacketRange())), 4u ); }