Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
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
6 changes: 2 additions & 4 deletions src/mscorlib/shared/System/Collections/Generic/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ public void Clear()
_count = 0;
_freeList = -1;
_freeCount = 0;
_version++;
Array.Clear(_entries, 0, count);
}
_version++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an improvement? I would expect that it prevents tailcall for Array.Clear. Should the version increment be done as the first thing, similar to insert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't reduce the size, though keeping the tail call have moved now the two Clears together at end so it can just run through cache setting them before making the calls out

; Lcl frame size = 40
G_M52189_IG01:
       push     rdi
       push     rsi
       sub      rsp, 40
       mov      rsi, rcx
G_M52189_IG02:
       mov      edi, dword ptr [rsi+56]
       test     edi, edi
       jle      SHORT G_M52189_IG04
       xor      r8d, r8d
       mov      dword ptr [rsi+56], r8d
       mov      dword ptr [rsi+60], -1
       mov      dword ptr [rsi+64], r8d
       inc      dword ptr [rsi+68]
       mov      rcx, gword ptr [rsi+8]
       mov      r8d, dword ptr [rcx+8]
       xor      edx, edx
       call     Array:Clear(ref,int,int)
       mov      rcx, gword ptr [rsi+16]
       mov      r8d, edi
       xor      edx, edx
       lea      rax, [(reloc)]
G_M52189_IG03:
       add      rsp, 40
       pop      rsi
       pop      rdi
       rex.jmp  rax
G_M52189_IG04:
       add      rsp, 40
       pop      rsi
       pop      rdi
       ret      
; Total bytes of code 84, prolog size 9 for method Dictionary`2:Clear():this

}

public bool ContainsKey(TKey key)
Expand Down Expand Up @@ -440,6 +440,7 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
}

_version++;
if (_buckets == null)
{
Initialize(0);
Expand Down Expand Up @@ -471,7 +472,6 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
if (behavior == InsertionBehavior.OverwriteExisting)
{
entries[i].value = value;
_version++;
return true;
}

Expand Down Expand Up @@ -509,7 +509,6 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
if (behavior == InsertionBehavior.OverwriteExisting)
{
entries[i].value = value;
_version++;
return true;
}

Expand Down Expand Up @@ -571,7 +570,6 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
entry.value = value;
// Value in _buckets is 1-based
targetBucket = index + 1;
_version++;

// Value types never rehash
if (default(TKey) == null && collisionCount > HashHelpers.HashCollisionThreshold && comparer is NonRandomizedStringEqualityComparer)
Expand Down