Skip to content

Commit 2a0c974

Browse files
authored
PERFORMANCE: Lucene.Net.Replicator.LocalReplicator.ReplicationSession: Use J2N.Collections.Dictionary<TKey, TValue> to allow deleting while iterating forward prior to .NET Core (fixes #1070). (#1108)
1 parent 013f962 commit 2a0c974

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Lucene.Net.Replicator/LocalReplicator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.IO;
88
using System.Linq;
9+
using JCG = J2N.Collections.Generic;
910

1011
namespace Lucene.Net.Replicator
1112
{
@@ -132,14 +133,13 @@ public virtual void MarkAccessed()
132133
private volatile bool disposed = false;
133134

134135
private readonly AtomicInt32 sessionToken = new AtomicInt32(0);
135-
private readonly IDictionary<string, ReplicationSession> sessions = new Dictionary<string, ReplicationSession>();
136+
private readonly JCG.Dictionary<string, ReplicationSession> sessions = new JCG.Dictionary<string, ReplicationSession>();
136137

137138
/// <exception cref="InvalidOperationException"></exception>
138139
private void CheckExpiredSessions()
139140
{
140-
// .NET NOTE: .ToArray() so we don't modify a collection we are enumerating...
141-
// I am wondering if it would be overall more practical to switch to a concurrent dictionary...
142-
foreach (ReplicationSession token in sessions.Values.Where(token => token.IsExpired(ExpirationThreshold)).ToArray())
141+
// LUCENENET NOTE: JCG.Dictionary<TKey, TValue> required for deleting while iterating forward prior to .NET Core
142+
foreach (ReplicationSession token in sessions.Values.Where(token => token.IsExpired(ExpirationThreshold)))
143143
{
144144
ReleaseSession(token.Session.Id);
145145
}

0 commit comments

Comments
 (0)