System.Text.StringBuilder.InternalEnsureCapacity C# (CSharp) Метод

InternalEnsureCapacity() приватный Метод

private InternalEnsureCapacity ( int size ) : void
size int
Результат void
		private void InternalEnsureCapacity (int size) 
		{
			if (size > _str.Length || (object) _cached_str == (object) _str) {
				int capacity = _str.Length;

				// Try double buffer, if that doesn't work, set the length as capacity
				if (size > capacity) {
					
					// The first time a string is appended, we just set _cached_str
					// and _str to it. This allows us to do some optimizations.
					// Below, we take this into account.
					if ((object) _cached_str == (object) _str && capacity < constDefaultCapacity)
						capacity = constDefaultCapacity;
					
					capacity = capacity << 1;
					if (size > capacity)
						capacity = size;

					if (capacity >= Int32.MaxValue || capacity < 0)
						capacity = Int32.MaxValue;

					if (capacity > _maxCapacity && size <= _maxCapacity)
						capacity = _maxCapacity;
					
					if (capacity > _maxCapacity)
						throw new ArgumentOutOfRangeException ("size", "capacity was less than the current size.");
				}

				string tmp = String.InternalAllocateStr (capacity);
				if (_length > 0)
					String.CharCopy (tmp, 0, _str, 0, _length);

				_str = tmp;
			}

			_cached_str = null;
		}