Skip to content

Commit

Permalink
Use concrete ConcurrentHashSet instead of abstraction for performance (
Browse files Browse the repository at this point in the history
…#960)

* Use concrete ConcurrentHashSet instead of abstraction for performance

Calling into an interface when its not necessary will result in poorer performance because the JIT needs to do some type analysis. When it is a concrete type, this is avoided. Since this is an internal field there's no reason to use the abstracted type. 

See https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1859
  • Loading branch information
Shazwazza authored Sep 20, 2024
1 parent 0d7bba7 commit 627fccc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Lucene.Net/Search/ReferenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected G Current

private readonly ReentrantLock refreshLock = new ReentrantLock();

private readonly ISet<ReferenceManager.IRefreshListener> refreshListeners = new ConcurrentHashSet<ReferenceManager.IRefreshListener>();
private readonly ConcurrentHashSet<ReferenceManager.IRefreshListener> refreshListeners = new ConcurrentHashSet<ReferenceManager.IRefreshListener>();

private void EnsureOpen()
{
Expand Down Expand Up @@ -367,7 +367,7 @@ public virtual void RemoveListener(ReferenceManager.IRefreshListener listener)
{
throw new ArgumentNullException(nameof(listener), "Listener cannot be null"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention)
}
refreshListeners.Remove(listener);
refreshListeners.TryRemove(listener);
}
}

Expand Down Expand Up @@ -396,4 +396,4 @@ public interface IRefreshListener
void AfterRefresh(bool didRefresh);
}
}
}
}

0 comments on commit 627fccc

Please sign in to comment.