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 c867278bc317fe808615a2fe17acc20b5e161a23 Author: Shad Storhaug <[email protected]> AuthorDate: Mon Jan 27 05:03:10 2020 +0700 Lucene.Net.Facet.Taxonomy.CachedOrdinalsReader: Removed locking for ordsCache when using ConditionalWeakTable (See LUCENENET-610, LUCENENET-640, LUCENENET-630) --- .../Taxonomy/CachedOrdinalsReader.cs | 30 ++++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs index 92909f7..d67b7ff 100644 --- a/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs @@ -1,6 +1,7 @@ using Lucene.Net.Support; using System; using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Runtime.CompilerServices; using System.Threading; @@ -78,26 +79,24 @@ namespace Lucene.Net.Facet.Taxonomy private CachedOrds GetCachedOrds(AtomicReaderContext context) { + object cacheKey = context.Reader.CoreCacheKey; +#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR + return ordsCache.GetValue(cacheKey, (cacheKey) => new CachedOrds(source.GetReader(context), context.Reader.MaxDoc)); +#else lock (this) { - object cacheKey = context.Reader.CoreCacheKey; if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords) || ords == null) { ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc); - ordsCache.AddOrUpdate(cacheKey, ords); + ordsCache[cacheKey] = ords; } return ords; } +#endif } - public override string IndexFieldName - { - get - { - return source.IndexFieldName; - } - } + public override string IndexFieldName => source.IndexFieldName; public override OrdinalsSegmentReader GetReader(AtomicReaderContext context) { @@ -199,19 +198,10 @@ namespace Lucene.Net.Facet.Taxonomy public virtual long RamBytesUsed() { +#if !FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR lock (this) - { - long bytes = 0; -#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR - foreach (var pair in ordsCache) - bytes += pair.Value.RamBytesUsed(); -#else - foreach (CachedOrds ords in ordsCache.Values) - bytes += ords.RamBytesUsed(); #endif - - return bytes; - } + return ordsCache.Sum(pair => pair.Value.RamBytesUsed()); } } } \ No newline at end of file
