Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert FieldCacheImpl delegate capture (Fixes #370, Closes #371) #389

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 96 additions & 6 deletions src/Lucene.Net/Search/FieldCacheImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public virtual FieldCache.Bytes GetBytes(AtomicReader reader, string field, Fiel
{
// Not cached here by FieldCacheImpl (cached instead
// per-thread by SegmentReader):
return new FieldCache.Bytes(get: (docID) => (byte)valuesIn.Get(docID));
return new FieldCache_BytesAnonymousInnerClassHelper(valuesIn);
}
else
{
Expand All @@ -604,6 +604,21 @@ public virtual FieldCache.Bytes GetBytes(AtomicReader reader, string field, Fiel
}
}

private class FieldCache_BytesAnonymousInnerClassHelper : FieldCache.Bytes
{
private readonly NumericDocValues valuesIn;

public FieldCache_BytesAnonymousInnerClassHelper(NumericDocValues valuesIn)
{
this.valuesIn = valuesIn;
}

public override byte Get(int docID)
{
return (byte)valuesIn.Get(docID);
}
}

internal class BytesFromArray : FieldCache.Bytes
{
private readonly sbyte[] values;
Expand Down Expand Up @@ -738,7 +753,7 @@ public virtual FieldCache.Int16s GetInt16s(AtomicReader reader, string field, Fi
{
// Not cached here by FieldCacheImpl (cached instead
// per-thread by SegmentReader):
return new FieldCache.Int16s(get: (docID) => (short)valuesIn.Get(docID));
return new FieldCache_Int16sAnonymousInnerClassHelper(valuesIn);
}
else
{
Expand All @@ -760,6 +775,21 @@ public virtual FieldCache.Int16s GetInt16s(AtomicReader reader, string field, Fi
}
}

private class FieldCache_Int16sAnonymousInnerClassHelper : FieldCache.Int16s
{
private readonly NumericDocValues valuesIn;

public FieldCache_Int16sAnonymousInnerClassHelper(NumericDocValues valuesIn)
{
this.valuesIn = valuesIn;
}

public override short Get(int docID)
{
return (short)valuesIn.Get(docID);
}
}

/// <summary>
/// NOTE: This was ShortsFromArray in Lucene
/// </summary>
Expand Down Expand Up @@ -895,7 +925,7 @@ public virtual FieldCache.Int32s GetInt32s(AtomicReader reader, string field, Fi
{
// Not cached here by FieldCacheImpl (cached instead
// per-thread by SegmentReader):
return new FieldCache.Int32s(get: (docID) => (int)valuesIn.Get(docID));
return new FieldCache_Int32sAnonymousInnerClassHelper(valuesIn);
}
else
{
Expand All @@ -917,6 +947,21 @@ public virtual FieldCache.Int32s GetInt32s(AtomicReader reader, string field, Fi
}
}

private class FieldCache_Int32sAnonymousInnerClassHelper : FieldCache.Int32s
{
private readonly NumericDocValues valuesIn;

public FieldCache_Int32sAnonymousInnerClassHelper(NumericDocValues valuesIn)
{
this.valuesIn = valuesIn;
}

public override int Get(int docID)
{
return (int)valuesIn.Get(docID);
}
}

/// <summary>
/// NOTE: This was IntsFromArray in Lucene
/// </summary>
Expand Down Expand Up @@ -1175,7 +1220,7 @@ public virtual FieldCache.Singles GetSingles(AtomicReader reader, string field,
{
// Not cached here by FieldCacheImpl (cached instead
// per-thread by SegmentReader):
return new FieldCache.Singles(get: (docID) => J2N.BitConversion.Int32BitsToSingle((int)valuesIn.Get(docID)));
return new FieldCache_SinglesAnonymousInnerClassHelper(valuesIn);
}
else
{
Expand All @@ -1197,6 +1242,21 @@ public virtual FieldCache.Singles GetSingles(AtomicReader reader, string field,
}
}

private class FieldCache_SinglesAnonymousInnerClassHelper : FieldCache.Singles
{
private readonly NumericDocValues valuesIn;

public FieldCache_SinglesAnonymousInnerClassHelper(NumericDocValues valuesIn)
{
this.valuesIn = valuesIn;
}

public override float Get(int docID)
{
return J2N.BitConversion.Int32BitsToSingle((int)valuesIn.Get(docID));
}
}

/// <summary>
/// NOTE: This was FloatsFromArray in Lucene
/// </summary>
Expand Down Expand Up @@ -1326,7 +1386,7 @@ public virtual FieldCache.Int64s GetInt64s(AtomicReader reader, string field, Fi
{
// Not cached here by FieldCacheImpl (cached instead
// per-thread by SegmentReader):
return new FieldCache.Int64s(get: (docID) => valuesIn.Get(docID));
return new FieldCache_Int64sAnonymousInnerClassHelper(valuesIn);
}
else
{
Expand All @@ -1348,6 +1408,21 @@ public virtual FieldCache.Int64s GetInt64s(AtomicReader reader, string field, Fi
}
}

private class FieldCache_Int64sAnonymousInnerClassHelper : FieldCache.Int64s
{
private readonly NumericDocValues valuesIn;

public FieldCache_Int64sAnonymousInnerClassHelper(NumericDocValues valuesIn)
{
this.valuesIn = valuesIn;
}

public override long Get(int docID)
{
return valuesIn.Get(docID);
}
}

/// <summary>
/// NOTE: This was LongsFromArray in Lucene
/// </summary>
Expand Down Expand Up @@ -1489,7 +1564,7 @@ public virtual FieldCache.Doubles GetDoubles(AtomicReader reader, string field,
{
// Not cached here by FieldCacheImpl (cached instead
// per-thread by SegmentReader):
return new FieldCache.Doubles(get: (docID) => J2N.BitConversion.Int64BitsToDouble(valuesIn.Get(docID)));
return new FieldCache_DoublesAnonymousInnerClassHelper(valuesIn);
}
else
{
Expand All @@ -1511,6 +1586,21 @@ public virtual FieldCache.Doubles GetDoubles(AtomicReader reader, string field,
}
}

private class FieldCache_DoublesAnonymousInnerClassHelper : FieldCache.Doubles
{
private readonly NumericDocValues valuesIn;

public FieldCache_DoublesAnonymousInnerClassHelper(NumericDocValues valuesIn)
{
this.valuesIn = valuesIn;
}

public override double Get(int docID)
{
return J2N.BitConversion.Int64BitsToDouble(valuesIn.Get(docID));
}
}

internal class DoublesFromArray : FieldCache.Doubles
{
private readonly double[] values;
Expand Down