private void InitTermBuffer() { if (termBuffer == null) { termBuffer = new char[ArrayUtil.GetNextSize(MIN_BUFFER_SIZE)]; termLength = 0; } }
/// <summary>Allocates a buffer char[] of at least newSize, without preserving the existing content. /// its always used in places that set the content /// </summary> /// <param name="newSize">minimum size of the buffer /// </param> private void GrowTermBuffer(int newSize) { if (termBuffer == null) { // The buffer is always at least MIN_BUFFER_SIZE termBuffer = new char[ArrayUtil.GetNextSize(newSize < MIN_BUFFER_SIZE?MIN_BUFFER_SIZE:newSize)]; } else { if (termBuffer.Length < newSize) { // Not big enough; create a new array with slight // over allocation: termBuffer = new char[ArrayUtil.GetNextSize(newSize)]; } } }
/// <summary>Grows the termBuffer to at least size newSize, preserving the /// existing content. Note: If the next operation is to change /// the contents of the term buffer use /// <see cref="SetTermBuffer(char[], int, int)" />, /// <see cref="SetTermBuffer(String)" />, or /// <see cref="SetTermBuffer(String, int, int)" /> /// to optimally combine the resize with the setting of the termBuffer. /// </summary> /// <param name="newSize">minimum size of the new termBuffer /// </param> /// <returns> newly created termBuffer with length >= newSize /// </returns> public virtual char[] ResizeTermBuffer(int newSize) { if (termBuffer == null) { termBuffer = new char[ArrayUtil.GetNextSize(newSize < MIN_BUFFER_SIZE ? MIN_BUFFER_SIZE : newSize)]; } else { if (termBuffer.Length < newSize) { // Not big enough; create a new array with slight // over allocation and preserve content var newCharBuffer = new char[ArrayUtil.GetNextSize(newSize)]; Array.Copy(termBuffer, 0, newCharBuffer, 0, termBuffer.Length); termBuffer = newCharBuffer; } } return(termBuffer); }
internal PerDoc GetPerDoc() { lock (this) { if (freeCount == 0) { allocCount++; if (allocCount > docFreeList.Length) { // Grow our free list up front to make sure we have // enough space to recycle all outstanding PerDoc // instances System.Diagnostics.Debug.Assert(allocCount == 1 + docFreeList.Length); docFreeList = new PerDoc[ArrayUtil.GetNextSize(allocCount)]; } return(new PerDoc(this)); } else { return(docFreeList[--freeCount]); } } }