Skip to content

Commit

Permalink
PERFORMANCE: Lucene.Net.Replicator.LocalReplicator.ReplicationSession…
Browse files Browse the repository at this point in the history
…: Use J2N.Collections.Dictionary<TKey, TValue> to allow deleting while iterating forward prior to .NET Core (fixes #1070). (#1108)
  • Loading branch information
NightOwl888 authored Jan 20, 2025
1 parent 013f962 commit 2a0c974
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Lucene.Net.Replicator/LocalReplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using JCG = J2N.Collections.Generic;

namespace Lucene.Net.Replicator
{
Expand Down Expand Up @@ -132,14 +133,13 @@ public virtual void MarkAccessed()
private volatile bool disposed = false;

private readonly AtomicInt32 sessionToken = new AtomicInt32(0);
private readonly IDictionary<string, ReplicationSession> sessions = new Dictionary<string, ReplicationSession>();
private readonly JCG.Dictionary<string, ReplicationSession> sessions = new JCG.Dictionary<string, ReplicationSession>();

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

0 comments on commit 2a0c974

Please sign in to comment.