report the adjustment delta in Buffer::AddAtEnd and Buffer::AddAtStart.
--- a/src/common/buffer.cc Wed Apr 23 08:35:59 2008 -0700
+++ b/src/common/buffer.cc Wed Apr 23 08:54:29 2008 -0700
@@ -333,9 +333,10 @@
return m_end - (m_zeroAreaEnd - m_zeroAreaStart);
}
-void
+int32_t
Buffer::AddAtStart (uint32_t start)
{
+ int32_t delta;
NS_ASSERT (CheckInternalState ());
bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
if (m_start >= start && !isDirty)
@@ -347,6 +348,7 @@
*/
NS_ASSERT (m_data->m_count == 1 || m_start == m_data->m_dirtyStart);
m_start -= start;
+ delta = 0;
HEURISTICS (g_nAddNoRealloc++);
}
else
@@ -361,12 +363,14 @@
}
m_data = newData;
- int32_t delta = start - m_start;
- m_start = 0;
+ delta = start - m_start;
+ m_start += delta;
m_zeroAreaStart += delta;
m_zeroAreaEnd += delta;
m_end += delta;
+ m_start -= start;
+
HEURISTICS (g_nAddRealloc++);
}
HEURISTICS (m_maxZeroAreaStart = std::max (m_maxZeroAreaStart, m_zeroAreaStart));
@@ -375,10 +379,12 @@
m_data->m_dirtyEnd = m_end;
LOG_INTERNAL_STATE ("add start=" << start << ", ");
NS_ASSERT (CheckInternalState ());
+ return delta;
}
-void
+int32_t
Buffer::AddAtEnd (uint32_t end)
{
+ int32_t delta;
NS_ASSERT (CheckInternalState ());
bool isDirty = m_data->m_count > 1 && m_end < m_data->m_dirtyEnd;
if (GetInternalEnd () + end <= m_data->m_size && !isDirty)
@@ -391,6 +397,8 @@
NS_ASSERT (m_data->m_count == 1 || m_end == m_data->m_dirtyEnd);
m_end += end;
+ delta = 0;
+
HEURISTICS (g_nAddNoRealloc++);
}
else
@@ -405,10 +413,11 @@
}
m_data = newData;
+ delta = -m_start;
- m_zeroAreaStart -= m_start;
- m_zeroAreaEnd -= m_start;
- m_end -= m_start;
+ m_zeroAreaStart += delta;
+ m_zeroAreaEnd += delta;
+ m_end += delta;
m_start = 0;
m_end += end;
@@ -421,6 +430,8 @@
m_data->m_dirtyEnd = m_end;
LOG_INTERNAL_STATE ("add end=" << end << ", ");
NS_ASSERT (CheckInternalState ());
+
+ return delta;
}
void
--- a/src/common/buffer.h Wed Apr 23 08:35:59 2008 -0700
+++ b/src/common/buffer.h Wed Apr 23 08:54:29 2008 -0700
@@ -392,24 +392,36 @@
/**
* \param start size to reserve
+ * \returns the adjustment delta.
*
* Add bytes at the start of the Buffer. The
* content of these bytes is undefined but debugging
* builds initialize them to 0x33.
* Any call to this method invalidates any Iterator
* pointing to this Buffer.
+ *
+ * The value returned by this method indicates how the internal
+ * buffer was modified to handle the user request to reserve space.
+ * If that value is zero, the buffer was not modified: the user
+ * request was completed without further memory allocation.
*/
- void AddAtStart (uint32_t start);
+ int32_t AddAtStart (uint32_t start);
/**
* \param end size to reserve
+ * \returns the adjustment delta.
*
* Add bytes at the end of the Buffer. The
* content of these bytes is undefined but debugging
* builds initialize them to 0x33.
* Any call to this method invalidates any Iterator
* pointing to this Buffer.
+ *
+ * The value returned by this method indicates how the internal
+ * buffer was modified to handle the user request to reserve space.
+ * If that value is zero, the buffer was not modified: the user
+ * request was completed without further memory allocation.
*/
- void AddAtEnd (uint32_t end);
+ int32_t AddAtEnd (uint32_t end);
void AddAtEnd (const Buffer &o);
/**