simplify code logic
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed May 07 15:02:07 2008 -0700 (21 months ago)
changeset 3052f64799121881
parent 3051 399d3858d190
child 3053 a14d83bacc9c
simplify code logic
src/common/packet-metadata.cc
src/common/packet-metadata.h
     1.1 --- a/src/common/packet-metadata.cc	Wed May 07 15:01:45 2008 -0700
     1.2 +++ b/src/common/packet-metadata.cc	Wed May 07 15:02:07 2008 -0700
     1.3 @@ -398,28 +398,23 @@
     1.4    uint32_t typeUidSize = GetUleb128Size (item->typeUid);
     1.5    uint32_t sizeSize = GetUleb128Size (item->size);
     1.6    uint32_t n = typeUidSize + sizeSize + 2 + 2 + 2;
     1.7 - restart:
     1.8 -  if (m_used + n <= m_data->m_size &&
     1.9 -      (m_head == 0xffff ||
    1.10 -       m_data->m_count == 1 ||
    1.11 -       m_used == m_data->m_dirtyEnd))
    1.12 -    {
    1.13 -      uint8_t *buffer = &m_data->m_data[m_used];
    1.14 -      Append16 (item->next, buffer);
    1.15 -      buffer += 2;
    1.16 -      Append16 (item->prev, buffer);
    1.17 -      buffer += 2;
    1.18 -      AppendValue (item->typeUid, buffer);
    1.19 -      buffer += typeUidSize;
    1.20 -      AppendValue (item->size, buffer);
    1.21 -      buffer += sizeSize;
    1.22 -      Append16 (item->chunkUid, buffer);
    1.23 -    }
    1.24 -  else
    1.25 +  if (m_used + n > m_data->m_size ||
    1.26 +      (m_head != 0xffff &&
    1.27 +       m_data->m_count != 1 &&
    1.28 +       m_used != m_data->m_dirtyEnd))
    1.29      {
    1.30        ReserveCopy (n);
    1.31 -      goto restart;
    1.32      }
    1.33 +  uint8_t *buffer = &m_data->m_data[m_used];
    1.34 +  Append16 (item->next, buffer);
    1.35 +  buffer += 2;
    1.36 +  Append16 (item->prev, buffer);
    1.37 +  buffer += 2;
    1.38 +  AppendValue (item->typeUid, buffer);
    1.39 +  buffer += typeUidSize;
    1.40 +  AppendValue (item->size, buffer);
    1.41 +  buffer += sizeSize;
    1.42 +  Append16 (item->chunkUid, buffer);
    1.43    return n;
    1.44  }
    1.45  
     2.1 --- a/src/common/packet-metadata.h	Wed May 07 15:01:45 2008 -0700
     2.2 +++ b/src/common/packet-metadata.h	Wed May 07 15:02:07 2008 -0700
     2.3 @@ -249,13 +249,13 @@
     2.4                      uint32_t available);
     2.5    inline void UpdateHead (uint16_t written);
     2.6    inline void UpdateTail (uint16_t written);
     2.7 -  uint32_t GetUleb128Size (uint32_t value) const;
     2.8 +  inline uint32_t GetUleb128Size (uint32_t value) const;
     2.9    uint32_t ReadUleb128 (const uint8_t **pBuffer) const;
    2.10    inline void Append16 (uint16_t value, uint8_t *buffer);
    2.11    inline bool TryToAppend (uint32_t value, uint8_t **pBuffer, uint8_t *end);
    2.12    inline bool TryToAppend32 (uint32_t value, uint8_t **pBuffer, uint8_t *end);
    2.13    inline bool TryToAppend16 (uint16_t value, uint8_t **pBuffer, uint8_t *end);
    2.14 -  void AppendValue (uint32_t value, uint8_t *buffer);
    2.15 +  inline void AppendValue (uint32_t value, uint8_t *buffer);
    2.16    void AppendValueExtra (uint32_t value, uint8_t *buffer);
    2.17    inline void Reserve (uint32_t n);
    2.18    void ReserveCopy (uint32_t n);