fix bug 159
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri Apr 04 19:02:03 2008 +0200 (22 months ago)
changeset 28771e8a42e5d4c1
parent 2876 ab1e9244ab41
child 2878 580a733e49d6
fix bug 159
src/common/packet-metadata.cc
src/common/packet-metadata.h
utils/bench-packets.cc
     1.1 --- a/src/common/packet-metadata.cc	Fri Apr 04 07:28:27 2008 +0200
     1.2 +++ b/src/common/packet-metadata.cc	Fri Apr 04 19:02:03 2008 +0200
     1.3 @@ -36,7 +36,6 @@
     1.4  uint32_t PacketMetadata::m_maxSize = 0;
     1.5  uint16_t PacketMetadata::m_chunkUid = 0;
     1.6  PacketMetadata::DataFreeList PacketMetadata::m_freeList;
     1.7 -bool g_optOne = false;
     1.8  
     1.9  PacketMetadata::DataFreeList::~DataFreeList ()
    1.10  {
    1.11 @@ -60,12 +59,6 @@
    1.12    m_enable = true;
    1.13  }
    1.14  
    1.15 -void 
    1.16 -PacketMetadata::SetOptOne (bool optOne)
    1.17 -{
    1.18 -  g_optOne = optOne;
    1.19 -}
    1.20 -
    1.21  void
    1.22  PacketMetadata::ReserveCopy (uint32_t size)
    1.23  {
    1.24 @@ -186,27 +179,6 @@
    1.25    buffer[1] = value;
    1.26  }
    1.27  bool
    1.28 -PacketMetadata::TryToAppendFast (uint32_t value, uint8_t **pBuffer, uint8_t *end)
    1.29 -{
    1.30 -  uint8_t *start = *pBuffer;
    1.31 -  if (value < 0x80 && start < end)
    1.32 -    {
    1.33 -      start[0] = value;
    1.34 -      *pBuffer = start + 1;
    1.35 -      return true;
    1.36 -    }
    1.37 -  if (value < 0x4000 && start + 1 < end)
    1.38 -    {
    1.39 -      uint8_t byte = value & (~0x80);
    1.40 -      start[0] = 0x80 | byte;
    1.41 -      value >>= 7;
    1.42 -      start[1] = value;
    1.43 -      *pBuffer = start + 2;
    1.44 -      return true;
    1.45 -    }
    1.46 -  return false;
    1.47 -}
    1.48 -bool
    1.49  PacketMetadata::TryToAppend16 (uint16_t value,  uint8_t **pBuffer, uint8_t *end)
    1.50  {
    1.51    uint8_t *start = *pBuffer;
    1.52 @@ -423,65 +395,32 @@
    1.53  {
    1.54    NS_ASSERT (m_data != 0);
    1.55    NS_ASSERT (m_used != item->prev && m_used != item->next);
    1.56 -  if (g_optOne)
    1.57 -    {
    1.58 -      uint32_t typeUidSize = GetUleb128Size (item->typeUid);
    1.59 -      uint32_t sizeSize = GetUleb128Size (item->size);
    1.60 -      uint32_t n = typeUidSize + sizeSize + 2 + 2 + 2;
    1.61 -    restart:
    1.62 -      if (m_used + n <= m_data->m_size &&
    1.63 -      (m_head == 0xffff ||
    1.64 -       m_data->m_count == 1 ||
    1.65 -       m_used == m_data->m_dirtyEnd))
    1.66 -        {
    1.67 -          uint8_t *buffer = &m_data->m_data[m_used];
    1.68 -          Append16 (item->next, buffer);
    1.69 -          buffer += 2;
    1.70 -          Append16 (item->prev, buffer);
    1.71 -          buffer += 2;
    1.72 -          AppendValue (item->typeUid, buffer);
    1.73 -          buffer += typeUidSize;
    1.74 -          AppendValue (item->size, buffer);
    1.75 -          buffer += sizeSize;
    1.76 -          Append16 (item->chunkUid, buffer);
    1.77 -        }
    1.78 -      else
    1.79 -        {
    1.80 -          ReserveCopy (n);
    1.81 -          goto restart;
    1.82 -        }
    1.83 -      return n;
    1.84 -    }
    1.85 - append:
    1.86 -  uint8_t *start = &m_data->m_data[m_used];
    1.87 -  uint8_t *end = &m_data->m_data[m_data->m_size];
    1.88 -  if (end - start >= 8 &&
    1.89 +  uint32_t typeUidSize = GetUleb128Size (item->typeUid);
    1.90 +  uint32_t sizeSize = GetUleb128Size (item->size);
    1.91 +  uint32_t n = typeUidSize + sizeSize + 2 + 2 + 2;
    1.92 + restart:
    1.93 +  if (m_used + n <= m_data->m_size &&
    1.94        (m_head == 0xffff ||
    1.95         m_data->m_count == 1 ||
    1.96         m_used == m_data->m_dirtyEnd))
    1.97      {
    1.98 -      uint8_t *buffer = start;
    1.99 -
   1.100 +      uint8_t *buffer = &m_data->m_data[m_used];
   1.101        Append16 (item->next, buffer);
   1.102        buffer += 2;
   1.103        Append16 (item->prev, buffer);
   1.104        buffer += 2;
   1.105 -      if (TryToAppendFast (item->typeUid, &buffer, end) &&
   1.106 -          TryToAppendFast (item->size, &buffer, end) &&
   1.107 -          TryToAppend16 (item->chunkUid, &buffer, end))
   1.108 -        {
   1.109 -          uintptr_t written = buffer - start;
   1.110 -          NS_ASSERT (written <= 0xffff);
   1.111 -          NS_ASSERT (written >= 8);
   1.112 -          return written;
   1.113 -        }
   1.114 +      AppendValue (item->typeUid, buffer);
   1.115 +      buffer += typeUidSize;
   1.116 +      AppendValue (item->size, buffer);
   1.117 +      buffer += sizeSize;
   1.118 +      Append16 (item->chunkUid, buffer);
   1.119      }
   1.120 -  uint32_t n = GetUleb128Size (item->typeUid);
   1.121 -  n += GetUleb128Size (item->size);
   1.122 -  n += 2;
   1.123 -  n += 2 + 2;
   1.124 -  Reserve (n);
   1.125 -  goto append;
   1.126 +  else
   1.127 +    {
   1.128 +      ReserveCopy (n);
   1.129 +      goto restart;
   1.130 +    }
   1.131 +  return n;
   1.132  }
   1.133  
   1.134  uint16_t
     2.1 --- a/src/common/packet-metadata.h	Fri Apr 04 07:28:27 2008 +0200
     2.2 +++ b/src/common/packet-metadata.h	Fri Apr 04 19:02:03 2008 +0200
     2.3 @@ -124,7 +124,6 @@
     2.4    };
     2.5  
     2.6    static void Enable (void);
     2.7 -  static void SetOptOne (bool optOne);
     2.8  
     2.9    inline PacketMetadata (uint32_t uid, uint32_t size);
    2.10    inline PacketMetadata (PacketMetadata const &o);
    2.11 @@ -254,7 +253,6 @@
    2.12    uint32_t ReadUleb128 (const uint8_t **pBuffer) const;
    2.13    inline void Append16 (uint16_t value, uint8_t *buffer);
    2.14    inline bool TryToAppend (uint32_t value, uint8_t **pBuffer, uint8_t *end);
    2.15 -  inline bool TryToAppendFast (uint32_t value, uint8_t **pBuffer, uint8_t *end);
    2.16    inline bool TryToAppend32 (uint32_t value, uint8_t **pBuffer, uint8_t *end);
    2.17    inline bool TryToAppend16 (uint16_t value, uint8_t **pBuffer, uint8_t *end);
    2.18    void AppendValue (uint32_t value, uint8_t *buffer);
     3.1 --- a/utils/bench-packets.cc	Fri Apr 04 07:28:27 2008 +0200
     3.2 +++ b/utils/bench-packets.cc	Fri Apr 04 19:02:03 2008 +0200
     3.3 @@ -224,14 +224,9 @@
     3.4    runBench (&benchPtrC, n, "c");
     3.5  
     3.6    //runBench (&benchPrint, n, "print");
     3.7 -  PacketMetadata::SetOptOne (false);
     3.8    runBench (&benchPtrA, n, "meta-a");
     3.9    runBench (&benchPtrB, n, "meta-b");
    3.10    runBench (&benchPtrC, n, "meta-c");
    3.11 -  PacketMetadata::SetOptOne (true);
    3.12 -  runBench (&benchPtrA, n, "meta-a-opt");
    3.13 -  runBench (&benchPtrB, n, "meta-b-opt");
    3.14 -  runBench (&benchPtrC, n, "meta-c-opt");
    3.15  
    3.16  
    3.17    return 0;