Exemplo n.º 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;
     }
 }
Exemplo n.º 2
0
 public override string ToString()
 {
     if (ReusableArray == null || Length < 1)
     {
         return(String.Empty);
     }
     return(new String(ReusableArray.GetArray(), 0, (int)Length));
 }
Exemplo n.º 3
0
        public IStringBuilder Append(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(this);
            }
            var startIndex = Length;

            Length = Length + text.Length;
            text.CopyTo(0, ReusableArray.GetArray(), (int)startIndex, text.Length);
            return(this);
        }
Exemplo n.º 4
0
        private IArray <T> GetArray <T>(Pool <T> pool)
        {
            var array = (ReusableArray <T>)pool.DequeueOrDefault();

            if (array == null)
            {
                array = new ReusableArray <T>(pool.ArraySize);
            }

            return(array.Initialize(
                       (IReusable reusable) =>
            {
                var a = (IArray <T>)reusable;
                if (a.IsReusable)
                {
                    pool.Enqueue(a);
                }
            }));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Sorts the collection using the provided comparer
 /// </summary>
 public void Sort(IComparer <T> comparer)
 {
     Array.Sort(ReusableArray.GetArray(), 0, (int)Length, comparer);
 }