From f8fe3ebcb38a5dae87a14a91eeca09e4501c8b4c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 6 Nov 2009 15:16:18 -0800 Subject: [PATCH] Ipv4L3Protocol::GetInterface optimization --- src/internet-stack/ipv4-l3-protocol.cc | 17 +++++------------ src/internet-stack/ipv4-l3-protocol.h | 3 ++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/internet-stack/ipv4-l3-protocol.cc b/src/internet-stack/ipv4-l3-protocol.cc index 8e95c4f70..917548654 100644 --- a/src/internet-stack/ipv4-l3-protocol.cc +++ b/src/internet-stack/ipv4-l3-protocol.cc @@ -82,8 +82,7 @@ Ipv4L3Protocol::GetTypeId (void) } Ipv4L3Protocol::Ipv4L3Protocol() - : m_nInterfaces (0), - m_identification (0) + : m_identification (0) { NS_LOG_FUNCTION_NOARGS (); } @@ -266,9 +265,8 @@ uint32_t Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) { NS_LOG_FUNCTION (this << interface); - uint32_t index = m_nInterfaces; + uint32_t index = m_interfaces.size (); m_interfaces.push_back (interface); - m_nInterfaces++; return index; } @@ -276,14 +274,9 @@ Ptr Ipv4L3Protocol::GetInterface (uint32_t index) const { NS_LOG_FUNCTION (this << index); - uint32_t tmp = 0; - for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) + if (index < m_interfaces.size ()) { - if (index == tmp) - { - return *i; - } - tmp++; + return m_interfaces[index]; } return 0; } @@ -292,7 +285,7 @@ uint32_t Ipv4L3Protocol::GetNInterfaces (void) const { NS_LOG_FUNCTION_NOARGS (); - return m_nInterfaces; + return m_interfaces.size (); } int32_t diff --git a/src/internet-stack/ipv4-l3-protocol.h b/src/internet-stack/ipv4-l3-protocol.h index b58029820..e3996559c 100644 --- a/src/internet-stack/ipv4-l3-protocol.h +++ b/src/internet-stack/ipv4-l3-protocol.h @@ -22,6 +22,7 @@ #define IPV4_L3_PROTOCOL_H #include +#include #include #include "ns3/ipv4-address.h" #include "ns3/ptr.h" @@ -233,7 +234,7 @@ private: Ptr GetIcmp (void) const; bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const; - typedef std::list > Ipv4InterfaceList; + typedef std::vector > Ipv4InterfaceList; typedef std::list > SocketList; typedef std::list > L4List_t;