// TODO: once we remove the deprecated termText() method // and switch entirely to char[] termBuffer we don't need // to use this method anymore, only for late init of the buffer private void InitTermBuffer() { if (termBuffer == null) { if (termText == null) { termBuffer = new char[ArrayUtil.GetNextSize(MIN_BUFFER_SIZE)]; termLength = 0; } else { int length = termText.Length; if (length < MIN_BUFFER_SIZE) { length = MIN_BUFFER_SIZE; } termBuffer = new char[ArrayUtil.GetNextSize(length)]; termLength = termText.Length; SupportClass.TextSupport.GetCharsFromString(termText, 0, termText.Length, termBuffer, 0); termText = null; } } else { termText = null; } }
/// <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 /// {@link #SetTermBuffer(char[], int, int)}, /// {@link #SetTermBuffer(String)}, or /// {@link #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) { // The buffer is always at least MIN_BUFFER_SIZE newSize = newSize < MIN_BUFFER_SIZE?MIN_BUFFER_SIZE:newSize; //Preserve termText if (termText != null) { int ttLen = termText.Length; newSize = newSize < ttLen?ttLen:newSize; termBuffer = new char[ArrayUtil.GetNextSize(newSize)]; SupportClass.TextSupport.GetCharsFromString(termText, 0, termText.Length, termBuffer, 0); termText = null; } else { // no term Text, the first allocation termBuffer = new char[ArrayUtil.GetNextSize(newSize)]; } } else { if (termBuffer.Length < newSize) { // Not big enough; create a new array with slight // over allocation and preserve content char[] newCharBuffer = new char[ArrayUtil.GetNextSize(newSize)]; Array.Copy(termBuffer, 0, newCharBuffer, 0, termBuffer.Length); termBuffer = newCharBuffer; } } return(termBuffer); }
private void InitTermBuffer() { if (termBuffer == null) { termBuffer = new char[ArrayUtil.GetNextSize(MIN_BUFFER_SIZE)]; termLength = 0; } }
public void GetPostings(RawPostingList[] postings) { lock (this) { System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint("TermsHash.getPostings start")); System.Diagnostics.Debug.Assert(postingsFreeCount <= postingsFreeList.Length); System.Diagnostics.Debug.Assert(postingsFreeCount <= postingsAllocCount, "postingsFreeCount=" + postingsFreeCount + " postingsAllocCount=" + postingsAllocCount); int numToCopy; if (postingsFreeCount < postings.Length) { numToCopy = postingsFreeCount; } else { numToCopy = postings.Length; } int start = postingsFreeCount - numToCopy; System.Diagnostics.Debug.Assert(start >= 0); System.Diagnostics.Debug.Assert(start + numToCopy <= postingsFreeList.Length); System.Diagnostics.Debug.Assert(numToCopy <= postings.Length); Array.Copy(postingsFreeList, start, postings, 0, numToCopy); // Directly allocate the remainder if any if (numToCopy != postings.Length) { int extra = postings.Length - numToCopy; int newPostingsAllocCount = postingsAllocCount + extra; consumer.CreatePostings(postings, numToCopy, extra); System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint("TermsHash.getPostings after create")); postingsAllocCount += extra; if (trackAllocations) { docWriter.BytesAllocated(extra * bytesPerPosting); } if (newPostingsAllocCount > postingsFreeList.Length) { // Pre-allocate the postingsFreeList so it's large // enough to hold all postings we've given out postingsFreeList = new RawPostingList[ArrayUtil.GetNextSize(newPostingsAllocCount)]; } } postingsFreeCount -= numToCopy; if (trackAllocations) { docWriter.BytesUsed(postings.Length * bytesPerPosting); } } }
internal virtual FormatPostingsDocsConsumer AddTerm(System.String text) { int len = text.Length; if (termBuffer == null || termBuffer.Length < 1 + len) { termBuffer = new char[ArrayUtil.GetNextSize(1 + len)]; } for (int i = 0; i < len; i++) { termBuffer[i] = (char)text[i]; } termBuffer[len] = (char)(0xffff); return(AddTerm(termBuffer, 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 /// {@link #SetTermBuffer(char[], int, int)}, /// {@link #SetTermBuffer(String)}, or /// {@link #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) { // 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 and preserve content char[] 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]); } } }