Ipv4L3Protocol::GetInterface optimization

This commit is contained in:
Mathieu Lacage
2009-11-06 15:16:18 -08:00
parent a0ff88e591
commit f8fe3ebcb3
2 changed files with 7 additions and 13 deletions

View File

@@ -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 (Ptr<Ipv4Interface>interface)
{
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<Ipv4Interface>
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

View File

@@ -22,6 +22,7 @@
#define IPV4_L3_PROTOCOL_H
#include <list>
#include <vector>
#include <stdint.h>
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
@@ -233,7 +234,7 @@ private:
Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const;
typedef std::list<Ptr<Ipv4Interface> > Ipv4InterfaceList;
typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList;
typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;