private void ExpandAndInsertSpace(TSize fromIndex, TSize toIndex) { TSize itemCount = Size.Subtract(toIndex, fromIndex); TSize minCapacity = Size.Add(_capacity, itemCount); TSize newCapacity = _capacity; while (Size.Compare(newCapacity, minCapacity) < 0) { Size.MultiplyWith(ref newCapacity, 2); } T[] newArray = Size.CreateArray <T>(newCapacity); if (Size.Compare(itemCount, Size.Zero) > 0 && Size.Compare(fromIndex, _count) < 0) { Size.CopyArray(_innerArray, Size.Zero, fromIndex, newArray, Size.Zero); Size.CopyArray(_innerArray, fromIndex, _count, newArray, toIndex); } else { Size.CopyArray(_innerArray, Size.Zero, _count, newArray, Size.Zero); } _innerArray = newArray; _capacity = newCapacity; Size.AddWith(ref _count, itemCount); }
internal static TSize Count(Iterator begin, Iterator end) { StreamBuffer <T, TSize, TSizeOperations> parent = begin._parent; if (begin.Equals(parent.Begin) && end.Equals(parent.End)) { return(parent.Count); } BufferSegment segment = begin._segment; TSize count = Size.From(-begin._indexInSegment); if (segment != null) { while (segment != end._segment) { Size.AddWith(ref count, segment.Capacity); segment = segment.NextSegment; } Size.AddWith(ref count, end._indexInSegment); } return(count); }