Пример #1
0
 /// <summary>
 /// Sets the capacity of the collection preserving all of the
 /// existing instances by copying them over to the new structure.
 /// This is an expensive operation that should be avoided whenever
 /// possible.
 /// </summary>
 protected void SetCapacity(Int64 capacity)
 {
     if (capacity == 0)
     {
         ReusableArray = null;
     }
     else
     {
         var newArray = _arrayFactory.CreateAtLeast <T>(capacity);
         if (ReusableArray != null)
         {
             if (newArray.Size > _array.Size)
             {
                 ReusableArray.GetArray().CopyTo(newArray.GetArray(), 0);
             }
             else
             {
                 var newArrayData = newArray.GetArray();
                 var oldArray     = _array.GetArray();
                 for (var index = 0; index < newArray.Size; index++)
                 {
                     newArrayData[index] = oldArray[index];
                 }
             }
         }
         ReusableArray = newArray;
     }
 }