Пример #1
0
 private void Cleanup()
 {
     if (blocks.Count == 0)
     {
         return;
     }
     for (int i = 0, count = blocks.Count; i < count; ++i)
     {
         SegmentPool.Release(blocks[i]);
     }
     blocks.Clear();
     current = new Segment();
 }
Пример #2
0
        public void Trim()
        {
            int index, count;

            // position <- marker
            if (marker >= 0)
            {
                if (position != marker)
                {
                    Position = (marker - front);
                }
                marker = -1;
            }

            if (position == back)
            {
                // all the bytes consumed; leave only the leading block
                index = 1;
                count = blocks.Count - 1;
                front = back = 0;
            }
            else
            {
                // clip out leading blocks consumed
                index = 0;
                count = position >> sizeExponent;
                if (count >= blocks.Count)
                {
                    count = blocks.Count - 1;
                }
                front = position & remainderMask;
                back -= BlockSize * count;
            }

            if (count > 0)
            {
                List <Segment> blocksToRemove = blocks.GetRange(index, count);
                blocks.RemoveRange(index, count);
                for (int i = 0; i < blocksToRemove.Count; ++i)
                {
                    SegmentPool.Release(blocksToRemove[i]);
                }
            }

            Position = 0;
        }