You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2019/07/09 21:29:30 UTC
[lucenenet] 14/29: Use ConcurrentDictionary::GetOrAdd
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 5aaf59acf7987616f93abf9aa3ab087a35648bdc
Author: Thomas Mathew <th...@microsoft.com>
AuthorDate: Fri Jun 7 13:35:48 2019 -0700
Use ConcurrentDictionary::GetOrAdd
---
src/Lucene.Net/Support/IO/FileSupport.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Lucene.Net/Support/IO/FileSupport.cs b/src/Lucene.Net/Support/IO/FileSupport.cs
index 55e722a..dacba8b 100644
--- a/src/Lucene.Net/Support/IO/FileSupport.cs
+++ b/src/Lucene.Net/Support/IO/FileSupport.cs
@@ -180,7 +180,7 @@ namespace Lucene.Net.Support.IO
return Path.Combine(directory.FullName, string.Concat(prefix, randomFileName));
}
- private static readonly IDictionary<string, string> fileCanonPathCache = new ConcurrentDictionary<string, string>();
+ private static readonly ConcurrentDictionary<string, string> fileCanonPathCache = new ConcurrentDictionary<string, string>();
/// <summary>
/// Returns the absolute path of this <see cref="FileSystemInfo"/> with all references resolved and
@@ -299,7 +299,7 @@ namespace Lucene.Net.Support.IO
//newResult = getCanonImpl(newResult);
newLength = newResult.Length;
canonPath = Encoding.UTF8.GetString(newResult, 0, newLength).TrimEnd('\0'); // LUCENENET: Eliminate null terminator char
- fileCanonPathCache[absPath] = canonPath;
+ canonPath = fileCanonPathCache.GetOrAdd(absPath, canonPath); // It's possible that a concurrent call may have already added it to the cache.
return canonPath;
}
}