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 |
| ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); | ||
| } | ||
|
|
||
| _version++; |
There was a problem hiding this comment.
Why move the version increment here? It is a potential breaking change.
| ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); | ||
| } | ||
|
|
||
| _version++; |
| // | ||
| public void Insert(int index, T item) | ||
| { | ||
| _version++; |
There was a problem hiding this comment.
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>
| 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.
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.
due to the skip :-/
Give a few mins...
There was a problem hiding this comment.
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.
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.
_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.
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.
|
|
||
| set | ||
| { | ||
| _version++; |
There was a problem hiding this comment.
This move of the _version++ should be also reverted.
|
Do we need a test for this also? |
and some mild asm improves