From ce1c722991fb85f251820cdcc33d60ef8a8f55b7 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Tue, 22 Oct 2024 02:12:30 +0700 Subject: [PATCH] SWEEP: Removed FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION. Updated private fields to use J2N.Collections.Generic.Dictionary for a performance boost when we upgrade to J2N 3.x (GetEnumerator() currently boxes from struct to interface). (fixes #978) --- Directory.Build.targets | 1 - .../Taxonomy/WriterCache/NameIntCacheLRU.cs | 11 +++-------- src/Lucene.Net.TestFramework/Util/Fst/FSTTester.cs | 14 +++++--------- src/Lucene.Net/Index/IndexWriter.cs | 9 ++------- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 35988f656f..b0bcc3b8c3 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -46,7 +46,6 @@ $(DefineConstants);FEATURE_ARGITERATOR - $(DefineConstants);FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION $(DefineConstants);FEATURE_PROCESS_KILL_ENTIREPROCESSTREE $(DefineConstants);FEATURE_STRING_CONCAT_READONLYSPAN diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs index e18927595c..ba990dbc48 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using JCG = J2N.Collections.Generic; namespace Lucene.Net.Facet.Taxonomy.WriterCache { @@ -162,13 +163,7 @@ private void CreateCache(int maxSize) } else { -#if FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION - cache = new Dictionary(capacity: 1000); -#else - // LUCENENET specific - we use ConcurrentDictionary here because it supports deleting while - // iterating through the collection, but Dictionary does not. - cache = new ConcurrentDictionary(concurrencyLevel: 3, capacity: 1000); //no need for LRU -#endif + cache = new JCG.Dictionary(capacity: 1000); } } @@ -255,4 +250,4 @@ bool IInternalNameInt32CacheLru.MakeRoomLRU() return true; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.TestFramework/Util/Fst/FSTTester.cs b/src/Lucene.Net.TestFramework/Util/Fst/FSTTester.cs index 9b4decc83d..e173c6f72b 100644 --- a/src/Lucene.Net.TestFramework/Util/Fst/FSTTester.cs +++ b/src/Lucene.Net.TestFramework/Util/Fst/FSTTester.cs @@ -833,13 +833,9 @@ private void VerifyPruned(int inputMode, FST fst, int prune1, int prune2) // build all prefixes -#if FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION - IDictionary> prefixes = new Dictionary>(); -#else - // LUCENENET: We use ConcurrentDictionary because Dictionary doesn't support - // deletion while iterating, but ConcurrentDictionary does. - IDictionary> prefixes = new ConcurrentDictionary>(); -#endif + // LUCENENET specific - using concrete type for the readerMap field, since it will eliminate boxing to an interface on GetEnumerator() calls + JCG.Dictionary> prefixes = new JCG.Dictionary>(); + Int32sRef scratch = new Int32sRef(10); foreach (InputOutput pair in pairs) { @@ -927,7 +923,7 @@ private void VerifyPruned(int inputMode, FST fst, int prune1, int prune2) if (!keep) { //it.remove(); - prefixes.Remove(ent); + prefixes.Remove(prefix); //System.out.println(" remove"); } else @@ -1028,4 +1024,4 @@ private void VerifyPruned(int inputMode, FST fst, int prune1, int prune2) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/IndexWriter.cs b/src/Lucene.Net/Index/IndexWriter.cs index 23c93846ea..829c7fcd57 100644 --- a/src/Lucene.Net/Index/IndexWriter.cs +++ b/src/Lucene.Net/Index/IndexWriter.cs @@ -471,13 +471,8 @@ public ReaderPool(IndexWriter outerInstance) this.outerInstance = outerInstance; } -#if FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION - private readonly IDictionary readerMap = new Dictionary(); -#else - // LUCENENET: We use ConcurrentDictionary because Dictionary doesn't support - // deletion while iterating, but ConcurrentDictionary does. - private readonly IDictionary readerMap = new ConcurrentDictionary(); -#endif + // LUCENENET specific - using concrete type for the readerMap field, since it will eliminate boxing to an interface on GetEnumerator() calls + private readonly JCG.Dictionary readerMap = new JCG.Dictionary(); // used only by asserts public virtual bool InfoIsLive(SegmentCommitInfo info)