Skip to content

Commit

Permalink
- reduce the heap allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler committed Jun 16, 2024
1 parent 34bc333 commit c8faf67
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/AbstractAllTermDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public bool Next(IState state)
return SkipTo(internalDoc + 1, state);
}

public int Read(int[] docs, int[] freqs, IState state)
public int Read(Span<int> docs, Span<int> freqs, IState state)
{
int length = docs.Length;
int i = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/DirectoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ public virtual bool Next(IState state)
}

/// <summary>Optimized implementation. </summary>
public virtual int Read(int[] docs, int[] freqs, IState state)
public virtual int Read(Span<int> docs, Span<int> freqs, IState state)
{
while (true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/FilterIndexReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public virtual bool Next(IState state)
{
return in_Renamed.Next(state);
}
public virtual int Read(int[] docs, int[] freqs, IState state)
public virtual int Read(Span<int> docs, Span<int> freqs, IState state)
{
return in_Renamed.Read(docs, freqs, state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/MultipleTermPositions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public virtual void Seek(TermEnum termEnum, IState state)

/// <summary> Not implemented.</summary>
/// <throws> UnsupportedOperationException </throws>
public virtual int Read(int[] arg0, int[] arg1, IState state)
public virtual int Read(Span<int> arg0, Span<int> arg1, IState state)
{
throw new System.NotSupportedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/ParallelReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public virtual bool Next(IState state)
return termDocs.Next(state);
}

public virtual int Read(int[] docs, int[] freqs, IState state)
public virtual int Read(Span<int> docs, Span<int> freqs, IState state)
{
if (termDocs == null)
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net/Index/SegmentTermDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public virtual bool Next(IState state)
}

/// <summary>Optimized implementation. </summary>
public virtual int Read(int[] docs, int[] freqs, IState state)
public virtual int Read(Span<int> docs, Span<int> freqs, IState state)
{
int length = docs.Length;
if (currentFieldOmitTermFreqAndPositions)
Expand Down Expand Up @@ -216,7 +216,7 @@ public virtual int Read(int[] docs, int[] freqs, IState state)
}
}

private int ReadNoTf(int[] docs, int[] freqs, int length, IState state)
private int ReadNoTf(Span<int> docs, Span<int> freqs, int length, IState state)
{
int i = 0;
while (i < length && count < df)
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/SegmentTermPositions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override bool Next(IState state)
return false;
}

public override int Read(int[] docs, int[] freqs, IState state)
public override int Read(Span<int> docs, Span<int> freqs, IState state)
{
throw new System.NotSupportedException("TermPositions does not support processing multiple documents in one call. Use TermDocs instead.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/TermDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public interface TermDocs : IDisposable
/// <p/>Returns the number of entries read. Zero is only returned when the
/// stream has been exhausted.
/// </summary>
int Read(int[] docs, int[] freqs, IState state);
int Read(Span<int> docs, Span<int> freqs, IState state);

/// <summary>Skips entries to the first beyond the current whose document number is
/// greater than or equal to <i>target</i>. <p/>Returns true iff there is such
Expand Down
5 changes: 3 additions & 2 deletions src/Lucene.Net/Search/MultiTermQueryWrapperFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ public override DocIdSet GetDocIdSet(IndexReader reader, IState state)
return DocIdSet.EMPTY_DOCIDSET;
// else fill into an OpenBitSet
OpenBitSet bitSet = new OpenBitSet(reader.MaxDoc);
int[] docs = new int[32];
int[] freqs = new int[32];
Span<int> docs = stackalloc int[32];
Span<int> freqs = stackalloc int[32];

TermDocs termDocs = reader.TermDocs(state);
try
{
Expand Down

0 comments on commit c8faf67

Please sign in to comment.