Exemplo n.º 1
0
        private void MoveTo(ViewBuffer destination)
        {
            for (var i = 0; i < Count; i++)
            {
                var page = this[i];

                var destinationPage = destination.Count == 0 ? null : destination[destination.Count - 1];

                // If the source page is less or equal to than half full, let's copy it's content to the destination
                // page if possible.
                var isLessThanHalfFull = 2 * page.Count <= page.Capacity;
                if (isLessThanHalfFull && destinationPage != null &&
                    (destinationPage.Capacity - destinationPage.Count >= page.Count))
                {
                    // We have room, let's copy the items.
                    Array.Copy(page.Buffer, 0, destinationPage.Buffer, destinationPage.Count, page.Count);

                    destinationPage.Count += page.Count;

                    // Now we can return the source page, and it can be reused in the scope of this request.
                    Array.Clear(page.Buffer, 0, page.Count);
                    fBufferScope.ReturnSegment(page.Buffer);
                }
                else
                {
                    // Otherwise, let's just add the source page to the other buffer.
                    destination.AddPage(page);
                }
            }

            Clear();
        }
Exemplo n.º 2
0
 public void ReturnSegment(ViewBufferValue[] segment)
 {
     ensureCreated();
     scopedBuffer.ReturnSegment(segment);
 }