Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 7e84010

Browse files
benaadamsjkotas
authored andcommitted
Dictionary Initalize CQ (#15461)
1 parent c8db268 commit 7e84010

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/mscorlib/shared/System/Collections/Generic/Dictionary.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,15 @@ private int FindEntry(TKey key)
376376
private void Initialize(int capacity)
377377
{
378378
int size = HashHelpers.GetPrime(capacity);
379-
_buckets = new int[size];
380-
for (int i = 0; i < _buckets.Length; i++) _buckets[i] = -1;
381-
_entries = new Entry[size];
379+
int[] buckets = new int[size];
380+
for (int i = 0; i < buckets.Length; i++)
381+
{
382+
buckets[i] = -1;
383+
}
384+
382385
_freeList = -1;
386+
_buckets = buckets;
387+
_entries = new Entry[size];
383388
}
384389

385390
private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
@@ -470,10 +475,7 @@ public virtual void OnDeserialization(object sender)
470475

471476
if (hashsize != 0)
472477
{
473-
_buckets = new int[hashsize];
474-
for (int i = 0; i < _buckets.Length; i++) _buckets[i] = -1;
475-
_entries = new Entry[hashsize];
476-
_freeList = -1;
478+
Initialize(hashsize);
477479

478480
KeyValuePair<TKey, TValue>[] array = (KeyValuePair<TKey, TValue>[])
479481
siInfo.GetValue(KeyValuePairsName, typeof(KeyValuePair<TKey, TValue>[]));

0 commit comments

Comments
 (0)