示例#1
0
 private static void ThrowInvalidNewCapacity(int minNewCapacity, int maxCapacity)
 {
     if (minNewCapacity < 0)
     {
         ThrowHelper.ThrowArgumentException_PositiveOrZero(minNewCapacity, ExceptionArgument.minNewCapacity);
     }
     if (minNewCapacity > maxCapacity)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException_MaxCapacity(minNewCapacity, maxCapacity);
     }
 }
 private static void ThrowInvalidNewCapacity(int minNewCapacity, int maxCapacity)
 {
     if ((uint)minNewCapacity > SharedConstants.TooBigOrNegative)
     {
         ThrowHelper.ThrowArgumentException_PositiveOrZero(minNewCapacity, ExceptionArgument.minNewCapacity);
     }
     if (minNewCapacity > maxCapacity)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException_MaxCapacity(minNewCapacity, maxCapacity);
     }
 }
示例#3
0
        public int CalculateNewCapacity(int minNewCapacity, int maxCapacity)
        {
            if (minNewCapacity < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException_MinNewCapacity(minNewCapacity);
            }
            if (minNewCapacity > maxCapacity)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException_MaxCapacity(minNewCapacity, maxCapacity);
            }

            const int Threshold = CalculateThreshold; // 4 MiB page

            if (minNewCapacity == CalculateThreshold)
            {
                return(Threshold);
            }

            int newCapacity;

            // If over threshold, do not double but just increase by threshold.
            if (minNewCapacity > Threshold)
            {
                newCapacity = minNewCapacity / Threshold * Threshold;
                if (newCapacity > maxCapacity - Threshold)
                {
                    newCapacity = maxCapacity;
                }
                else
                {
                    newCapacity += Threshold;
                }

                return(newCapacity);
            }

            // Not over threshold. Double up to 4 MiB, starting from 64.
            newCapacity = 64;
            while (newCapacity < minNewCapacity)
            {
                newCapacity <<= 1;
            }

            return(Math.Min(newCapacity, maxCapacity));
        }