diff --git a/src/Lucene.Net/Search/FieldCacheImpl.cs b/src/Lucene.Net/Search/FieldCacheImpl.cs index 93ac26c523..a82214f9e9 100644 --- a/src/Lucene.Net/Search/FieldCacheImpl.cs +++ b/src/Lucene.Net/Search/FieldCacheImpl.cs @@ -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 @@ -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 @@ -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++) @@ -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()); @@ -476,7 +476,7 @@ public override bool Equals(object o) /// Composes a hashcode based on the field and type. 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 @@ 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); @@ -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) @@ -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; } @@ -653,7 +655,7 @@ protected override FieldCache.Bytes CreateValue(AtomicReader reader, CacheKey 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 @@ protected override FieldCache.Int32s CreateValue(AtomicReader reader, CacheKey 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 @@ protected override FieldCache.Singles CreateValue(AtomicReader reader, CacheKey< } float[] values = valuesRef.Get(); - if (values == null) + if (values is null) { values = new float[reader.MaxDoc]; } @@ -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 @@ -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; } @@ -1397,7 +1399,7 @@ internal Int64Cache(FieldCacheImpl wrapper) protected override FieldCache.Int64s CreateValue(AtomicReader reader, CacheKey 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 @@ protected override FieldCache.Int64s CreateValue(AtomicReader reader, CacheKey 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 @@ 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]; } @@ -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 @@ -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; } @@ -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); } @@ -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; } @@ -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; } @@ -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)); }