Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorRodrigo Kumpera <kumpera@users.noreply.github.com>2018-09-06 18:08:07 +0300
committerLudovic Henry <luhenry@microsoft.com>2018-09-06 18:08:07 +0300
commitd21d00b366cbf9115248c40bd8c72d4db717fd63 (patch)
tree155b8be1f39950910599229f05a21b2ed28e6fad /mcs
parent0c7e4b378e1fd8c524116dcdf8a2be83c8a0ad83 (diff)
[corlib] Don't decrement ConditionalWeakTable::size on remove. (#10477)
We can't decrement the size on removal as we use tombstones. When using tombstones, the invariant to keep is on the number of null entries as those are used as search stop-marks. Without this change, it's possible that a long series of add/remove operations could leave the array with no null entries, just tombstones and filled entries. In that case, search would degenerate into a linear search that would look into all array elements. This change fixes worst-case perf of not-found searches to be bound to the load factor. Additionally, clear the array to null entries, otherwise we fall into the above trap even more easily.
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/corlib/System.Runtime.CompilerServices/ConditionalWeakTable.cs3
1 files changed, 1 insertions, 2 deletions
diff --git a/mcs/class/corlib/System.Runtime.CompilerServices/ConditionalWeakTable.cs b/mcs/class/corlib/System.Runtime.CompilerServices/ConditionalWeakTable.cs
index 17474df4f97..97bab6e7961 100644
--- a/mcs/class/corlib/System.Runtime.CompilerServices/ConditionalWeakTable.cs
+++ b/mcs/class/corlib/System.Runtime.CompilerServices/ConditionalWeakTable.cs
@@ -225,7 +225,6 @@ namespace System.Runtime.CompilerServices
if (k == key) {
data [idx].key = GC.EPHEMERON_TOMBSTONE;
data [idx].value = null;
- --size;
return true;
}
if (k == null)
@@ -325,7 +324,7 @@ namespace System.Runtime.CompilerServices
{
for (int i = 0; i < data.Length; i++)
{
- data[i].key = GC.EPHEMERON_TOMBSTONE;
+ data[i].key = null;
data[i].value = null;
}