This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 57ed84af858b74429e391ddc52d5190c2334651a
Author: Shad Storhaug <[email protected]>
AuthorDate: Mon Aug 24 20:39:51 2020 +0700

    PERFORMANCE: Lucene.Net.Util.AttributeSource.DefaultAttributeFactory: Use 
external lock for better performance and removed redundant GetOrAdd() call
---
 src/Lucene.Net/Util/AttributeSource.cs | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/Lucene.Net/Util/AttributeSource.cs 
b/src/Lucene.Net/Util/AttributeSource.cs
index 7cfa60b..0b5f922 100644
--- a/src/Lucene.Net/Util/AttributeSource.cs
+++ b/src/Lucene.Net/Util/AttributeSource.cs
@@ -61,6 +61,7 @@ namespace Lucene.Net.Util
                 // identity for a class, so there is no need for an identity 
wrapper for it.
                 private static readonly ConditionalWeakTable<Type, 
WeakReference<Type>> attClassImplMap =
                     new ConditionalWeakTable<Type, WeakReference<Type>>();
+                private static readonly object attClassImplMapLock = new 
object();
 
                 internal DefaultAttributeFactory()
                 {
@@ -108,16 +109,13 @@ namespace Lucene.Net.Util
                     var attClass = typeof(T);
                     Type clazz;
 
-                    // LUCENENET: If the weakreference is dead, we need to 
explicitly remove and re-add its key.
-                    // We synchronize on attClassImplMap only to make the 
operation atomic. This does not actually
-                    // utilize the same lock as attClassImplMap does 
internally, but since this is the only place
-                    // it is used, it is fine here.
-                    lock (attClassImplMap)
+                    // LUCENENET: If the weakreference is dead, we need to 
explicitly update its key.
+                    // We synchronize on attClassImplMapLock to make the 
operation atomic.
+                    lock (attClassImplMapLock)
                     {
                         if (!attClassImplMap.TryGetValue(attClass, out var 
@ref) || [email protected](out clazz))
                         {
 #if FEATURE_CONDITIONALWEAKTABLE_ADDORUPDATE
-                            // There is a small chance that multiple threads 
will get through here, but it doesn't matter
                             attClassImplMap.AddOrUpdate(attClass, 
CreateAttributeWeakReference(attClass, out clazz));
 #else
                             attClassImplMap.Remove(attClass);

Reply via email to