MongoDB.Bson.IO.MultiChunkBuffer.ShrinkCapacity C# (CSharp) Method

ShrinkCapacity() private method

private ShrinkCapacity ( int targetCapacity ) : void
targetCapacity int
return void
        private void ShrinkCapacity(int targetCapacity)
        {
            while (_capacity > targetCapacity && (_capacity - targetCapacity) >= _chunkSize)
            {
                var lastIndex = _chunks.Count - 1;
                _chunks[lastIndex].DecrementReferenceCount();
                _chunks.RemoveAt(lastIndex);
                _capacity -= _chunkSize;
            }

            if (_length > targetCapacity)
            {
                _length = targetCapacity;
            }
            if (_position > targetCapacity)
            {
                _position = targetCapacity;
            }
        }
    }