Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[]
AcquireAllLocks(ref locksAcquired);

int count = 0;

for (int i = 0; i < _tables._locks.Length && count >= 0; i++)
int[] countPerLock = _tables._countPerLock;
for (int i = 0; i < countPerLock.Length && count >= 0; i++)
{
count += _tables._countPerLock[i];
count += countPerLock[i];
}

if (array.Length - count < index || count < 0) //"count" itself or "count + index" can overflow
Expand Down Expand Up @@ -670,9 +670,10 @@ public KeyValuePair<TKey, TValue>[] ToArray()
int count = 0;
checked
{
for (int i = 0; i < _tables._locks.Length; i++)
int[] countPerLock = _tables._countPerLock;
for (int i = 0; i < countPerLock.Length; i++)
{
count += _tables._countPerLock[i];
count += countPerLock[i];
}
}

Expand Down Expand Up @@ -998,11 +999,12 @@ public int Count
private int GetCountInternal()
{
int count = 0;
int[] countPerLocks = _tables._countPerLock;

// Compute the count, we allow overflow
for (int i = 0; i < _tables._countPerLock.Length; i++)
for (int i = 0; i < countPerLocks.Length; i++)
{
count += _tables._countPerLock[i];
count += countPerLocks[i];
}

return count;
Expand Down Expand Up @@ -1668,10 +1670,10 @@ void ICollection.CopyTo(Array array, int index)
Tables tables = _tables;

int count = 0;

for (int i = 0; i < tables._locks.Length && count >= 0; i++)
int[] countPerLock = tables._countPerLock;
for (int i = 0; i < countPerLock.Length && count >= 0; i++)
{
count += tables._countPerLock[i];
count += countPerLock[i];
}

if (array.Length - count < index || count < 0) //"count" itself or "count + index" can overflow
Expand Down Expand Up @@ -1985,9 +1987,10 @@ private ReadOnlyCollection<TKey> GetKeys()
if (count < 0) throw new OutOfMemoryException();

List<TKey> keys = new List<TKey>(count);
for (int i = 0; i < _tables._buckets.Length; i++)
Node[] buckets = _tables._buckets;
for (int i = 0; i < buckets.Length; i++)
{
Node current = _tables._buckets[i];
Node current = buckets[i];
while (current != null)
{
keys.Add(current._key);
Expand Down Expand Up @@ -2017,9 +2020,10 @@ private ReadOnlyCollection<TValue> GetValues()
if (count < 0) throw new OutOfMemoryException();

List<TValue> values = new List<TValue>(count);
for (int i = 0; i < _tables._buckets.Length; i++)
Node[] buckets = _tables._buckets;
for (int i = 0; i < buckets.Length; i++)
{
Node current = _tables._buckets[i];
Node current = buckets[i];
while (current != null)
{
values.Add(current._value);
Expand Down