This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new 799c603 Lucene.Net.Support.DictionaryExtensions: Factored out
EntrySet(), as IDictionary<TKey, TValue> is already enumerable without copying
it to another data structure
799c603 is described below
commit 799c60382d9b949865a2fca2b65f9b1bd12163d1
Author: Shad Storhaug <[email protected]>
AuthorDate: Tue Dec 3 21:38:52 2019 +0700
Lucene.Net.Support.DictionaryExtensions: Factored out EntrySet(), as
IDictionary<TKey, TValue> is already enumerable without copying it to another
data structure
---
src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs | 2 +-
src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs | 4 ++--
.../Index/BaseDocValuesFormatTestCase.cs | 3 +--
.../Index/BasePostingsFormatTestCase.cs | 2 +-
src/Lucene.Net.Tests.Join/TestJoinUtil.cs | 2 +-
src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs | 2 +-
src/Lucene.Net/Support/DictionaryExtensions.cs | 12 ------------
7 files changed, 7 insertions(+), 20 deletions(-)
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs
b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs
index 480c4d6..aa8fada 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayMap.cs
@@ -1424,7 +1424,7 @@ namespace Lucene.Net.Analysis.Util
{
var sb = new StringBuilder("{");
- using (IEnumerator<KeyValuePair<string, TValue>> iter1 =
DictionaryExtensions.EntrySet(this).GetEnumerator())
+ using (var iter1 = this.GetEnumerator())
{
while (iter1.MoveNext())
{
diff --git a/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
b/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
index cc2c248..1b3bdda 100644
--- a/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
@@ -403,7 +403,7 @@ namespace Lucene.Net.Codecs.Bloom
public override long RamBytesUsed()
{
var sizeInBytes = ((_delegateFieldsProducer != null) ?
_delegateFieldsProducer.RamBytesUsed() : 0);
- foreach (var entry in _bloomsByFieldName.EntrySet())
+ foreach (var entry in _bloomsByFieldName)
{
sizeInBytes += entry.Key.Length *
RamUsageEstimator.NUM_BYTES_CHAR;
sizeInBytes += entry.Value.RamBytesUsed();
@@ -455,7 +455,7 @@ namespace Lucene.Net.Codecs.Bloom
{
_delegateFieldsConsumer.Dispose();
// Now we are done accumulating values for these fields
- var nonSaturatedBlooms = (from entry in
_bloomFilters.EntrySet() let bloomFilter = entry.Value where
!outerInstance._bloomFilterFactory.IsSaturated(bloomFilter, entry.Key) select
entry).ToList();
+ var nonSaturatedBlooms = (from entry in _bloomFilters let
bloomFilter = entry.Value where
!outerInstance._bloomFilterFactory.IsSaturated(bloomFilter, entry.Key) select
entry).ToList();
var bloomFileName = IndexFileNames.SegmentFileName(
_state.SegmentInfo.Name, _state.SegmentSuffix,
BLOOM_EXTENSION);
diff --git a/src/Lucene.Net.TestFramework/Index/BaseDocValuesFormatTestCase.cs
b/src/Lucene.Net.TestFramework/Index/BaseDocValuesFormatTestCase.cs
index 03f8e1b..3ef0cb7 100644
--- a/src/Lucene.Net.TestFramework/Index/BaseDocValuesFormatTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Index/BaseDocValuesFormatTestCase.cs
@@ -1448,9 +1448,8 @@ namespace Lucene.Net.Index
Assert.AreEqual(i, ord);
}
AtomicReader slowR =
SlowCompositeReaderWrapper.Wrap(reader);
- ISet<KeyValuePair<string, string>> entrySet =
docToString.EntrySet();
- foreach (KeyValuePair<string, string> entry in
entrySet)
+ foreach (KeyValuePair<string, string> entry in
docToString)
{
// pk lookup
DocsEnum termDocsEnum = slowR.GetTermDocsEnum(new
Term("id", entry.Key));
diff --git a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
index 2759cec..e03d0e3 100644
--- a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
@@ -523,7 +523,7 @@ namespace Lucene.Net.Index
foreach (KeyValuePair<string, SortedDictionary<BytesRef, long>>
fieldEnt in fields)
{
string field = fieldEnt.Key;
- foreach (KeyValuePair<BytesRef, long> termEnt in
fieldEnt.Value.EntrySet())
+ foreach (KeyValuePair<BytesRef, long> termEnt in
fieldEnt.Value)
{
allTerms.Add(new FieldAndTerm(field, termEnt.Key));
}
diff --git a/src/Lucene.Net.Tests.Join/TestJoinUtil.cs
b/src/Lucene.Net.Tests.Join/TestJoinUtil.cs
index 3d26727..d6916bb 100644
--- a/src/Lucene.Net.Tests.Join/TestJoinUtil.cs
+++ b/src/Lucene.Net.Tests.Join/TestJoinUtil.cs
@@ -993,7 +993,7 @@ namespace Lucene.Net.Tests.Join
? context.FromHitsToJoinScore[queryValue]
: context.ToHitsToJoinScore[queryValue];
- var hits = new List<KeyValuePair<int,
JoinScore>>(hitsToJoinScores.EntrySet());
+ var hits = new List<KeyValuePair<int,
JoinScore>>(hitsToJoinScores);
hits.Sort(new ComparerAnonymousInnerClassHelper(this, scoreMode));
ScoreDoc[] scoreDocs = new ScoreDoc[Math.Min(10, hits.Count)];
for (int i = 0; i < scoreDocs.Length; i++)
diff --git a/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs
b/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs
index 6e194c9..04d0da0 100644
--- a/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs
+++ b/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs
@@ -136,7 +136,7 @@ namespace Lucene.Net.Search
StartingGun.Wait();
for (int i = 0; i < 20; i++)
{
- IList<KeyValuePair<BytesRef, TopDocs>> shuffled = new
List<KeyValuePair<BytesRef, TopDocs>>(Answers.EntrySet());
+ IList<KeyValuePair<BytesRef, TopDocs>> shuffled = new
List<KeyValuePair<BytesRef, TopDocs>>(Answers);
Collections.Shuffle(shuffled);
foreach (KeyValuePair<BytesRef, TopDocs> ent in
shuffled)
{
diff --git a/src/Lucene.Net/Support/DictionaryExtensions.cs
b/src/Lucene.Net/Support/DictionaryExtensions.cs
index d143bf8..0dda2c0 100644
--- a/src/Lucene.Net/Support/DictionaryExtensions.cs
+++ b/src/Lucene.Net/Support/DictionaryExtensions.cs
@@ -33,18 +33,6 @@ namespace Lucene.Net.Support
}
}
- // LUCENENET TODO: Maybe factor this out? Dictionaries already expose
their entries and there is
- // little point in putting them into a set just so you can enumerate
them.
- public static ISet<KeyValuePair<TKey, TValue>> EntrySet<TKey,
TValue>(this IDictionary<TKey, TValue> dict)
- {
- ISet<KeyValuePair<TKey, TValue>> iset = new
HashSet<KeyValuePair<TKey, TValue>>();
- foreach (KeyValuePair<TKey, TValue> kvp in dict)
- {
- iset.Add(kvp);
- }
- return iset;
- }
-
public static TValue Put<TKey, TValue>(this IDictionary<TKey, TValue>
dict, TKey key, TValue value)
{
if (dict == null)