From 3c012530e85930cf016f96a6825a48176c2f846f Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Tue, 3 Nov 2020 22:42:45 +0700 Subject: [PATCH] SWEEP: Use IndexOptionsComparer class to avoid the boxing associated with System.Enum.CompareTo() on IndexOptions enum (closes #375, closes #376) --- .../BlockTerms/BlockTermsReader.cs | 10 +++-- .../Memory/DirectPostingsFormat.cs | 7 ++-- .../Memory/FSTOrdTermsReader.cs | 7 ++-- .../Memory/FSTTermsReader.cs | 7 ++-- .../Memory/MemoryPostingsFormat.cs | 13 ++++--- .../Pulsing/PulsingPostingsReader.cs | 12 ++++-- .../Pulsing/PulsingPostingsWriter.cs | 9 +++-- .../Sep/SepPostingsWriter.cs | 3 +- .../SimpleText/SimpleTextFieldInfosWriter.cs | 4 +- .../SimpleText/SimpleTextFieldsReader.cs | 17 +++++---- .../SimpleText/SimpleTextFieldsWriter.cs | 13 ++++--- .../Index/Sorter/SortingAtomicReader.cs | 6 ++- .../Asserting/AssertingPostingsFormat.cs | 3 +- .../Codecs/Lucene3x/PreFlexRWFieldsWriter.cs | 3 +- .../Lucene40/Lucene40FieldInfosWriter.cs | 3 +- .../Codecs/Lucene40/Lucene40PostingsWriter.cs | 9 +++-- .../Lucene42/Lucene42FieldInfosWriter.cs | 3 +- .../Codecs/RAMOnly/RAMOnlyPostingsFormat.cs | 10 +++-- .../Index/BasePostingsFormatTestCase.cs | 33 ++++++++++------- src/Lucene.Net/Codecs/BlockTreeTermsReader.cs | 13 ++++--- .../Codecs/Lucene3x/Lucene3xFields.cs | 9 +++-- .../Lucene40/Lucene40FieldInfosReader.cs | 7 ++-- .../Codecs/Lucene40/Lucene40PostingsReader.cs | 18 +++++---- .../Codecs/Lucene41/Lucene41PostingsReader.cs | 37 +++++++++++-------- .../Codecs/Lucene41/Lucene41PostingsWriter.cs | 9 +++-- .../Lucene46/Lucene46FieldInfosWriter.cs | 4 +- src/Lucene.Net/Index/CheckIndex.cs | 12 ++++-- src/Lucene.Net/Index/FieldInfo.cs | 12 ++++-- src/Lucene.Net/Index/FieldInfos.cs | 5 ++- .../Index/FreqProxTermsWriterPerField.cs | 14 ++++--- .../Support/Index/IndexOptionsComparer.cs | 7 +++- 31 files changed, 195 insertions(+), 124 deletions(-) diff --git a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs index 91da1c4e12..a0edca65aa 100644 --- a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs +++ b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs @@ -277,11 +277,12 @@ public override TermsEnum GetEnumerator() return new SegmentTermsEnum(this); } - public override bool HasFreqs => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + public override bool HasFreqs => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; - public override bool HasOffsets => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + public override bool HasOffsets => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; - public override bool HasPositions => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + public override bool HasPositions => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => fieldInfo.HasPayloads; @@ -786,7 +787,8 @@ public override DocsEnum Docs(IBits liveDocs, DocsEnum reuse, DocsFlags flags) public override DocsAndPositionsEnum DocsAndPositions(IBits liveDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - if (outerInstance.fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(outerInstance.fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { // Positions were not indexed: return null; diff --git a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs index dd00defeae..4f3b825773 100644 --- a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs +++ b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs @@ -388,9 +388,10 @@ public DirectField(SegmentReadState state, string field, Terms termsIn, int minS this.minSkipCount = minSkipCount; - hasFreq = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_ONLY) > 0; - hasPos = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) > 0; - hasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) > 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + hasFreq = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_ONLY) > 0; + hasPos = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) > 0; + hasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) > 0; hasPayloads = fieldInfo.HasPayloads; BytesRef term; diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs index 7dbbe8cdb5..6c4da9fc05 100644 --- a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs +++ b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs @@ -243,11 +243,12 @@ internal TermsReader(FSTOrdTermsReader outerInstance, FieldInfo fieldInfo, Index public override IComparer Comparer => BytesRef.UTF8SortedAsUnicodeComparer; - public override bool HasFreqs => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + public override bool HasFreqs => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; - public override bool HasOffsets => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + public override bool HasOffsets => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; - public override bool HasPositions => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + public override bool HasPositions => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => fieldInfo.HasPayloads; diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs b/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs index c88704ae4d..74dba55d3c 100644 --- a/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs +++ b/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs @@ -215,11 +215,12 @@ internal TermsReader(FSTTermsReader outerInstance, FieldInfo fieldInfo, IndexInp public override IComparer Comparer => BytesRef.UTF8SortedAsUnicodeComparer; - public override bool HasFreqs => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + public override bool HasFreqs => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; - public override bool HasOffsets => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + public override bool HasOffsets => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; - public override bool HasPositions => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + public override bool HasPositions => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => fieldInfo.HasPayloads; diff --git a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs index ac6b87717b..3b0035963a 100644 --- a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs +++ b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs @@ -200,7 +200,8 @@ public override void AddPosition(int pos, BytesRef payload, int startOffset, int buffer.WriteVInt32(delta); } - if (outerInstance.field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(outerInstance.field.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) { // don't use startOffset - lastEndOffset, because this creates lots of negative vints for synonyms, // and the numbers aren't that much smaller anyways. @@ -825,8 +826,8 @@ public override DocsEnum Docs(IBits liveDocs, DocsEnum reuse, DocsFlags flags) public override DocsAndPositionsEnum DocsAndPositions(IBits liveDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - bool hasOffsets = field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; - if (field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + bool hasOffsets = IndexOptionsComparer.Default.Compare(field.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + if (IndexOptionsComparer.Default.Compare(field.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { return null; } @@ -948,11 +949,11 @@ public override TermsEnum GetEnumerator() public override IComparer Comparer => BytesRef.UTF8SortedAsUnicodeComparer; - public override bool HasFreqs => field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + public override bool HasFreqs => IndexOptionsComparer.Default.Compare(field.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; - public override bool HasOffsets => field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + public override bool HasOffsets => IndexOptionsComparer.Default.Compare(field.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; - public override bool HasPositions => field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + public override bool HasPositions => IndexOptionsComparer.Default.Compare(field.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => field.HasPayloads; diff --git a/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs b/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs index d429bd6cc9..cbbdf8adad 100644 --- a/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs +++ b/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs @@ -177,7 +177,8 @@ public override void DecodeTerm(long[] empty, DataInput input, FieldInfo fieldIn termState2.Absolute = termState2.Absolute || absolute; // if we have positions, its total TF, otherwise its computed based on docFreq. // TODO Double check this is right.. - long count = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + long count = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 ? termState2.TotalTermFreq : termState2.DocFreq; @@ -335,7 +336,8 @@ public PulsingDocsEnum(FieldInfo fieldInfo) { _indexOptions = fieldInfo.IndexOptions; _storePayloads = fieldInfo.HasPayloads; - _storeOffsets = _indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + _storeOffsets = IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; } public virtual PulsingDocsEnum Reset(IBits liveDocs, PulsingTermState termState) @@ -385,7 +387,8 @@ public override int NextDoc() _accum += (int)((uint)code >> 1); ; // shift off low bit _freq = (code & 1) != 0 ? 1 : _postings.ReadVInt32(); - if (_indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { // Skip positions if (_storePayloads) @@ -472,7 +475,8 @@ public PulsingDocsAndPositionsEnum(FieldInfo fieldInfo) { _indexOptions = fieldInfo.IndexOptions; _storePayloads = fieldInfo.HasPayloads; - _storeOffsets = _indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + _storeOffsets = IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; } internal bool CanReuse(FieldInfo fieldInfo) diff --git a/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsWriter.cs b/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsWriter.cs index 918fcc8bf8..a5e83d4b07 100644 --- a/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsWriter.cs +++ b/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsWriter.cs @@ -288,7 +288,8 @@ public override void FinishTerm(BlockTermState state) // given codec wants to store other interesting // stuff, it could use this pulsing codec to do so - if (_indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { var lastDocID = 0; var pendingIDX = 0; @@ -341,7 +342,8 @@ public override void FinishTerm(BlockTermState state) _buffer.WriteVInt32(posDelta); } - if (_indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) { //System.out.println("write=" + pos.startOffset + "," + pos.endOffset); var offsetDelta = pos.startOffset - lastOffset; @@ -474,7 +476,8 @@ private void Push() _wrappedPostingsWriter.StartTerm(); // Flush all buffered docs - if (_indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { Position doc = null; diff --git a/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs b/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs index 4a62621868..2e64ffb8ce 100644 --- a/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs +++ b/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs @@ -197,7 +197,8 @@ public override int SetField(FieldInfo fieldInfo) { this.fieldInfo = fieldInfo; this.indexOptions = fieldInfo.IndexOptions; - if (indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) { throw new NotSupportedException("this codec cannot index offsets"); } diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs index 7abfdccf9f..e54e227b46 100644 --- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs +++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs @@ -1,4 +1,5 @@ using Lucene.Net.Diagnostics; +using Lucene.Net.Index; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -92,7 +93,8 @@ public override void Write(Directory directory, string segmentName, string segme if (fi.IsIndexed) { - if (Debugging.AssertsEnabled) Debugging.Assert(fi.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (Debugging.AssertsEnabled) Debugging.Assert(IndexOptionsComparer.Default.Compare(fi.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); SimpleTextUtil.Write(output, INDEXOPTIONS); SimpleTextUtil.Write(output, fi.IndexOptions != IndexOptions.NONE ? fi.IndexOptions.ToString() : string.Empty, diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs index 6bb03ca06d..f78809ad32 100644 --- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs +++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs @@ -4,7 +4,6 @@ using Lucene.Net.Util.Fst; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Text; using JCG = J2N.Collections.Generic; @@ -209,8 +208,8 @@ public override DocsEnum Docs(IBits liveDocs, DocsEnum reuse, DocsFlags flags) public override DocsAndPositionsEnum DocsAndPositions(IBits liveDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - - if (_indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { // Positions were not indexed return null; @@ -387,8 +386,9 @@ public virtual SimpleTextDocsAndPositionsEnum Reset(long fp, IBits liveDocs, Ind _liveDocs = liveDocs; _nextDocStart = fp; _docId = -1; - _readPositions = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - _readOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + _readPositions = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + _readOffsets = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; if (!_readOffsets) { @@ -673,11 +673,12 @@ public override TermsEnum GetEnumerator() public override int DocCount => _docCount; - public override bool HasFreqs => _fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + public override bool HasFreqs => IndexOptionsComparer.Default.Compare(_fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; - public override bool HasOffsets => _fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + public override bool HasOffsets => IndexOptionsComparer.Default.Compare(_fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; - public override bool HasPositions => _fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + public override bool HasPositions => IndexOptionsComparer.Default.Compare(_fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => _fieldInfo.HasPayloads; } diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs index e91d540c18..1af8ea38c9 100644 --- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs +++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs @@ -1,7 +1,7 @@ using Lucene.Net.Diagnostics; +using Lucene.Net.Index; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; namespace Lucene.Net.Codecs.SimpleText @@ -23,11 +23,11 @@ namespace Lucene.Net.Codecs.SimpleText * limitations under the License. */ - using IndexOptions = Index.IndexOptions; + using BytesRef = Util.BytesRef; using FieldInfo = Index.FieldInfo; - using SegmentWriteState = Index.SegmentWriteState; + using IndexOptions = Index.IndexOptions; using IndexOutput = Store.IndexOutput; - using BytesRef = Util.BytesRef; + using SegmentWriteState = Index.SegmentWriteState; internal class SimpleTextFieldsWriter : FieldsConsumer { @@ -117,8 +117,9 @@ public SimpleTextPostingsWriter(SimpleTextFieldsWriter outerInstance, FieldInfo { _outerInstance = outerInstance; _indexOptions = field.IndexOptions; - _writePositions = _indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - _writeOffsets = _indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + _writePositions = IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + _writeOffsets = IndexOptionsComparer.Default.Compare(_indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; } public override void StartDoc(int docId, int termDocFreq) diff --git a/src/Lucene.Net.Misc/Index/Sorter/SortingAtomicReader.cs b/src/Lucene.Net.Misc/Index/Sorter/SortingAtomicReader.cs index ab98827674..8147cc3c6a 100644 --- a/src/Lucene.Net.Misc/Index/Sorter/SortingAtomicReader.cs +++ b/src/Lucene.Net.Misc/Index/Sorter/SortingAtomicReader.cs @@ -158,7 +158,8 @@ public override DocsEnum Docs(IBits liveDocs, DocsEnum reuse, DocsFlags flags) } DocsEnum inDocs = m_input.Docs(NewToOld(liveDocs), inReuse, flags); - bool withFreqs = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0 && (flags & DocsFlags.FREQS) != 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool withFreqs = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS) >= 0 && (flags & DocsFlags.FREQS) != 0; return new SortingDocsEnum(docMap.Count, wrapReuse, inDocs, withFreqs, docMap); } @@ -189,7 +190,8 @@ public override DocsAndPositionsEnum DocsAndPositions(IBits liveDocs, DocsAndPos // since this code is expected to be used during addIndexes which will // ask for everything. if that assumption changes in the future, we can // factor in whether 'flags' says offsets are not required. - bool storeOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool storeOffsets = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; return new SortingDocsAndPositionsEnum(docMap.Count, wrapReuse, inDocsAndPositions, docMap, storeOffsets); } } diff --git a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs index f0e3fc243e..d211c7bbcc 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs @@ -274,7 +274,8 @@ public override void FinishDoc() { if (Debugging.AssertsEnabled) Debugging.Assert(state == PostingsConsumerState.START); state = PostingsConsumerState.INITIAL; - if (fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { if (Debugging.AssertsEnabled) Debugging.Assert(positionCount == 0); // we should not have fed any positions! } diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs index aec17597ef..60d967726d 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs @@ -82,7 +82,8 @@ public PreFlexRWFieldsWriter(SegmentWriteState state) public override TermsConsumer AddField(FieldInfo field) { if (Debugging.AssertsEnabled) Debugging.Assert(field.Number != -1); - if (field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(field.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) { throw new NotSupportedException("this codec cannot index offsets"); } diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40FieldInfosWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40FieldInfosWriter.cs index 3a13facb1e..79cd3ade8c 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40FieldInfosWriter.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40FieldInfosWriter.cs @@ -66,7 +66,8 @@ public override void Write(Directory directory, string segmentName, string segme if (fi.IsIndexed) { bits |= Lucene40FieldInfosFormat.IS_INDEXED; - if (Debugging.AssertsEnabled) Debugging.Assert(indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (Debugging.AssertsEnabled) Debugging.Assert(IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); if (indexOptions == IndexOptions.DOCS_ONLY) { bits |= Lucene40FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS; diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40PostingsWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40PostingsWriter.cs index 4f1853e9a3..75d7d8da23 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40PostingsWriter.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40PostingsWriter.cs @@ -180,7 +180,8 @@ public override int SetField(FieldInfo fieldInfo) this.fieldInfo = fieldInfo; indexOptions = fieldInfo.IndexOptions; - storeOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + storeOffsets = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; storePayloads = fieldInfo.HasPayloads; lastState = emptyState; //System.out.println(" set init blockFreqStart=" + freqStart); @@ -234,7 +235,8 @@ public override void StartDoc(int docID, int termDocFreq) public override void AddPosition(int position, BytesRef payload, int startOffset, int endOffset) { //if (DEBUG) System.out.println("SPW: addPos pos=" + position + " payload=" + (payload == null ? "null" : (payload.Length + " bytes")) + " proxFP=" + proxOut.getFilePointer()); - if (Debugging.AssertsEnabled) Debugging.Assert(indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0,"invalid indexOptions: {0}", indexOptions); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (Debugging.AssertsEnabled) Debugging.Assert(IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0, "invalid indexOptions: {0}", indexOptions); if (Debugging.AssertsEnabled) Debugging.Assert(proxOut != null); int delta = position - lastPosition; @@ -340,7 +342,8 @@ public override void EncodeTerm(long[] empty, DataOutput @out, FieldInfo fieldIn if (Debugging.AssertsEnabled) Debugging.Assert(state_.SkipOffset > 0); @out.WriteVInt64(state_.SkipOffset); } - if (indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { @out.WriteVInt64(state_.ProxStart - lastState.ProxStart); } diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs index f47d6c52bb..439c184992 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs @@ -66,7 +66,8 @@ public override void Write(Directory directory, string segmentName, string segme if (fi.IsIndexed) { bits |= Lucene42FieldInfosFormat.IS_INDEXED; - if (Debugging.AssertsEnabled) Debugging.Assert(indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (Debugging.AssertsEnabled) Debugging.Assert(IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); if (indexOptions == IndexOptions.DOCS_ONLY) { bits |= Lucene42FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS; diff --git a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs index 61e370e441..66fa732a69 100644 --- a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs +++ b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs @@ -171,14 +171,15 @@ public override TermsEnum GetEnumerator() public override IComparer Comparer => reverseUnicodeComparer; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() public override bool HasFreqs - => info.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + => IndexOptionsComparer.Default.Compare(info.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; public override bool HasOffsets - => info.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + => IndexOptionsComparer.Default.Compare(info.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; public override bool HasPositions - => info.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + => IndexOptionsComparer.Default.Compare(info.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => info.HasPayloads; } @@ -250,7 +251,8 @@ public RAMFieldsConsumer(RAMPostings postings) public override TermsConsumer AddField(FieldInfo field) { - if (field.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(field.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) { throw new NotSupportedException("this codec cannot index offsets"); } diff --git a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs index 3dff2dde6e..829ff244b2 100644 --- a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs +++ b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs @@ -162,7 +162,8 @@ public SeedPostings(long seed, int minDocFreq, int maxDocFreq, IBits liveDocs, I var payloadBytes = new byte[payloadSize]; payload = new BytesRef(payloadBytes); this.options = options; - doPositions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS.CompareTo(options) <= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + doPositions = IndexOptionsComparer.Default.Compare(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS, options) <= 0; } public override int NextDoc() @@ -570,7 +571,8 @@ private FieldsProducer BuildIndex(Directory dir, IndexOptions maxAllowed, bool a // Randomly picked the IndexOptions to index this // field with: IndexOptions indexOptions = ALL_INDEX_OPTIONS[alwaysTestMax ? fieldMaxIndexOption : Random.Next(1, 1 + fieldMaxIndexOption)]; // LUCENENET: Skipping NONE option - bool doPayloads = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && allowPayloads; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool doPayloads = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && allowPayloads; newFieldInfoArray[fieldUpto] = new FieldInfo(oldFieldInfo.Name, true, fieldUpto, false, false, doPayloads, indexOptions, DocValuesType.NONE, DocValuesType.NUMERIC, null); } @@ -601,10 +603,11 @@ private FieldsProducer BuildIndex(Directory dir, IndexOptions maxAllowed, bool a Console.WriteLine("field=" + field + " indexOtions=" + indexOptions); } - bool doFreq = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; - bool doPos = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - bool doPayloads = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && allowPayloads; - bool doOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool doFreq = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; + bool doPos = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + bool doPayloads = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && allowPayloads; + bool doOffsets = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; TermsConsumer termsConsumer = fieldsConsumer.AddField(fieldInfo); long sumTotalTF = 0; @@ -748,16 +751,19 @@ private void VerifyEnum(ThreadState threadState, maxIndexOptions); Assert.AreEqual(expected.DocFreq, termsEnum.DocFreq); - bool allowFreqs = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0 && - maxTestOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool allowFreqs = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0 && + IndexOptionsComparer.Default.Compare(maxTestOptions, IndexOptions.DOCS_AND_FREQS) >= 0; bool doCheckFreqs = allowFreqs && (alwaysTestMax || Random.Next(3) <= 2); - bool allowPositions = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && - maxTestOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool allowPositions = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && + IndexOptionsComparer.Default.Compare(maxTestOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; bool doCheckPositions = allowPositions && (alwaysTestMax || Random.Next(3) <= 2); - bool allowOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >=0 && - maxTestOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool allowOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >=0 && + IndexOptionsComparer.Default.Compare(maxTestOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; bool doCheckOffsets = allowOffsets && (alwaysTestMax || Random.Next(3) <= 2); bool doCheckPayloads = options.Contains(Option.PAYLOADS) && allowPositions && fieldInfo.HasPayloads && (alwaysTestMax || Random.Next(3) <= 2); @@ -1085,7 +1091,8 @@ private void VerifyEnum(ThreadState threadState, } } } - else if (fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + else if (IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) < 0) { if (Verbose) { diff --git a/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs b/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs index 59e1209b5b..0f45c18735 100644 --- a/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs +++ b/src/Lucene.Net/Codecs/BlockTreeTermsReader.cs @@ -613,11 +613,12 @@ public Stats ComputeStats() public override IComparer Comparer => BytesRef.UTF8SortedAsUnicodeComparer; - public override bool HasFreqs => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + public override bool HasFreqs => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; - public override bool HasOffsets => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + public override bool HasOffsets => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; - public override bool HasPositions => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + public override bool HasPositions => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => fieldInfo.HasPayloads; @@ -1156,7 +1157,8 @@ public override DocsEnum Docs(IBits skipDocs, DocsEnum reuse, DocsFlags flags) public override DocsAndPositionsEnum DocsAndPositions(IBits skipDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - if (outerInstance.fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(outerInstance.fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { // Positions were not indexed: return null; @@ -2594,7 +2596,8 @@ public override DocsEnum Docs(IBits skipDocs, DocsEnum reuse, DocsFlags flags) public override DocsAndPositionsEnum DocsAndPositions(IBits skipDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - if (outerInstance.fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(outerInstance.fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { // Positions were not indexed: return null; diff --git a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs index a65e195082..a0fa9d4a75 100644 --- a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs +++ b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs @@ -243,19 +243,22 @@ public override IComparer Comparer public override int DocCount => -1; - public override bool HasFreqs => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + public override bool HasFreqs => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; public override bool HasOffsets { get { // preflex doesn't support this - if (Debugging.AssertsEnabled) Debugging.Assert(fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) < 0); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (Debugging.AssertsEnabled) Debugging.Assert(IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) < 0); return false; } } - public override bool HasPositions => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + public override bool HasPositions => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; public override bool HasPayloads => fieldInfo.HasPayloads; } diff --git a/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs b/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs index ac18c98860..301947b004 100644 --- a/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs +++ b/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs @@ -1,6 +1,6 @@ +using Lucene.Net.Index; using System; using System.Collections.Generic; -using System.Globalization; namespace Lucene.Net.Codecs.Lucene40 { @@ -22,8 +22,8 @@ namespace Lucene.Net.Codecs.Lucene40 */ using CorruptIndexException = Lucene.Net.Index.CorruptIndexException; - using DocValuesType = Lucene.Net.Index.DocValuesType; using Directory = Lucene.Net.Store.Directory; + using DocValuesType = Lucene.Net.Index.DocValuesType; using FieldInfo = Lucene.Net.Index.FieldInfo; using FieldInfos = Lucene.Net.Index.FieldInfos; using IndexFileNames = Lucene.Net.Index.IndexFileNames; @@ -94,7 +94,8 @@ public override FieldInfos Read(Directory directory, string segmentName, string // LUCENE-3027: past indices were able to write // storePayloads=true when omitTFAP is also true, // which is invalid. We correct that, here: - if (isIndexed && indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (isIndexed && IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { storePayloads = false; } diff --git a/src/Lucene.Net/Codecs/Lucene40/Lucene40PostingsReader.cs b/src/Lucene.Net/Codecs/Lucene40/Lucene40PostingsReader.cs index 2f32c2ff65..309790fbb4 100644 --- a/src/Lucene.Net/Codecs/Lucene40/Lucene40PostingsReader.cs +++ b/src/Lucene.Net/Codecs/Lucene40/Lucene40PostingsReader.cs @@ -2,7 +2,6 @@ using Lucene.Net.Index; using Lucene.Net.Support; using System; -using System.Diagnostics; namespace Lucene.Net.Codecs.Lucene40 { @@ -23,7 +22,6 @@ namespace Lucene.Net.Codecs.Lucene40 * limitations under the License. */ - using IBits = Lucene.Net.Util.IBits; using BytesRef = Lucene.Net.Util.BytesRef; using DataInput = Lucene.Net.Store.DataInput; using Directory = Lucene.Net.Store.Directory; @@ -31,6 +29,7 @@ namespace Lucene.Net.Codecs.Lucene40 using DocsEnum = Lucene.Net.Index.DocsEnum; using FieldInfo = Lucene.Net.Index.FieldInfo; using FieldInfos = Lucene.Net.Index.FieldInfos; + using IBits = Lucene.Net.Util.IBits; using IndexFileNames = Lucene.Net.Index.IndexFileNames; using IndexInput = Lucene.Net.Store.IndexInput; using IndexOptions = Lucene.Net.Index.IndexOptions; @@ -206,7 +205,8 @@ public override void DecodeTerm(long[] longs, DataInput @in, FieldInfo fieldInfo // undefined } - if (fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { termState2.proxOffset += @in.ReadVInt64(); // if (DEBUG) System.out.println(" proxFP=" + termState2.proxOffset); @@ -254,7 +254,8 @@ private DocsEnum NewDocsEnum(IBits liveDocs, FieldInfo fieldInfo, StandardTermSt public override DocsAndPositionsEnum DocsAndPositions(FieldInfo fieldInfo, BlockTermState termState, IBits liveDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - bool hasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool hasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; // TODO: can we optimize if FLAG_PAYLOADS / FLAG_OFFSETS // isn't passed? @@ -347,7 +348,8 @@ internal virtual DocsEnum Reset(FieldInfo fieldInfo, StandardTermState termState { m_indexOmitsTF = fieldInfo.IndexOptions == IndexOptions.DOCS_ONLY; m_storePayloads = fieldInfo.HasPayloads; - m_storeOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + m_storeOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; m_freqOffset = termState.freqOffset; m_skipOffset = termState.skipOffset; @@ -1004,11 +1006,13 @@ public SegmentFullPositionsEnum(Lucene40PostingsReader outerInstance, IndexInput public virtual SegmentFullPositionsEnum Reset(FieldInfo fieldInfo, StandardTermState termState, IBits liveDocs) { - storeOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + storeOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; storePayloads = fieldInfo.HasPayloads; if (Debugging.AssertsEnabled) { - Debugging.Assert(fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + Debugging.Assert(IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0); Debugging.Assert(storePayloads || storeOffsets); } if (payload == null) diff --git a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs index b8a82435ea..f3b3305ecb 100644 --- a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs +++ b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsReader.cs @@ -4,7 +4,6 @@ using Lucene.Net.Support; using Lucene.Net.Util; using System; -using System.Diagnostics; namespace Lucene.Net.Codecs.Lucene41 { @@ -140,8 +139,9 @@ protected override void Dispose(bool disposing) public override void DecodeTerm(long[] longs, DataInput @in, FieldInfo fieldInfo, BlockTermState termState, bool absolute) { Lucene41PostingsWriter.Int32BlockTermState termState2 = (Lucene41PostingsWriter.Int32BlockTermState)termState; - bool fieldHasPositions = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - bool fieldHasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool fieldHasPositions = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + bool fieldHasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; bool fieldHasPayloads = fieldInfo.HasPayloads; if (absolute) @@ -195,8 +195,9 @@ public override void DecodeTerm(long[] longs, DataInput @in, FieldInfo fieldInfo private void DecodeTerm(DataInput @in, FieldInfo fieldInfo, Lucene41PostingsWriter.Int32BlockTermState termState) { - bool fieldHasPositions = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - bool fieldHasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool fieldHasPositions = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + bool fieldHasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; bool fieldHasPayloads = fieldInfo.HasPayloads; if (termState.DocFreq == 1) { @@ -255,7 +256,8 @@ public override DocsEnum Docs(FieldInfo fieldInfo, BlockTermState termState, IBi public override DocsAndPositionsEnum DocsAndPositions(FieldInfo fieldInfo, BlockTermState termState, IBits liveDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags) { - bool indexHasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool indexHasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; bool indexHasPayloads = fieldInfo.HasPayloads; if ((!indexHasOffsets || (flags & DocsAndPositionsFlags.OFFSETS) == 0) && (!indexHasPayloads || (flags & DocsAndPositionsFlags.PAYLOADS) == 0)) @@ -345,18 +347,20 @@ public BlockDocsEnum(Lucene41PostingsReader outerInstance, FieldInfo fieldInfo) this.outerInstance = outerInstance; this.startDocIn = outerInstance.docIn; this.docIn = null; - indexHasFreq = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; - indexHasPos = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - indexHasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + indexHasFreq = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; + indexHasPos = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + indexHasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; indexHasPayloads = fieldInfo.HasPayloads; encoded = new byte[ForUtil.MAX_ENCODED_SIZE]; } public bool CanReuse(IndexInput docIn, FieldInfo fieldInfo) { + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() return docIn == startDocIn && - indexHasFreq == (fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0) && - indexHasPos == (fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) && + indexHasFreq == (IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0) && + indexHasPos == (IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) && indexHasPayloads == fieldInfo.HasPayloads; } @@ -667,14 +671,15 @@ public BlockDocsAndPositionsEnum(Lucene41PostingsReader outerInstance, FieldInfo this.docIn = null; this.posIn = (IndexInput)outerInstance.posIn.Clone(); encoded = new byte[ForUtil.MAX_ENCODED_SIZE]; - indexHasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + indexHasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; indexHasPayloads = fieldInfo.HasPayloads; } public bool CanReuse(IndexInput docIn, FieldInfo fieldInfo) { return docIn == startDocIn && - indexHasOffsets == (fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) + indexHasOffsets == (IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) && indexHasPayloads == fieldInfo.HasPayloads; } @@ -1143,7 +1148,8 @@ public EverythingEnum(Lucene41PostingsReader outerInstance, FieldInfo fieldInfo) this.posIn = (IndexInput)outerInstance.posIn.Clone(); this.payIn = (IndexInput)outerInstance.payIn.Clone(); encoded = new byte[ForUtil.MAX_ENCODED_SIZE]; - indexHasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + indexHasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; if (indexHasOffsets) { offsetStartDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE]; @@ -1174,8 +1180,9 @@ public EverythingEnum(Lucene41PostingsReader outerInstance, FieldInfo fieldInfo) public bool CanReuse(IndexInput docIn, FieldInfo fieldInfo) { + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() return docIn == startDocIn && - indexHasOffsets == (fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) && + indexHasOffsets == (IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0) && indexHasPayloads == fieldInfo.HasPayloads; } diff --git a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsWriter.cs b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsWriter.cs index 1627b9736b..f47cb45177 100644 --- a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsWriter.cs +++ b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsWriter.cs @@ -1,6 +1,6 @@ using Lucene.Net.Diagnostics; +using Lucene.Net.Index; using System; -using System.Diagnostics; namespace Lucene.Net.Codecs.Lucene41 { @@ -249,9 +249,10 @@ public override void Init(IndexOutput termsOut) public override int SetField(FieldInfo fieldInfo) { IndexOptions indexOptions = fieldInfo.IndexOptions; - fieldHasFreqs = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; - fieldHasPositions = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - fieldHasOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + fieldHasFreqs = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; + fieldHasPositions = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + fieldHasOffsets = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; fieldHasPayloads = fieldInfo.HasPayloads; skipWriter.SetField(fieldHasPositions, fieldHasOffsets, fieldHasPayloads); lastState = emptyState; diff --git a/src/Lucene.Net/Codecs/Lucene46/Lucene46FieldInfosWriter.cs b/src/Lucene.Net/Codecs/Lucene46/Lucene46FieldInfosWriter.cs index 3449d17d01..c3e61de0e7 100644 --- a/src/Lucene.Net/Codecs/Lucene46/Lucene46FieldInfosWriter.cs +++ b/src/Lucene.Net/Codecs/Lucene46/Lucene46FieldInfosWriter.cs @@ -1,4 +1,5 @@ using Lucene.Net.Diagnostics; +using Lucene.Net.Index; using System; using System.Diagnostics; @@ -73,7 +74,8 @@ public override void Write(Directory directory, string segmentName, string segme if (fi.IsIndexed) { bits |= Lucene46FieldInfosFormat.IS_INDEXED; - if (Debugging.AssertsEnabled) Debugging.Assert(indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (Debugging.AssertsEnabled) Debugging.Assert(IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads); if (indexOptions == IndexOptions.DOCS_ONLY) { bits |= Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS; diff --git a/src/Lucene.Net/Index/CheckIndex.cs b/src/Lucene.Net/Index/CheckIndex.cs index 77635e21ce..87da6d812f 100644 --- a/src/Lucene.Net/Index/CheckIndex.cs +++ b/src/Lucene.Net/Index/CheckIndex.cs @@ -1046,7 +1046,8 @@ private static Status.TermIndexStatus CheckFields(Fields fields, IBits liveDocs, bool hasOffsets = terms.HasOffsets; // term vectors cannot omit TF: - bool expectedHasFreqs = (isVectors || fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool expectedHasFreqs = (isVectors || IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0); if (hasFreqs != expectedHasFreqs) { @@ -1063,7 +1064,8 @@ private static Status.TermIndexStatus CheckFields(Fields fields, IBits liveDocs, if (!isVectors) { - bool expectedHasPositions = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool expectedHasPositions = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; if (hasPositions != expectedHasPositions) { throw new Exception("field \"" + field + "\" should have hasPositions=" + expectedHasPositions + " but got " + hasPositions); @@ -1075,7 +1077,8 @@ private static Status.TermIndexStatus CheckFields(Fields fields, IBits liveDocs, throw new Exception("field \"" + field + "\" should have hasPayloads=" + expectedHasPayloads + " but got " + hasPayloads); } - bool expectedHasOffsets = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool expectedHasOffsets = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; if (hasOffsets != expectedHasOffsets) { throw new Exception("field \"" + field + "\" should have hasOffsets=" + expectedHasOffsets + " but got " + hasOffsets); @@ -2135,7 +2138,8 @@ public static Status.TermVectorStatus TestTermVectors(AtomicReader reader, TextW { Terms terms = tfv.GetTerms(field); termsEnum = terms.GetEnumerator(termsEnum); - bool postingsHasFreq = fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool postingsHasFreq = IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; bool postingsHasPayload = fieldInfo.HasPayloads; bool vectorsHasPayload = terms.HasPayloads; diff --git a/src/Lucene.Net/Index/FieldInfo.cs b/src/Lucene.Net/Index/FieldInfo.cs index b5ce647d02..5830693d9d 100644 --- a/src/Lucene.Net/Index/FieldInfo.cs +++ b/src/Lucene.Net/Index/FieldInfo.cs @@ -111,7 +111,8 @@ private bool CheckConsistency() if (Debugging.AssertsEnabled) Debugging.Assert(normType == DocValuesType.NONE); } // Cannot store payloads unless positions are indexed: - if (Debugging.AssertsEnabled) Debugging.Assert(indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !this.storePayloads); + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (Debugging.AssertsEnabled) Debugging.Assert(IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !this.storePayloads); } return true; @@ -154,9 +155,11 @@ internal void Update(bool indexed, bool storeTermVector, bool omitNorms, bool st else { // downgrade - this.indexOptions = this.indexOptions.CompareTo(indexOptions) < 0 ? this.indexOptions : indexOptions; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + this.indexOptions = IndexOptionsComparer.Default.Compare(this.indexOptions, indexOptions) < 0 ? this.indexOptions : indexOptions; } - if (this.indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (IndexOptionsComparer.Default.Compare(this.indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { // cannot store payloads if we don't store positions: this.storePayloads = false; @@ -222,7 +225,8 @@ internal void SetStoreTermVectors() internal void SetStorePayloads() { - if (indexed && indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + if (indexed && IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { storePayloads = true; } diff --git a/src/Lucene.Net/Index/FieldInfos.cs b/src/Lucene.Net/Index/FieldInfos.cs index b418d8eb86..c3ec781902 100644 --- a/src/Lucene.Net/Index/FieldInfos.cs +++ b/src/Lucene.Net/Index/FieldInfos.cs @@ -81,9 +81,10 @@ public FieldInfos(FieldInfo[] infos) byName[info.Name] = info; hasVectors |= info.HasVectors; - hasProx |= info.IsIndexed && info.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + hasProx |= info.IsIndexed && IndexOptionsComparer.Default.Compare(info.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; hasFreq |= info.IsIndexed && info.IndexOptions != IndexOptions.DOCS_ONLY; - hasOffsets |= info.IsIndexed && info.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + hasOffsets |= info.IsIndexed && IndexOptionsComparer.Default.Compare(info.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; hasNorms |= info.HasNorms; hasDocValues |= info.HasDocValues; hasPayloads |= info.HasPayloads; diff --git a/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs b/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs index 5eaea1abd6..5ed775ccc2 100644 --- a/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs +++ b/src/Lucene.Net/Index/FreqProxTermsWriterPerField.cs @@ -112,9 +112,10 @@ private void SetIndexOptions(IndexOptions indexOptions) } else { - hasFreq = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; - hasProx = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - hasOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + hasFreq = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; + hasProx = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + hasOffsets = IndexOptionsComparer.Default.Compare(indexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; } } @@ -418,9 +419,10 @@ internal void Flush(string fieldName, FieldsConsumer consumer, SegmentWriteState IndexOptions currentFieldIndexOptions = fieldInfo.IndexOptions; if (Debugging.AssertsEnabled) Debugging.Assert(currentFieldIndexOptions != IndexOptions.NONE); - bool writeTermFreq = currentFieldIndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; - bool writePositions = currentFieldIndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; - bool writeOffsets = currentFieldIndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; + // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare() + bool writeTermFreq = IndexOptionsComparer.Default.Compare(currentFieldIndexOptions, IndexOptions.DOCS_AND_FREQS) >= 0; + bool writePositions = IndexOptionsComparer.Default.Compare(currentFieldIndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; + bool writeOffsets = IndexOptionsComparer.Default.Compare(currentFieldIndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; bool readTermFreq = this.hasFreq; bool readPositions = this.hasProx; diff --git a/src/Lucene.Net/Support/Index/IndexOptionsComparer.cs b/src/Lucene.Net/Support/Index/IndexOptionsComparer.cs index de49ff377e..4f97e6cc8a 100644 --- a/src/Lucene.Net/Support/Index/IndexOptionsComparer.cs +++ b/src/Lucene.Net/Support/Index/IndexOptionsComparer.cs @@ -21,10 +21,13 @@ namespace Lucene.Net.Index */ /// + /// Represents an comparison operation that uses comparison rules. + /// /// Since in .NET the standard comparers will do boxing when comparing enum types, - /// this class was created as a more performant workaround than calling CompareTo() on . + /// this class was created as a more performant alternative than calling CompareTo() on . /// - internal class IndexOptionsComparer : IComparer + // See: GH-376 + public sealed class IndexOptionsComparer : IComparer { private IndexOptionsComparer() { } // No instance