diff options
Diffstat (limited to 'src/mscorlib/src/System/Collections/Generic')
7 files changed, 14 insertions, 161 deletions
diff --git a/src/mscorlib/src/System/Collections/Generic/Comparer.cs b/src/mscorlib/src/System/Collections/Generic/Comparer.cs index 4f06b0af69..056843a606 100644 --- a/src/mscorlib/src/System/Collections/Generic/Comparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/Comparer.cs @@ -265,9 +265,6 @@ namespace System.Collections.Generic Debug.Assert(typeof(T).IsEnum, "This type is only intended to be used to compare enums!"); } - // Used by the serialization engine. - private Int64EnumComparer(SerializationInfo info, StreamingContext context) { } - public override int Compare(T x, T y) { long lx = JitHelpers.UnsafeEnumCastLong(x); diff --git a/src/mscorlib/src/System/Collections/Generic/DebugView.cs b/src/mscorlib/src/System/Collections/Generic/DebugView.cs index d0711e551e..27c5011147 100644 --- a/src/mscorlib/src/System/Collections/Generic/DebugView.cs +++ b/src/mscorlib/src/System/Collections/Generic/DebugView.cs @@ -16,7 +16,6 @@ namespace System.Collections.Generic { using System; using System.Collections.ObjectModel; - using System.Security.Permissions; using System.Diagnostics; using System.Diagnostics.Contracts; diff --git a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs index c2b2da9ad2..7b60e31031 100644 --- a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs +++ b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs @@ -48,12 +48,10 @@ namespace System.Collections.Generic { using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.Serialization; - using System.Security.Permissions; [DebuggerTypeProxy(typeof(Mscorlib_DictionaryDebugView<,>))] [DebuggerDisplay("Count = {Count}")] [Serializable] - [System.Runtime.InteropServices.ComVisible(false)] public class Dictionary<TKey,TValue>: IDictionary<TKey,TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback { private struct Entry { diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs index 3731114119..0f9259d2f3 100644 --- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs @@ -6,7 +6,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.Security; -using System.Runtime.Serialization; namespace System.Collections.Generic { @@ -367,7 +366,7 @@ namespace System.Collections.Generic } [Serializable] - internal class EnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct + internal class EnumEqualityComparer<T> : EqualityComparer<T> where T : struct { [Pure] public override bool Equals(T x, T y) { @@ -384,16 +383,6 @@ namespace System.Collections.Generic public EnumEqualityComparer() { } - // This is used by the serialization engine. - protected EnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - - public void GetObjectData(SerializationInfo info, StreamingContext context) { - // For back-compat we need to serialize the comparers for enums with underlying types other than int as ObjectEqualityComparer - if (Type.GetTypeCode(Enum.GetUnderlyingType(typeof(T))) != TypeCode.Int32) { - info.SetType(typeof(ObjectEqualityComparer<T>)); - } - } - // Equals method for the comparer itself. public override bool Equals(Object obj) => obj != null && GetType() == obj.GetType(); @@ -427,13 +416,10 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class SByteEnumEqualityComparer<T> : EnumEqualityComparer<T>, ISerializable where T : struct + internal sealed class SByteEnumEqualityComparer<T> : EnumEqualityComparer<T> where T : struct { public SByteEnumEqualityComparer() { } - // This is used by the serialization engine. - public SByteEnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - [Pure] public override int GetHashCode(T obj) { int x_final = System.Runtime.CompilerServices.JitHelpers.UnsafeEnumCast(obj); @@ -442,13 +428,10 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T>, ISerializable where T : struct + internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T> where T : struct { public ShortEnumEqualityComparer() { } - // This is used by the serialization engine. - public ShortEnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - [Pure] public override int GetHashCode(T obj) { int x_final = System.Runtime.CompilerServices.JitHelpers.UnsafeEnumCast(obj); @@ -457,7 +440,7 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct + internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T> where T : struct { [Pure] public override bool Equals(T x, T y) { @@ -481,16 +464,6 @@ namespace System.Collections.Generic public LongEnumEqualityComparer() { } - // This is used by the serialization engine. - public LongEnumEqualityComparer(SerializationInfo information, StreamingContext context) { } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - // The LongEnumEqualityComparer does not exist on 4.0 so we need to serialize this comparer as ObjectEqualityComparer - // to allow for roundtrip between 4.0 and 4.5. - info.SetType(typeof(ObjectEqualityComparer<T>)); - } - internal override int IndexOf(T[] array, T value, int startIndex, int count) { long toFind = JitHelpers.UnsafeEnumCastLong(value); @@ -515,122 +488,4 @@ namespace System.Collections.Generic return -1; } } - -#if FEATURE_RANDOMIZED_STRING_HASHING - // This type is not serializeable by design. It does not exist in previous versions and will be removed - // Once we move the framework to using secure hashing by default. - internal sealed class RandomizedStringEqualityComparer : IEqualityComparer<String>, IEqualityComparer, IWellKnownStringEqualityComparer - { - private long _entropy; - - public RandomizedStringEqualityComparer() { - _entropy = HashHelpers.GetEntropy(); - } - - public new bool Equals(object x, object y) { - if (x == y) return true; - if (x == null || y == null) return false; - if ((x is string) && (y is string)) return Equals((string)x, (string)y); - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison); - return false; - } - - [Pure] - public bool Equals(string x, string y) { - if (x != null) { - if (y != null) return x.Equals(y); - return false; - } - if (y != null) return false; - return true; - } - - [Pure] - public int GetHashCode(String obj) { - if(obj == null) return 0; - return String.InternalMarvin32HashString(obj, obj.Length, _entropy); - } - - [Pure] - public int GetHashCode(Object obj) { - if(obj == null) return 0; - - string sObj = obj as string; - if(sObj != null) return String.InternalMarvin32HashString(sObj, sObj.Length, _entropy); - - return obj.GetHashCode(); - } - - // Equals method for the comparer itself. - public override bool Equals(Object obj) { - RandomizedStringEqualityComparer comparer = obj as RandomizedStringEqualityComparer; - return (comparer != null) && (this._entropy == comparer._entropy); - } - - public override int GetHashCode() { - return (this.GetType().GetHashCode() ^ ((int) (_entropy & 0x7FFFFFFF))); - } - - - IEqualityComparer IWellKnownStringEqualityComparer.GetRandomizedEqualityComparer() { - return new RandomizedStringEqualityComparer(); - } - - // We want to serialize the old comparer. - IEqualityComparer IWellKnownStringEqualityComparer.GetEqualityComparerForSerialization() { - return EqualityComparer<string>.Default; - } - } - - // This type is not serializeable by design. It does not exist in previous versions and will be removed - // Once we move the framework to using secure hashing by default. - internal sealed class RandomizedObjectEqualityComparer : IEqualityComparer, IWellKnownStringEqualityComparer - { - private long _entropy; - - public RandomizedObjectEqualityComparer() { - _entropy = HashHelpers.GetEntropy(); - } - - [Pure] - public new bool Equals(Object x, Object y) { - if (x != null) { - if (y != null) return x.Equals(y); - return false; - } - if (y != null) return false; - return true; - } - - [Pure] - public int GetHashCode(Object obj) { - if(obj == null) return 0; - - string sObj = obj as string; - if(sObj != null) return String.InternalMarvin32HashString(sObj, sObj.Length, _entropy); - - return obj.GetHashCode(); - } - - // Equals method for the comparer itself. - public override bool Equals(Object obj){ - RandomizedObjectEqualityComparer comparer = obj as RandomizedObjectEqualityComparer; - return (comparer != null) && (this._entropy == comparer._entropy); - } - - public override int GetHashCode() { - return (this.GetType().GetHashCode() ^ ((int) (_entropy & 0x7FFFFFFF))); - } - - IEqualityComparer IWellKnownStringEqualityComparer.GetRandomizedEqualityComparer() { - return new RandomizedObjectEqualityComparer(); - } - - // We want to serialize the old comparer, which in this case was null. - IEqualityComparer IWellKnownStringEqualityComparer.GetEqualityComparerForSerialization() { - return null; - } - } -#endif } - diff --git a/src/mscorlib/src/System/Collections/Generic/KeyNotFoundException.cs b/src/mscorlib/src/System/Collections/Generic/KeyNotFoundException.cs index ffcd0405fd..1cd18cf808 100644 --- a/src/mscorlib/src/System/Collections/Generic/KeyNotFoundException.cs +++ b/src/mscorlib/src/System/Collections/Generic/KeyNotFoundException.cs @@ -20,7 +20,6 @@ namespace System.Collections.Generic { using System.Runtime.Serialization; [Serializable] - [System.Runtime.InteropServices.ComVisible(true)] public class KeyNotFoundException : SystemException, ISerializable { public KeyNotFoundException () diff --git a/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs b/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs index ad9f7472aa..ba98adad7d 100644 --- a/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs +++ b/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs @@ -16,6 +16,7 @@ namespace System.Collections.Generic { using System; + using System.ComponentModel; using System.Text; // Provides the Create factory method for KeyValuePair<TKey, TValue>. @@ -63,7 +64,7 @@ namespace System.Collections.Generic { return StringBuilderCache.GetStringAndRelease(s); } - // BLOCKED (do not add now): [EditorBrowsable(EditorBrowsableState.Never)] + [EditorBrowsable(EditorBrowsableState.Never)] public void Deconstruct(out TKey key, out TValue value) { key = Key; diff --git a/src/mscorlib/src/System/Collections/Generic/List.cs b/src/mscorlib/src/System/Collections/Generic/List.cs index 3e2947f5f9..362e26599d 100644 --- a/src/mscorlib/src/System/Collections/Generic/List.cs +++ b/src/mscorlib/src/System/Collections/Generic/List.cs @@ -20,7 +20,6 @@ namespace System.Collections.Generic { using System.Diagnostics; using System.Diagnostics.Contracts; using System.Collections.ObjectModel; - using System.Security.Permissions; // Implements a variable-size List that uses an array of objects to store the // elements. A List has a capacity, which is the allocated length @@ -927,7 +926,9 @@ namespace System.Collections.Generic { ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); - Array.Reverse(_items, index, count); + if (count > 1) { + Array.Reverse(_items, index, count); + } _version++; } @@ -966,7 +967,9 @@ namespace System.Collections.Generic { ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); - Array.Sort<T>(_items, index, count, comparer); + if (count > 1) { + Array.Sort<T>(_items, index, count, comparer); + } _version++; } @@ -976,9 +979,10 @@ namespace System.Collections.Generic { } Contract.EndContractBlock(); - if( _size > 0) { + if (_size > 1) { ArraySortHelper<T>.Sort(_items, 0, _size, comparison); } + _version++; } // ToArray returns an array containing the contents of the List. |