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 990f929cca17a0fbfb9bb2a798258a77ebedd6a4 Author: Shad Storhaug <[email protected]> AuthorDate: Mon Aug 24 20:16:52 2020 +0700 PERFORMANCE: Lucene.Net.Util: Streamlined DefaultAttributeFactory to make the get/update process of creating an attribute WeakReference atomic --- src/Lucene.Net/Util/AttributeSource.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Lucene.Net/Util/AttributeSource.cs b/src/Lucene.Net/Util/AttributeSource.cs index 0f0ed10..7cfa60b 100644 --- a/src/Lucene.Net/Util/AttributeSource.cs +++ b/src/Lucene.Net/Util/AttributeSource.cs @@ -108,20 +108,13 @@ namespace Lucene.Net.Util var attClass = typeof(T); Type clazz; -#if !FEATURE_CONDITIONALWEAKTABLE_ADDORUPDATE // 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. - - // In .NET Standard 2.1, we can use AddOrUpdate, so don't need the lock. lock (attClassImplMap) -#endif { - var @ref = attClassImplMap.GetValue(attClass, createValueCallback: (key) => - CreateAttributeWeakReference(key, out clazz)); - - if ([email protected](out clazz)) + 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
