protected void CheckCapacity(int requestedLength)
{
if (requestedLength + headIndex >= capacity)
{
// have to do something
if ((requestedLength + headIndex > (capacity >> 1))
&& (requestedLength < capacity - 1))
{
// we're more than half-way through the buffer, and shifting is enough
// so just shift
ShiftToZero();
}
else
{
// not far into buffer or shift wouldn't be enough anyway
Grow(0);
}
}
}