From 5719bdbf70c57a882335046cde767eed08d51980 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Mon, 26 Feb 2018 23:11:26 -0800 Subject: [PATCH] Allocate WeakKeyDictionary`2 with smaller initial capacities Fixes #221 --- .../AsyncReaderWriterResourceLock.cs | 2 +- .../JoinableTaskCollection.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.VisualStudio.Threading/AsyncReaderWriterResourceLock.cs b/src/Microsoft.VisualStudio.Threading/AsyncReaderWriterResourceLock.cs index 5671c94d8..b967d7d2f 100644 --- a/src/Microsoft.VisualStudio.Threading/AsyncReaderWriterResourceLock.cs +++ b/src/Microsoft.VisualStudio.Threading/AsyncReaderWriterResourceLock.cs @@ -477,7 +477,7 @@ internal class Helper /// /// A map of resources to the tasks that most recently began evaluating them. /// - private WeakKeyDictionary resourcePreparationTasks = new WeakKeyDictionary(); + private WeakKeyDictionary resourcePreparationTasks = new WeakKeyDictionary(capacity: 2); /// /// Initializes a new instance of the class. diff --git a/src/Microsoft.VisualStudio.Threading/JoinableTaskCollection.cs b/src/Microsoft.VisualStudio.Threading/JoinableTaskCollection.cs index 5fc071d61..e414d2eb9 100644 --- a/src/Microsoft.VisualStudio.Threading/JoinableTaskCollection.cs +++ b/src/Microsoft.VisualStudio.Threading/JoinableTaskCollection.cs @@ -26,14 +26,14 @@ public class JoinableTaskCollection : IEnumerable /// The value is the number of times the joinable was added to this collection (and not yet removed) /// if this collection is ref counted; otherwise the value is always 1. /// - private readonly WeakKeyDictionary joinables = new WeakKeyDictionary(); + private readonly WeakKeyDictionary joinables = new WeakKeyDictionary(capacity: 2); /// /// The set of joinable tasks that have Joined this collection -- that is, the set of joinable tasks that are interested /// in the completion of any and all joinable tasks that belong to this collection. /// The value is the number of times a particular joinable task has Joined this collection. /// - private readonly WeakKeyDictionary joiners = new WeakKeyDictionary(); + private readonly WeakKeyDictionary joiners = new WeakKeyDictionary(capacity: 2); /// /// A value indicating whether joinable tasks are only removed when completed or removed as many times as they were added.