{
AcquireAllLocks(ref locksAcquired);
+ // If the dictionary is already empty, then there's nothing to clear.
+ if (AreAllBucketsEmpty())
+ {
+ return;
+ }
+
Tables tables = _tables;
var newTables = new Tables(new Node[DefaultCapacity], tables._locks, new int[tables._countPerLock.Length]);
_tables = newTables;
ReleaseLocks(0, acquiredLocks);
}
- bool AreAllBucketsEmpty()
- {
- int[] countPerLock = _tables._countPerLock;
-
- for (int i = 0; i < countPerLock.Length; i++)
- {
- if (countPerLock[i] != 0)
- {
- return false;
- }
- }
- return true;
- }
}
}
#endregion
+
+ private bool AreAllBucketsEmpty()
+ {
+ int[] countPerLock = _tables._countPerLock;
+
+ for (int i = 0; i < countPerLock.Length; i++)
+ {
+ if (countPerLock[i] != 0)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
/// <summary>
/// Replaces the bucket table with a larger one. To prevent multiple threads from resizing the
/// table as a result of races, the Tables instance that holds the table of buckets deemed too