From 1e1599a4ca6639651dcadc25354f4012217e5efe Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 20 Sep 2024 09:05:41 -0600 Subject: [PATCH 1/2] 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Lucene.Net/Search/ReferenceManager.cs b/src/Lucene.Net/Search/ReferenceManager.cs index ee9c2f34b5..0e4b134473 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() { @@ -396,4 +396,4 @@ public interface IRefreshListener void AfterRefresh(bool didRefresh); } } -} \ No newline at end of file +} From 4d9c142f5f652cc4f47d1eea647e1db87908be76 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 20 Sep 2024 09:44:04 -0600 Subject: [PATCH 2/2] fix build --- src/Lucene.Net/Search/ReferenceManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lucene.Net/Search/ReferenceManager.cs b/src/Lucene.Net/Search/ReferenceManager.cs index 0e4b134473..ccfb109f4e 100644 --- a/src/Lucene.Net/Search/ReferenceManager.cs +++ b/src/Lucene.Net/Search/ReferenceManager.cs @@ -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); } }