Skip to content

Commit

Permalink
Lucene.Net.Search.FieldCacheImpl: Changed null equality comparisons f…
Browse files Browse the repository at this point in the history
…rom == to is
  • Loading branch information
NightOwl888 committed Sep 26, 2020
1 parent f320da8 commit 37d7ffd
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions src/Lucene.Net/Search/FieldCacheImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public virtual void Put(AtomicReader reader, TKey key, TValue value)
#else
lock (readerCache)
{
if (!readerCache.TryGetValue(readerKey, out innerCache) || innerCache == null)
if (!readerCache.TryGetValue(readerKey, out innerCache) || innerCache is null)
{
// First time this reader is using FieldCache
innerCache = new ConcurrentDictionary<TKey, object>
Expand Down Expand Up @@ -313,7 +313,7 @@ public virtual TValue Get(AtomicReader reader, TKey key, bool setDocsWithField)
#else
lock (readerCache)
{
if (!readerCache.TryGetValue(readerKey, out innerCache) || innerCache == null)
if (!readerCache.TryGetValue(readerKey, out innerCache) || innerCache is null)
{
// First time this reader is using FieldCache
innerCache = new ConcurrentDictionary<TKey, object>
Expand Down Expand Up @@ -357,7 +357,7 @@ public virtual TValue Get(AtomicReader reader, TKey key, bool setDocsWithField)
return (TValue)value;
}

private void PrintNewInsanity(TextWriter infoStream, object value)
private void PrintNewInsanity(TextWriter infoStream, TValue value)
{
FieldCacheSanityChecker.Insanity[] insanities = FieldCacheSanityChecker.CheckSanity(wrapper);
for (int i = 0; i < insanities.Length; i++)
Expand All @@ -366,7 +366,7 @@ private void PrintNewInsanity(TextWriter infoStream, object value)
FieldCache.CacheEntry[] entries = insanity.CacheEntries;
for (int j = 0; j < entries.Length; j++)
{
if (entries[j].Value == value)
if (ReferenceEquals(entries[j].Value, value))
{
// OK this insanity involves our entry
infoStream.WriteLine("WARNING: new FieldCache insanity created\nDetails: " + insanity.ToString());
Expand Down Expand Up @@ -476,7 +476,7 @@ public override bool Equals(object o)
/// Composes a hashcode based on the field and type. </summary>
public override int GetHashCode()
{
return field.GetHashCode() ^ (custom == null ? 0 : custom.GetHashCode());
return field.GetHashCode() ^ (custom is null ? 0 : custom.GetHashCode());
}
}

Expand Down Expand Up @@ -520,7 +520,7 @@ public virtual void DoUninvert(AtomicReader reader, string field, bool setDocsWi
VisitDoc(docID);
if (setDocsWithField)
{
if (docsWithField == null)
if (docsWithField is null)
{
// Lazy init
this.docsWithField = docsWithField = new FixedBitSet(maxDoc);
Expand All @@ -544,11 +544,13 @@ internal virtual void SetDocsWithField(AtomicReader reader, string field, IBits
{
int maxDoc = reader.MaxDoc;
IBits bits;
if (docsWithField == null)
if (docsWithField is null)
{
bits = new Lucene.Net.Util.Bits.MatchNoBits(maxDoc);
}
#pragma warning disable IDE0038 // Use pattern matching
else if (docsWithField is FixedBitSet)
#pragma warning restore IDE0038 // Use pattern matching
{
int numSet = ((FixedBitSet)docsWithField).Cardinality();
if (numSet >= maxDoc)
Expand Down Expand Up @@ -601,7 +603,7 @@ public virtual FieldCache.Bytes GetBytes(AtomicReader reader, string field, Fiel
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return FieldCache.Bytes.EMPTY;
}
Expand Down Expand Up @@ -653,7 +655,7 @@ protected override FieldCache.Bytes CreateValue(AtomicReader reader, CacheKey<Fi
#pragma warning disable 612, 618
FieldCache.IByteParser parser = key.custom;
#pragma warning restore 612, 618
if (parser == null)
if (parser is null)
{
// Confusing: must delegate to wrapper (vs simply
// setting parser = DEFAULT_INT16_PARSER) so cache
Expand Down Expand Up @@ -759,7 +761,7 @@ public virtual FieldCache.Int16s GetInt16s(AtomicReader reader, string field, Fi
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return FieldCache.Int16s.EMPTY;
}
Expand Down Expand Up @@ -814,7 +816,7 @@ protected override FieldCache.Int16s CreateValue(AtomicReader reader, CacheKey<F
short[] values;
#pragma warning disable 612, 618
FieldCache.IInt16Parser parser = key.custom;
if (parser == null)
if (parser is null)
{
// Confusing: must delegate to wrapper (vs simply
// setting parser = DEFAULT_INT16_PARSER) so cache
Expand Down Expand Up @@ -916,7 +918,7 @@ public virtual FieldCache.Int32s GetInt32s(AtomicReader reader, string field, Fi
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return FieldCache.Int32s.EMPTY;
}
Expand Down Expand Up @@ -995,7 +997,7 @@ internal Int32Cache(FieldCacheImpl wrapper)
protected override FieldCache.Int32s CreateValue(AtomicReader reader, CacheKey<FieldCache.IInt32Parser> key, bool setDocsWithField)
{
FieldCache.IInt32Parser parser = key.custom;
if (parser == null)
if (parser is null)
{
// Confusing: must delegate to wrapper (vs simply
// setting parser =
Expand Down Expand Up @@ -1025,7 +1027,7 @@ protected override FieldCache.Int32s CreateValue(AtomicReader reader, CacheKey<F
wrapper.SetDocsWithField(reader, key.field, u.docsWithField);
}
GrowableWriterAndMinValue values = valuesRef.Get();
if (values == null)
if (values is null)
{
return new Int32sFromArray(new PackedInt32s.NullReader(reader.MaxDoc), 0);
}
Expand All @@ -1052,7 +1054,7 @@ public UninvertAnonymousInnerClassHelper(AtomicReader reader, FieldCache.IInt32P
protected override void VisitTerm(BytesRef term)
{
currentValue = parser.ParseInt32(term);
if (values == null)
if (values is null)
{
// Lazy alloc so for the numeric field case
// (which will hit a FormatException
Expand Down Expand Up @@ -1094,7 +1096,7 @@ protected override TermsEnum GetTermsEnum(Terms terms)
public virtual IBits GetDocsWithField(AtomicReader reader, string field)
{
FieldInfo fieldInfo = reader.FieldInfos.FieldInfo(field);
if (fieldInfo == null)
if (fieldInfo is null)
{
// field does not exist or has no value
return new Lucene.Net.Util.Bits.MatchNoBits(reader.MaxDoc);
Expand Down Expand Up @@ -1139,7 +1141,7 @@ protected override IBits CreateValue(AtomicReader reader, CacheKey key, bool set
DocsEnum docs = null;
while (termsEnum.MoveNext())
{
if (res == null)
if (res is null)
{
// lazy init
res = new FixedBitSet(maxDoc);
Expand All @@ -1158,7 +1160,7 @@ protected override IBits CreateValue(AtomicReader reader, CacheKey key, bool set
}
}
}
if (res == null)
if (res is null)
{
return new Lucene.Net.Util.Bits.MatchNoBits(maxDoc);
}
Expand Down Expand Up @@ -1196,7 +1198,7 @@ public virtual FieldCache.Singles GetSingles(AtomicReader reader, string field,
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return FieldCache.Singles.EMPTY;
}
Expand Down Expand Up @@ -1244,7 +1246,7 @@ internal SingleCache(FieldCacheImpl wrapper)
protected override FieldCache.Singles CreateValue(AtomicReader reader, CacheKey<FieldCache.ISingleParser> key, bool setDocsWithField)
{
FieldCache.ISingleParser parser = key.custom;
if (parser == null)
if (parser is null)
{
// Confusing: must delegate to wrapper (vs simply
// setting parser =
Expand Down Expand Up @@ -1275,7 +1277,7 @@ protected override FieldCache.Singles CreateValue(AtomicReader reader, CacheKey<
}

float[] values = valuesRef.Get();
if (values == null)
if (values is null)
{
values = new float[reader.MaxDoc];
}
Expand All @@ -1301,7 +1303,7 @@ public UninvertAnonymousInnerClassHelper(AtomicReader reader, FieldCache.ISingle
protected override void VisitTerm(BytesRef term)
{
currentValue = parser.ParseSingle(term);
if (values == null)
if (values is null)
{
// Lazy alloc so for the numeric field case
// (which will hit a FormatException
Expand Down Expand Up @@ -1347,7 +1349,7 @@ public virtual FieldCache.Int64s GetInt64s(AtomicReader reader, string field, Fi
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return FieldCache.Int64s.EMPTY;
}
Expand Down Expand Up @@ -1397,7 +1399,7 @@ internal Int64Cache(FieldCacheImpl wrapper)
protected override FieldCache.Int64s CreateValue(AtomicReader reader, CacheKey<FieldCache.IInt64Parser> key, bool setDocsWithField)
{
FieldCache.IInt64Parser parser = key.custom;
if (parser == null)
if (parser is null)
{
// Confusing: must delegate to wrapper (vs simply
// setting parser =
Expand Down Expand Up @@ -1427,7 +1429,7 @@ protected override FieldCache.Int64s CreateValue(AtomicReader reader, CacheKey<F
wrapper.SetDocsWithField(reader, key.field, u.docsWithField);
}
GrowableWriterAndMinValue values = valuesRef.Get();
if (values == null)
if (values is null)
{
return new Int64sFromArray(new PackedInt32s.NullReader(reader.MaxDoc), 0L);
}
Expand All @@ -1454,7 +1456,7 @@ public UninvertAnonymousInnerClassHelper(AtomicReader reader, FieldCache.IInt64P
protected override void VisitTerm(BytesRef term)
{
currentValue = parser.ParseInt64(term);
if (values == null)
if (values is null)
{
// Lazy alloc so for the numeric field case
// (which will hit a FormatException
Expand Down Expand Up @@ -1510,7 +1512,7 @@ public virtual FieldCache.Doubles GetDoubles(AtomicReader reader, string field,
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return FieldCache.Doubles.EMPTY;
}
Expand Down Expand Up @@ -1552,7 +1554,7 @@ internal DoubleCache(FieldCacheImpl wrapper)
protected override FieldCache.Doubles CreateValue(AtomicReader reader, CacheKey<FieldCache.IDoubleParser> key, bool setDocsWithField)
{
FieldCache.IDoubleParser parser = key.custom;
if (parser == null)
if (parser is null)
{
// Confusing: must delegate to wrapper (vs simply
// setting parser =
Expand Down Expand Up @@ -1582,7 +1584,7 @@ protected override FieldCache.Doubles CreateValue(AtomicReader reader, CacheKey<
wrapper.SetDocsWithField(reader, key.field, u.docsWithField);
}
double[] values = valuesRef.Get();
if (values == null)
if (values is null)
{
values = new double[reader.MaxDoc];
}
Expand All @@ -1608,7 +1610,7 @@ public UninvertAnonymousInnerClassHelper(AtomicReader reader, FieldCache.IDouble
protected override void VisitTerm(BytesRef term)
{
currentValue = parser.ParseDouble(term);
if (values == null)
if (values is null)
{
// Lazy alloc so for the numeric field case
// (which will hit a FormatException
Expand Down Expand Up @@ -1683,7 +1685,7 @@ public virtual SortedDocValues GetTermsIndex(AtomicReader reader, string field,
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return DocValues.EMPTY_SORTED;
}
Expand Down Expand Up @@ -1838,7 +1840,7 @@ public virtual BinaryDocValues GetTerms(AtomicReader reader, string field, bool
public virtual BinaryDocValues GetTerms(AtomicReader reader, string field, bool setDocsWithField, float acceptableOverheadRatio)
{
BinaryDocValues valuesIn = reader.GetBinaryDocValues(field);
if (valuesIn == null)
if (valuesIn is null)
{
valuesIn = reader.GetSortedDocValues(field);
}
Expand All @@ -1851,7 +1853,7 @@ public virtual BinaryDocValues GetTerms(AtomicReader reader, string field, bool
}

FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return DocValues.EMPTY_BINARY;
}
Expand Down Expand Up @@ -2001,7 +2003,7 @@ public virtual SortedSetDocValues GetDocTermOrds(AtomicReader reader, string fie
}

FieldInfo info = reader.FieldInfos.FieldInfo(field);
if (info == null)
if (info is null)
{
return DocValues.EMPTY_SORTED_SET;
}
Expand Down Expand Up @@ -2040,7 +2042,7 @@ public virtual TextWriter InfoStream
set =>
// LUCENENET specific - use a SafeTextWriterWrapper to ensure that if the TextWriter
// is disposed by the caller (using block) we don't get any exceptions if we keep using it.
infoStream = value == null
infoStream = value is null
? null
: (value is SafeTextWriterWrapper ? value : new SafeTextWriterWrapper(value));
}
Expand Down

0 comments on commit 37d7ffd

Please sign in to comment.