From 627fccc840ad74fa51bfff897373f5a5b450c661 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 20 Sep 2024 15:34:08 -0600 Subject: [PATCH] Use concrete ConcurrentHashSet instead of abstraction for performance (#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 --- src/Lucene.Net/Search/ReferenceManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Lucene.Net/Search/ReferenceManager.cs b/src/Lucene.Net/Search/ReferenceManager.cs index ee9c2f34b5..ccfb109f4e 100644 --- a/src/Lucene.Net/Search/ReferenceManager.cs +++ b/src/Lucene.Net/Search/ReferenceManager.cs @@ -56,7 +56,7 @@ protected G Current private readonly ReentrantLock refreshLock = new ReentrantLock(); - private readonly ISet refreshListeners = new ConcurrentHashSet(); + private readonly ConcurrentHashSet refreshListeners = new ConcurrentHashSet(); private void EnsureOpen() { @@ -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); } } @@ -396,4 +396,4 @@ public interface IRefreshListener void AfterRefresh(bool didRefresh); } } -} \ No newline at end of file +}