-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Dictionary/List code clean up/formatting (C#7) #17196
Conversation
@dotnet-bot test Windows_NT x64 Checked corefx_baseline |
baseline failures https://github.com/dotnet/coreclr/issues/17205
|
@@ -684,6 +672,7 @@ public bool Remove(TKey key) | |||
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); | |||
} | |||
|
|||
_version++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why move the version increment here? It is a potential breaking change.
@@ -740,6 +728,7 @@ public bool Remove(TKey key, out TValue value) | |||
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); | |||
} | |||
|
|||
_version++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
@@ -724,6 +676,7 @@ public int IndexOf(T item, int index, int count) | |||
// | |||
public void Insert(int index, T item) | |||
{ | |||
_version++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Won't comment on all places.
Along same lines as "Prevent concurrent use corruption from causing infinite loops" #16991 At the moment the version will only update if Can back it out (especially since this was mostly cosmetic changes) |
d755f40
to
3971a59
Compare
Dropped the behaviour changing version moves
|
Thanks. Here is example that I was concerned about: var d = new Dictionary<string,string>();
d.Add("a", "b");
d.Add("c", "d");
foreach (var e in d)
{
if (d.Remove(e.Key + "Sibling")) break;
} This works perfectly fine today, but it would start throwing exceptions with the version increments moved. |
Ah... yeah that's valid |
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
@@ -320,20 +315,16 @@ private void CopyTo(KeyValuePair<TKey, TValue>[] array, int index) | |||
{ | |||
if (entries[i].hashCode >= 0) | |||
{ | |||
array[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value); | |||
array[index + i] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change and needs to be reverted. Let's say there were 2 entries in the dictionary and then 1 was removed, so for example Count == 1, entries[0].hashCode == -1, entries[1] == the item. This would previously copy the single entry to array[0]; now it's going to copy it to array[1], which a) is the wrong index and b) will blow up if a developer passed in an array sized to Count.
cc: @jkotas, @benaadams
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
due to the skip :-/
Give a few mins...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i
always increases but there might not be an entry (due to hashCode < 0
) so the index for the array shouldn't increase when there isn't an entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, and _count isn't the same as Count (Count is confusingly _count - _freeCount). Lots of System.Net.Http outerloop tests are failing as a result. Looks like we must also then have a Dictionary test hole that needs to be plugged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_count isn't the same as Count (Count is confusingly _count - _freeCount). Lots of System.Net.Http outerloop tests are failing as a result. Looks like we must also then have a Dictionary test hole that needs to be plugged.
Because they should have failed with array out of bounds on CopyTo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because they should have failed with array out of bounds on CopyTo?
That's the failure mode hitting System.Net.Http, as CurlHandler uses CopyTo.
But if the output array is large enough to accommodate it, the bug could also manifest as a gap in the copied data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -181,12 +163,12 @@ object System.Collections.ICollection.SyncRoot | |||
|
|||
set | |||
{ | |||
_version++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This move of the _version++
should be also reverted.
Do we need a test for this also?
|
and some mild asm improves