Lucene.Net.Search.FieldCacheImpl: Changed null equality comparisons from == to is
diff --git a/src/Lucene.Net/Search/FieldCacheImpl.cs b/src/Lucene.Net/Search/FieldCacheImpl.cs
index 93ac26c..a82214f 100644
--- a/src/Lucene.Net/Search/FieldCacheImpl.cs
+++ b/src/Lucene.Net/Search/FieldCacheImpl.cs
@@ -279,7 +279,7 @@
#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>
@@ -313,7 +313,7 @@
#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>
@@ -357,7 +357,7 @@
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++)
@@ -366,7 +366,7 @@
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());
@@ -476,7 +476,7 @@
/// 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());
}
}
@@ -520,7 +520,7 @@
VisitDoc(docID);
if (setDocsWithField)
{
- if (docsWithField == null)
+ if (docsWithField is null)
{
// Lazy init
this.docsWithField = docsWithField = new FixedBitSet(maxDoc);
@@ -544,11 +544,13 @@
{
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)
@@ -601,7 +603,7 @@
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return FieldCache.Bytes.EMPTY;
}
@@ -653,7 +655,7 @@
#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
@@ -759,7 +761,7 @@
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return FieldCache.Int16s.EMPTY;
}
@@ -814,7 +816,7 @@
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
@@ -916,7 +918,7 @@
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return FieldCache.Int32s.EMPTY;
}
@@ -995,7 +997,7 @@
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 =
@@ -1025,7 +1027,7 @@
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);
}
@@ -1052,7 +1054,7 @@
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
@@ -1094,7 +1096,7 @@
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);
@@ -1139,7 +1141,7 @@
DocsEnum docs = null;
while (termsEnum.MoveNext())
{
- if (res == null)
+ if (res is null)
{
// lazy init
res = new FixedBitSet(maxDoc);
@@ -1158,7 +1160,7 @@
}
}
}
- if (res == null)
+ if (res is null)
{
return new Lucene.Net.Util.Bits.MatchNoBits(maxDoc);
}
@@ -1196,7 +1198,7 @@
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return FieldCache.Singles.EMPTY;
}
@@ -1244,7 +1246,7 @@
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 =
@@ -1275,7 +1277,7 @@
}
float[] values = valuesRef.Get();
- if (values == null)
+ if (values is null)
{
values = new float[reader.MaxDoc];
}
@@ -1301,7 +1303,7 @@
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
@@ -1347,7 +1349,7 @@
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return FieldCache.Int64s.EMPTY;
}
@@ -1397,7 +1399,7 @@
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 =
@@ -1427,7 +1429,7 @@
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);
}
@@ -1454,7 +1456,7 @@
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
@@ -1510,7 +1512,7 @@
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return FieldCache.Doubles.EMPTY;
}
@@ -1552,7 +1554,7 @@
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 =
@@ -1582,7 +1584,7 @@
wrapper.SetDocsWithField(reader, key.field, u.docsWithField);
}
double[] values = valuesRef.Get();
- if (values == null)
+ if (values is null)
{
values = new double[reader.MaxDoc];
}
@@ -1608,7 +1610,7 @@
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
@@ -1683,7 +1685,7 @@
else
{
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return DocValues.EMPTY_SORTED;
}
@@ -1838,7 +1840,7 @@
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);
}
@@ -1851,7 +1853,7 @@
}
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return DocValues.EMPTY_BINARY;
}
@@ -2001,7 +2003,7 @@
}
FieldInfo info = reader.FieldInfos.FieldInfo(field);
- if (info == null)
+ if (info is null)
{
return DocValues.EMPTY_SORTED_SET;
}
@@ -2040,7 +2042,7 @@
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));
}