Skip to content

Commit

Permalink
small code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed May 25, 2019
1 parent ee168fb commit 7d0301b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/NLog/Internal/ThreadSafeDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ThreadSafeDictionary(ThreadSafeDictionary<TKey, TValue> source)

public TValue this[TKey key]
{
get { return GetReadOnlyDict()[key]; }
get => GetReadOnlyDict()[key];
set
{
lock (_lockObject)
Expand Down Expand Up @@ -124,16 +124,13 @@ public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)

public void CopyFrom(IDictionary<TKey, TValue> source)
{
if (!ReferenceEquals(this, source))
if (!ReferenceEquals(this, source) && source?.Count > 0)
{
if (source?.Count > 0)
lock (_lockObject)
{
lock (_lockObject)
{
var destDict = GetWritableDict();
foreach (var item in source)
destDict[item.Key] = item.Value;
}
var destDict = GetWritableDict();
foreach (var item in source)
destDict[item.Key] = item.Value;
}
}
}
Expand Down

0 comments on commit 7d0301b

Please sign in to comment.