diff --git a/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/HTMLStripCharFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/HTMLStripCharFilter.cs index c1955b7045..8f41ca19b0 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/HTMLStripCharFilter.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/CharFilter/HTMLStripCharFilter.cs @@ -224,12 +224,12 @@ public sealed class HTMLStripCharFilter : BaseCharFilter "\x000A\x00BC\x0007\x0000\x001A\x0001\x0004\x0000\x0001\x0002\x0001\x0000\x001A\x0001\x000B\x0000\x0059\x0001\x0003\x0000" + "\x0006\x0001\x0002\x0000\x0006\x0001\x0002\x0000\x0006\x0001\x0002\x0000\x0003\x0001\x0023\x0000"; - /** + /** * Translates characters to character classes */ private static readonly char[] ZZ_CMAP = ZzUnpackCMap(ZZ_CMAP_PACKED); - /** + /** * Translates DFA states to action switch labels. */ private static readonly int[] ZZ_ACTION = ZzUnpackAction(); @@ -348,7 +348,7 @@ private static int ZzUnpackAction(string packed, int offset, int[] result) } - /** + /** * Translates a state to a row index in the transition table */ private static readonly int[] ZZ_ROWMAP = ZzUnpackRowMap(); @@ -30693,7 +30693,7 @@ private static readonly IDictionary upperCaseVariantsAccepted private static CharArrayDictionary LoadEntityValues() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { - CharArrayDictionary entityValues + CharArrayDictionary result #pragma warning disable 612, 618 = new CharArrayDictionary(LuceneVersion.LUCENE_CURRENT, 253, false); #pragma warning restore 612, 618 @@ -30775,13 +30775,13 @@ CharArrayDictionary entityValues for (int i = 0; i < entities.Length; i += 2) { var value = entities[i + 1][0]; - entityValues[entities[i]] = value; + result[entities[i]] = value; if (upperCaseVariantsAccepted.TryGetValue(entities[i], out string upperCaseVariant) && upperCaseVariant != null) { - entityValues[upperCaseVariant] = value; + result[upperCaseVariant] = value; } } - return entityValues; + return result; } private static readonly int INITIAL_INPUT_SEGMENT_SIZE = 1024; private static readonly char BLOCK_LEVEL_START_TAG_REPLACEMENT = '\n'; @@ -31024,7 +31024,7 @@ private bool ZzRefill() zzEndRead += numRead; return false; } - // unlikely but not impossible: read 0 characters, but not at end of stream + // unlikely but not impossible: read 0 characters, but not at end of stream if (numRead == 0) { int c = zzReader.Read(); @@ -31104,7 +31104,7 @@ private void YyBegin(int newState) //private string YyText => new string(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead); /// - /// Returns the character at position pos from the + /// Returns the character at position pos from the /// matched text. It is equivalent to YyText[pos], but faster /// /// the position of the character to fetch. A value from 0 to YyLength()-1. @@ -31124,7 +31124,7 @@ private char YyCharAt(int pos) /// Reports an error that occured while scanning. /// /// In a wellformed scanner (no or only correct usage of - /// YyPushBack(int) and a match-all fallback rule) this method + /// YyPushBack(int) and a match-all fallback rule) this method /// will only be called with things that "Can't Possibly Happen". /// If this method is called, something is seriously wrong /// (e.g. a JFlex bug producing a faulty scanner etc.). @@ -31151,7 +31151,7 @@ private static void ZzScanError(int errorCode) // LUCENENET: CA1822: Mark member /// /// Pushes the specified amount of characters back into the input stream. - /// + /// /// They will be read again by then next call of the scanning method /// /// the number of characters to be read again. @@ -32094,4 +32094,4 @@ private int NextChar() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs index 396bd7cab7..35172b8ba9 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Nl/DutchAnalyzer.cs @@ -29,7 +29,7 @@ namespace Lucene.Net.Analysis.Nl */ /// - /// for Dutch language. + /// for Dutch language. /// /// Supports an external list of stopwords (words that /// will not be indexed at all), an external list of exclusions (word that will @@ -38,20 +38,20 @@ namespace Lucene.Net.Analysis.Nl /// A default set of stopwords is used unless an alternative list is specified, but the /// exclusion list is empty by default. /// - /// + /// /// You must specify the required /// compatibility when creating : /// /// As of 3.6, and /// also populate /// the default entries for the stem override dictionary - /// As of 3.1, Snowball stemming is done with SnowballFilter, - /// LowerCaseFilter is used prior to StopFilter, and Snowball + /// As of 3.1, Snowball stemming is done with SnowballFilter, + /// LowerCaseFilter is used prior to StopFilter, and Snowball /// stopwords are used by default. /// As of 2.9, StopFilter preserves position /// increments /// - /// + /// /// /// NOTE: This class uses the same /// dependent settings as . @@ -93,13 +93,13 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons private static CharArrayDictionary LoadDefaultStemDict() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { #pragma warning disable 612, 618 - var DEFAULT_STEM_DICT = new CharArrayDictionary(LuceneVersion.LUCENE_CURRENT, 4, false); + var result = new CharArrayDictionary(LuceneVersion.LUCENE_CURRENT, 4, false); #pragma warning restore 612, 618 - DEFAULT_STEM_DICT["fiets"] = "fiets"; //otherwise fiet - DEFAULT_STEM_DICT["bromfiets"] = "bromfiets"; //otherwise bromfiet - DEFAULT_STEM_DICT["ei"] = "eier"; - DEFAULT_STEM_DICT["kind"] = "kinder"; - return DEFAULT_STEM_DICT; + result["fiets"] = "fiets"; //otherwise fiet + result["bromfiets"] = "bromfiets"; //otherwise bromfiet + result["ei"] = "eier"; + result["kind"] = "kinder"; + return result; } } @@ -121,7 +121,7 @@ private static CharArrayDictionary LoadDefaultStemDict() // LUCENENET: A private readonly LuceneVersion matchVersion; /// - /// Builds an analyzer with the default stop words () + /// Builds an analyzer with the default stop words () /// and a few default entries for the stem exclusion table. /// public DutchAnalyzer(LuceneVersion matchVersion) @@ -191,11 +191,11 @@ public DutchAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords, CharArr } /// - /// Returns a (possibly reused) which tokenizes all the + /// Returns a (possibly reused) which tokenizes all the /// text in the provided . /// /// A built from a - /// filtered with , , + /// filtered with , , /// , if a stem exclusion set is provided, /// , and protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader aReader) @@ -235,4 +235,4 @@ protected internal override TokenStreamComponents CreateComponents(string fieldN } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/ScriptIterator.cs b/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/ScriptIterator.cs index bf80745898..a4849266c7 100644 --- a/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/ScriptIterator.cs +++ b/src/Lucene.Net.Analysis.ICU/Analysis/Icu/Segmentation/ScriptIterator.cs @@ -24,10 +24,10 @@ namespace Lucene.Net.Analysis.Icu.Segmentation */ /// - /// An iterator that locates ISO 15924 script boundaries in text. + /// An iterator that locates ISO 15924 script boundaries in text. /// /// - /// This is not the same as simply looking at the Unicode block, or even the + /// This is not the same as simply looking at the Unicode block, or even the /// Script property. Some characters are 'common' across multiple scripts, and /// some 'inherit' the script value of text surrounding them. /// @@ -36,10 +36,10 @@ namespace Lucene.Net.Analysis.Icu.Segmentation /// /// /// Doesn't attempt to match paired punctuation. For tokenization purposes, this - /// is not necessary. Its also quite expensive. + /// is not necessary. Its also quite expensive. /// /// - /// Non-spacing marks inherit the script of their base character, following + /// Non-spacing marks inherit the script of their base character, following /// recommendations from UTR #24. /// /// @@ -157,10 +157,10 @@ public void SetText(char[] text, int start, int length) private static int[] LoadBasicLatin() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { - var basicLatin = new int[128]; - for (int i = 0; i < basicLatin.Length; i++) - basicLatin[i] = UScript.GetScript(i); - return basicLatin; + var result = new int[128]; + for (int i = 0; i < result.Length; i++) + result[i] = UScript.GetScript(i); + return result; } /// Fast version of . Basic Latin is an array lookup. diff --git a/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs b/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs index 651b726d96..cca9fbe9c6 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/JapaneseAnalyzer.cs @@ -62,7 +62,7 @@ public JapaneseAnalyzer(LuceneVersion matchVersion, UserDictionary userDict, Jap public static ISet DefaultStopTags => DefaultSetHolder.DEFAULT_STOP_TAGS; /// - /// Atomically loads DEFAULT_STOP_SET, DEFAULT_STOP_TAGS in a lazy fashion once the + /// Atomically loads DEFAULT_STOP_SET, DEFAULT_STOP_TAGS in a lazy fashion once the /// outer class accesses the static final set the first time. /// private static class DefaultSetHolder @@ -88,12 +88,12 @@ private static ISet LoadDefaultStopTagSet() // LUCENENET: Avoid static c try { CharArraySet tagset = LoadStopwordSet(false, typeof(JapaneseAnalyzer), "stoptags.txt", "#"); - var DEFAULT_STOP_TAGS = new JCG.HashSet(); + var result = new JCG.HashSet(); foreach (string element in tagset) { - DEFAULT_STOP_TAGS.Add(element); + result.Add(element); } - return DEFAULT_STOP_TAGS.AsReadOnly(); // LUCENENET: Made readonly as stated in the docs: https://github.com/apache/lucene/issues/11866 + return result.AsReadOnly(); // LUCENENET: Made readonly as stated in the docs: https://github.com/apache/lucene/issues/11866 } catch (Exception ex) when (ex.IsIOException()) { diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs index 863213baef..ec6363a669 100644 --- a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs +++ b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs @@ -116,12 +116,12 @@ public bool Matches(string txt) private static IDictionary LoadLangs() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { - IDictionary langs = new Dictionary(); + IDictionary result = new Dictionary(); foreach (NameType s in Enum.GetValues(typeof(NameType))) { - langs[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s)); + result[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s)); } - return langs; + return result; } /// diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Languages.cs b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Languages.cs index 89de55067d..0631200ae3 100644 --- a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Languages.cs +++ b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Languages.cs @@ -72,12 +72,12 @@ public class Languages private static IDictionary LoadLanguages() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { - IDictionary LANGUAGES = new Dictionary(); + IDictionary result = new Dictionary(); foreach (NameType s in Enum.GetValues(typeof(NameType))) { - LANGUAGES[s] = GetInstance(LangResourceName(s)); + result[s] = GetInstance(LangResourceName(s)); } - return LANGUAGES; + return result; } public static Languages GetInstance(NameType nameType) @@ -130,7 +130,7 @@ public static Languages GetInstance(string languagesResourceName) private static string LangResourceName(NameType nameType) { - return string.Format("{0}_languages.txt", nameType.GetName()); + return string.Format("{0}_languages.txt", nameType.GetName()); } private readonly ISet languages; diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecDocParser.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecDocParser.cs index 03e991a04a..1b1015f28e 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecDocParser.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/TrecDocParser.cs @@ -26,7 +26,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds /// /// Parser for trec doc content, invoked on doc text excluding <DOC> and <DOCNO> - /// which are handled in TrecContentSource. Required to be stateless and hence thread safe. + /// which are handled in TrecContentSource. Required to be stateless and hence thread safe. /// public abstract class TrecDocParser { @@ -48,12 +48,12 @@ public enum ParsePathType { GOV2, FBIS, FT, FR94, LATIMES, UNKNOWN } internal static readonly IDictionary pathName2Type = LoadPathName2Type(); private static IDictionary LoadPathName2Type() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { - var pathName2Type = new Dictionary(); + var result = new Dictionary(); foreach (ParsePathType ppt in Enum.GetValues(typeof(ParsePathType))) { - pathName2Type[ppt.ToString().ToUpperInvariant()] = ppt; + result[ppt.ToString().ToUpperInvariant()] = ppt; } - return pathName2Type; + return result; } @@ -84,14 +84,14 @@ public static ParsePathType PathType(FileInfo f) } /// - /// Parse the text prepared in docBuf into a result DocData, + /// Parse the text prepared in docBuf into a result DocData, /// no synchronization is required. /// /// Reusable result. /// Name that should be set to the result. /// Calling trec content source. /// Text to parse. - /// Type of parsed file, or if unknown - may be used by + /// Type of parsed file, or if unknown - may be used by /// parsers to alter their behavior according to the file path type. /// public abstract DocData Parse(DocData docData, string name, TrecContentSource trecSrc, diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/ElementType.cs b/src/Lucene.Net.Benchmark/Support/TagSoup/ElementType.cs index 2a14fd5d2f..55510c4924 100644 --- a/src/Lucene.Net.Benchmark/Support/TagSoup/ElementType.cs +++ b/src/Lucene.Net.Benchmark/Support/TagSoup/ElementType.cs @@ -39,7 +39,7 @@ public class ElementType /// The content model, member-of, and flags vectors are specified as ints. /// /// The element type name - /// ORed-together bits representing the content + /// ORed-together bits representing the content /// models allowed in the content of this element type /// ORed-together bits representing the content models /// to which this element type belongs @@ -198,7 +198,7 @@ public virtual void SetAttribute(Attributes atts, string name, string type, stri } string ns = GetNamespace(name, true); - string localName = GetLocalName(name); + string ln = GetLocalName(name); // LUCENENET specific - renamed from localName to not shadow field int i = atts.GetIndex(name); if (i == -1) { @@ -211,7 +211,7 @@ public virtual void SetAttribute(Attributes atts, string name, string type, stri { value = Normalize(value); } - atts.AddAttribute(ns, localName, name, type, value); + atts.AddAttribute(ns, ln, name, type, value); } else { @@ -223,7 +223,7 @@ public virtual void SetAttribute(Attributes atts, string name, string type, stri { value = Normalize(value); } - atts.SetAttribute(i, ns, localName, name, type, value); + atts.SetAttribute(i, ns, ln, name, type, value); } } diff --git a/src/Lucene.Net.Misc/Document/LazyDocument.cs b/src/Lucene.Net.Misc/Document/LazyDocument.cs index a64335fff2..5537216c84 100644 --- a/src/Lucene.Net.Misc/Document/LazyDocument.cs +++ b/src/Lucene.Net.Misc/Document/LazyDocument.cs @@ -51,17 +51,17 @@ public LazyDocument(IndexReader reader, int docID) } /// - /// Creates an IndexableField whose value will be lazy loaded if and - /// when it is used. + /// Creates an IndexableField whose value will be lazy loaded if and + /// when it is used. /// - /// NOTE: This method must be called once for each value of the field - /// name specified in sequence that the values exist. This method may not be - /// used to generate multiple, lazy, IndexableField instances refering to + /// NOTE: This method must be called once for each value of the field + /// name specified in sequence that the values exist. This method may not be + /// used to generate multiple, lazy, IndexableField instances refering to /// the same underlying IndexableField instance. /// /// - /// The lazy loading of field values from all instances of IndexableField - /// objects returned by this method are all backed by a single Document + /// The lazy loading of field values from all instances of IndexableField + /// objects returned by this method are all backed by a single Document /// per LazyDocument instance. /// /// @@ -95,7 +95,7 @@ public virtual IIndexableField GetField(FieldInfo fieldInfo) /// /// non-private for test only access - /// @lucene.internal + /// @lucene.internal /// internal virtual Document GetDocument() { @@ -144,7 +144,7 @@ private void FetchRealValues(string name, int fieldNum) /// - /// @lucene.internal + /// @lucene.internal /// public class LazyField : IIndexableField, IFormattable { @@ -163,7 +163,7 @@ internal LazyField(LazyDocument outerInstance, string name, int fieldNum) /// /// non-private for test only access - /// @lucene.internal + /// @lucene.internal /// public virtual bool HasBeenLoaded => null != realValue; @@ -218,7 +218,7 @@ public virtual string GetStringValue() /// An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric. /// The string representation of the value if it is either a or numeric type. // LUCENENET specific - created overload so we can format an underlying numeric type using specified provider - public virtual string GetStringValue(IFormatProvider provider) + public virtual string GetStringValue(IFormatProvider provider) { return GetRealValue().GetStringValue(provider); } @@ -231,7 +231,7 @@ public virtual string GetStringValue(IFormatProvider provider) /// A standard or custom numeric format string. This parameter has no effect if this field is non-numeric. /// The string representation of the value if it is either a or numeric type. // LUCENENET specific - created overload so we can format an underlying numeric type using specified format - public virtual string GetStringValue(string format) + public virtual string GetStringValue(string format) { return GetRealValue().GetStringValue(format); } @@ -245,7 +245,7 @@ public virtual string GetStringValue(string format) /// An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric. /// The string representation of the value if it is either a or numeric type. // LUCENENET specific - created overload so we can format an underlying numeric type using specified format and provider - public virtual string GetStringValue(string format, IFormatProvider provider) + public virtual string GetStringValue(string format, IFormatProvider provider) { return GetRealValue().GetStringValue(format, provider); } @@ -269,15 +269,15 @@ public virtual object GetNumericValue() /// /// Gets the of the underlying value, or if the value is not set or non-numeric. /// - /// Expert: The difference between this property and is + /// Expert: The difference between this property and is /// this is represents the current state of the field (whether being written or read) and the /// property represents instructions on how the field will be written, /// but does not re-populate when reading back from an index (it is write-only). /// - /// In Java, the numeric type was determined by checking the type of + /// In Java, the numeric type was determined by checking the type of /// . However, since there are no reference number /// types in .NET, using so will cause boxing/unboxing. It is - /// therefore recommended to use this property to check the underlying type and the corresponding + /// therefore recommended to use this property to check the underlying type and the corresponding /// Get*Value() method to retrieve the value. /// /// NOTE: Since Lucene codecs do not support or , @@ -387,16 +387,16 @@ public virtual string ToString(IFormatProvider provider) // LUCENENET specific - method added for better .NET compatibility public virtual string ToString(string format,IFormatProvider provider) { - IIndexableField realValue = GetRealValue(); - if(realValue is IFormattable formattable) + IIndexableField rv = GetRealValue(); + if (rv is IFormattable formattable) { return formattable.ToString(format, provider); } else { - return realValue.ToString(); + return rv.ToString(); } } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs b/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs index d2d784c3c2..8c42c3891f 100644 --- a/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs +++ b/src/Lucene.Net.QueryParser/ComplexPhrase/ComplexPhraseQueryParser.cs @@ -120,9 +120,9 @@ public override Query Parse(string query) isPass2ResolvingPhrases = true; try { - foreach (var currentPhraseQuery in complexPhrases) + foreach (var enumeratorValue in complexPhrases) { - this.currentPhraseQuery = currentPhraseQuery; + currentPhraseQuery = enumeratorValue; // in each phrase, now parse the contents between quotes as a // separate parse operation currentPhraseQuery.ParsePhraseElements(this); diff --git a/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesConsumer.cs b/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesConsumer.cs index 24350ed5af..d4a68a4e67 100644 --- a/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesConsumer.cs +++ b/src/Lucene.Net/Codecs/Lucene45/Lucene45DocValuesConsumer.cs @@ -126,7 +126,7 @@ internal virtual void AddNumericField(FieldInfo field, IEnumerable values bool missing = false; // TODO: more efficient? JCG.HashSet uniqueValues = null; - + if (optimizeStorage) { uniqueValues = new JCG.HashSet(); @@ -487,8 +487,6 @@ public override void AddSortedSetField(FieldInfo field, IEnumerable va IEnumerator docToOrdCountIter = docToOrdCount.GetEnumerator(); IEnumerator ordsIter = ords.GetEnumerator(); - const long MISSING_ORD = -1; - while (docToOrdCountIter.MoveNext()) { long current = docToOrdCountIter.Current.Value; @@ -540,4 +538,4 @@ protected override void Dispose(bool disposing) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/FieldInfos.cs b/src/Lucene.Net/Index/FieldInfos.cs index a52f26977f..c6a63ba5df 100644 --- a/src/Lucene.Net/Index/FieldInfos.cs +++ b/src/Lucene.Net/Index/FieldInfos.cs @@ -263,13 +263,14 @@ internal bool ContainsConsistent(int number, string name, DocValuesType dvType) UninterruptableMonitor.Enter(this); try { - numberToName.TryGetValue(number, out string numberToNameStr); - nameToNumber.TryGetValue(name, out int nameToNumberVal); - this.docValuesType.TryGetValue(name, out DocValuesType docValuesType); - - return name.Equals(numberToNameStr, StringComparison.Ordinal) - && number.Equals(nameToNumber[name]) && - (dvType == DocValuesType.NONE || docValuesType == DocValuesType.NONE || dvType == docValuesType); + // LUCENENET specific - using TryGetValue to avoid throwing an exception + numberToName.TryGetValue(number, out string numberToNameValue); + nameToNumber.TryGetValue(name, out int nameToNumberValue); + docValuesType.TryGetValue(name, out DocValuesType docValuesTypeValue); + + return name.Equals(numberToNameValue, StringComparison.Ordinal) + && number.Equals(nameToNumberValue) && + (dvType == DocValuesType.NONE || docValuesTypeValue == DocValuesType.NONE || dvType == docValuesTypeValue); } finally { @@ -439,4 +440,4 @@ public FieldInfos Finish() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/SortedSetDocValuesWriter.cs b/src/Lucene.Net/Index/SortedSetDocValuesWriter.cs index 3cabc9a2c4..34eb99b4fb 100644 --- a/src/Lucene.Net/Index/SortedSetDocValuesWriter.cs +++ b/src/Lucene.Net/Index/SortedSetDocValuesWriter.cs @@ -1,6 +1,7 @@ using Lucene.Net.Diagnostics; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace Lucene.Net.Index @@ -175,13 +176,15 @@ public override void Flush(SegmentWriteState state, DocValuesConsumer dvConsumer ordMap[sortedValues[ord]] = ord; } - dvConsumer.AddSortedSetField(fieldInfo, GetBytesRefEnumberable(valueCount, sortedValues), + dvConsumer.AddSortedSetField(fieldInfo, + // ord -> value + GetValuesEnumerable(valueCount, sortedValues), - // doc -> ordCount - GetOrdsEnumberable(maxDoc), + // doc -> ordCount + GetOrdCountEnumerable(maxDoc), - // ords - GetOrdCountEnumberable(maxCountPerDoc, ordMap)); + // ords + GetOrdsEnumerable(ordMap, maxCountPerDoc)); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -189,7 +192,7 @@ public override void Abort() { } - private IEnumerable GetBytesRefEnumberable(int valueCount, int[] sortedValues) + private IEnumerable GetValuesEnumerable(int valueCount, int[] sortedValues) { var scratch = new BytesRef(); @@ -199,26 +202,28 @@ private IEnumerable GetBytesRefEnumberable(int valueCount, int[] sorte } } - private IEnumerable GetOrdsEnumberable(int maxDoc) + [SuppressMessage("ReSharper", "AccessToStaticMemberViaDerivedType", Justification = "Matches Lucene")] + private IEnumerable GetOrdCountEnumerable(int maxDoc) { AppendingDeltaPackedInt64Buffer.Iterator iter = pendingCounts.GetIterator(); - if (Debugging.AssertsEnabled) Debugging.Assert(pendingCounts.Count == maxDoc,"MaxDoc: {0}, pending.Count: {1}", maxDoc, pending.Count); + if (Debugging.AssertsEnabled) Debugging.Assert(pendingCounts.Count == maxDoc, "MaxDoc: {0}, pending.Count: {1}", maxDoc, pending.Count); - for (int i = 0; i < maxDoc; ++i) + for (int docUpto = 0; docUpto < maxDoc; ++docUpto) { yield return iter.Next(); } } - private IEnumerable GetOrdCountEnumberable(int maxCountPerDoc, int[] ordMap) + [SuppressMessage("ReSharper", "AccessToStaticMemberViaDerivedType", Justification = "Matches Lucene")] + private IEnumerable GetOrdsEnumerable(int[] ordMap, int maxCountPerDoc) { int currentUpTo = 0, currentLength = 0; AppendingPackedInt64Buffer.Iterator iter = pending.GetIterator(); AppendingDeltaPackedInt64Buffer.Iterator counts = pendingCounts.GetIterator(); - int[] currentDoc = new int[maxCountPerDoc]; + int[] cd = new int[maxCountPerDoc]; // LUCENENET specific - renamed from currentDoc to cd to prevent conflict - for (long i = 0; i < pending.Count; ++i) + for (long ordUpto = 0; ordUpto < pending.Count; ++ordUpto) { while (currentUpTo == currentLength) { @@ -227,14 +232,14 @@ private IEnumerable GetBytesRefEnumberable(int valueCount, int[] sorte currentLength = (int)counts.Next(); for (int j = 0; j < currentLength; j++) { - currentDoc[j] = ordMap[(int)iter.Next()]; + cd[j] = ordMap[(int)iter.Next()]; } - Array.Sort(currentDoc, 0, currentLength); + Array.Sort(cd, 0, currentLength); } - int ord = currentDoc[currentUpTo]; + int ord = cd[currentUpTo]; currentUpTo++; yield return ord; } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Support/CRC32.cs b/src/Lucene.Net/Support/CRC32.cs index 3681576494..571e52f01a 100644 --- a/src/Lucene.Net/Support/CRC32.cs +++ b/src/Lucene.Net/Support/CRC32.cs @@ -19,17 +19,16 @@ * */ -using System; - namespace Lucene.Net.Support { internal class CRC32 : IChecksum { - private static readonly uint[] crcTable = InitializeCRCTable(); + private static readonly uint[] crcTable = LoadCRCTable(); - private static uint[] InitializeCRCTable() + // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) + private static uint[] LoadCRCTable() { - uint[] crcTable = new uint[256]; + uint[] result = new uint[256]; for (uint n = 0; n < 256; n++) { uint c = n; @@ -40,9 +39,9 @@ private static uint[] InitializeCRCTable() else c = c >> 1; } - crcTable[n] = c; + result[n] = c; } - return crcTable; + return result; } private uint crc = 0; @@ -74,4 +73,4 @@ public void Update(byte[] buf) Update(buf, 0, buf.Length); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/SPIClassIterator.cs b/src/Lucene.Net/Util/SPIClassIterator.cs index 30babe3812..8cdd9697a8 100644 --- a/src/Lucene.Net/Util/SPIClassIterator.cs +++ b/src/Lucene.Net/Util/SPIClassIterator.cs @@ -37,7 +37,7 @@ public class SPIClassIterator : IEnumerable private static JCG.HashSet LoadTypes() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { - var types = new JCG.HashSet(); + var result = new JCG.HashSet(); var assembliesToExamine = Support.AssemblyUtils.GetReferencedAssemblies(); @@ -94,7 +94,7 @@ private static JCG.HashSet LoadTypes() // LUCENENET: Avoid static construc if (matchingCtors.Any()) { - types.Add(type); + result.Add(type); } } catch @@ -108,7 +108,7 @@ private static JCG.HashSet LoadTypes() // LUCENENET: Avoid static construc // swallow } } - return types; + return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -135,4 +135,4 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() return GetEnumerator(); } } -} \ No newline at end of file +}