optimize Iterator::ReadU8
This commit is contained in:
@@ -753,39 +753,6 @@ Buffer::Iterator::Write (uint8_t const*buffer, uint32_t size)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t
|
||||
Buffer::Iterator::ReadU8 (void)
|
||||
{
|
||||
if (m_current < m_dataStart)
|
||||
{
|
||||
// XXX trying to read from outside of data area
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
else if (m_current < m_zeroStart)
|
||||
{
|
||||
uint8_t data = m_data[m_current];
|
||||
m_current++;
|
||||
return data;
|
||||
}
|
||||
else if (m_current < m_zeroEnd)
|
||||
{
|
||||
m_current++;
|
||||
return 0;
|
||||
}
|
||||
else if (m_current < m_dataEnd)
|
||||
{
|
||||
uint8_t data = m_data[m_current - (m_zeroEnd-m_zeroStart)];
|
||||
m_current++;
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
// XXX trying to read from outside of data area
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
// to quiet compiler.
|
||||
return 0;
|
||||
}
|
||||
uint16_t
|
||||
Buffer::Iterator::ReadU16 (void)
|
||||
{
|
||||
@@ -935,6 +902,40 @@ Buffer::Iterator::WriteU8 (uint8_t data, uint32_t len)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t
|
||||
Buffer::Iterator::ReadU8 (void)
|
||||
{
|
||||
if (m_current < m_dataStart)
|
||||
{
|
||||
// XXX trying to read from outside of data area
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
else if (m_current < m_zeroStart)
|
||||
{
|
||||
uint8_t data = m_data[m_current];
|
||||
m_current++;
|
||||
return data;
|
||||
}
|
||||
else if (m_current < m_zeroEnd)
|
||||
{
|
||||
m_current++;
|
||||
return 0;
|
||||
}
|
||||
else if (m_current < m_dataEnd)
|
||||
{
|
||||
uint8_t data = m_data[m_current - (m_zeroEnd-m_zeroStart)];
|
||||
m_current++;
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
// XXX trying to read from outside of data area
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
// to quiet compiler.
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* BUFFER_USE_INLINE */
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -184,7 +184,7 @@ public:
|
||||
* Read data and advance the Iterator by the number of bytes
|
||||
* read.
|
||||
*/
|
||||
uint8_t ReadU8 (void);
|
||||
BUFFER_INLINE uint8_t ReadU8 (void);
|
||||
/**
|
||||
* \return the two bytes read in the buffer.
|
||||
*
|
||||
@@ -398,6 +398,32 @@ Buffer::Iterator::WriteU8 (uint8_t data, uint32_t len)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t
|
||||
Buffer::Iterator::ReadU8 (void)
|
||||
{
|
||||
NS_ASSERT (m_current >= m_dataStart &&
|
||||
m_current <= m_dataEnd);
|
||||
|
||||
if (m_current < m_zeroStart)
|
||||
{
|
||||
uint8_t data = m_data[m_current];
|
||||
m_current++;
|
||||
return data;
|
||||
}
|
||||
else if (m_current < m_zeroEnd)
|
||||
{
|
||||
m_current++;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t data = m_data[m_current - (m_zeroEnd-m_zeroStart)];
|
||||
m_current++;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* BUFFER_USE_INLINE */
|
||||
|
||||
Reference in New Issue
Block a user