Skip to content

Commit

Permalink
all: optimized cast to cPacket: check it with isPacket()
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoltanBojthe authored and levy committed Jan 16, 2024
1 parent ddf3e10 commit 34b76a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/inet/common/FingerprintCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,26 @@ bool FingerprintCalculator::addEventIngredient(cEvent *event, cSingleFingerprint
case NETWORK_COMMUNICATION_FILTER:
break;
case NETWORK_NODE_PATH:
if (auto cpacket = dynamic_cast<cPacket *>(event)) {
if (event->isPacket()) {
auto cpacket = static_cast<cPacket *>(event);
if (auto senderNode = findContainingNode(cpacket->getSenderModule()))
hasher_ << senderNode->getFullPath();
if (auto arrivalNode = findContainingNode(cpacket->getArrivalModule()))
hasher_ << arrivalNode->getFullPath();
}
break;
case NETWORK_INTERFACE_PATH:
if (auto cpacket = dynamic_cast<cPacket *>(event)) {
if (event->isPacket()) {
auto cpacket = static_cast<cPacket *>(event);
if (auto senderInterface = findContainingNicModule(cpacket->getSenderModule()))
hasher_ << senderInterface->getInterfaceFullPath();
if (auto arrivalInterface = findContainingNicModule(cpacket->getArrivalModule()))
hasher_ << arrivalInterface->getInterfaceFullPath();
}
break;
case PACKET_DATA: {
if (auto cpacket = dynamic_cast<cPacket *>(event)) {
if (event->isPacket()) {
auto cpacket = static_cast<cPacket *>(event);
auto packet = dynamic_cast<Packet *>(cpacket);
if (packet == nullptr)
packet = dynamic_cast<Packet *>(cpacket->getEncapsulatedPacket());
Expand Down
5 changes: 3 additions & 2 deletions src/inet/common/misc/ThruputMeteringChannel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ cChannel::Result ThruputMeteringChannel::processMessage(cMessage *msg, const Sen
{
cChannel::Result result = cDatarateChannel::processMessage(msg, options, t);

cPacket *pkt = dynamic_cast<cPacket *>(msg);
// TODO handle disabled state (show with different style?/color? or print "disabled"?)
if (!pkt || !fmt || *fmt == 0 || result.discard)
if (!msg->isPacket() || !fmt || *fmt == 0 || result.discard)
return result;

cPacket *pkt = static_cast<cPacket *>(msg);

// count packets and bits
numPackets++;
numBits += pkt->getBitLength();
Expand Down

0 comments on commit 34b76a2

Please sign in to comment.