diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2017-06-13 18:47:36 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2017-06-13 18:47:36 +0900 |
commit | 61d6a817e39d3bae0f47dbc09838d51db22a5d30 (patch) | |
tree | cb37caa1784bc738b976273335d6ed04a7cc80b0 /src/mscorlib/src/System/Collections/Generic | |
parent | 5b975f8233e8c8d17b215372f89ca713b45d6a0b (diff) | |
download | coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.tar.gz coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.tar.bz2 coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.zip |
Imported Upstream version 2.0.0.11992upstream/2.0.0.11992
Diffstat (limited to 'src/mscorlib/src/System/Collections/Generic')
5 files changed, 31 insertions, 52 deletions
diff --git a/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs b/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs index e313cda0fb..e4a4acf74e 100644 --- a/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs +++ b/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs @@ -368,7 +368,6 @@ namespace System.Collections.Generic } } - [Serializable()] internal class GenericArraySortHelper<T> : IArraySortHelper<T> where T : IComparable<T> diff --git a/src/mscorlib/src/System/Collections/Generic/Comparer.cs b/src/mscorlib/src/System/Collections/Generic/Comparer.cs index a9b4b3f0dd..e163faa80f 100644 --- a/src/mscorlib/src/System/Collections/Generic/Comparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/Comparer.cs @@ -51,7 +51,6 @@ namespace System.Collections.Generic // reasons. Adding another base class (even one with no fields) // means another generic instantiation, which can be costly esp. // for value types. - [Serializable] internal sealed class GenericComparer<T> : Comparer<T> where T : IComparable<T> { @@ -112,7 +111,6 @@ namespace System.Collections.Generic GetType().GetHashCode(); } - [Serializable] internal sealed class ComparisonComparer<T> : Comparer<T> { private readonly Comparison<T> _comparison; @@ -133,7 +131,6 @@ namespace System.Collections.Generic // and have a SerializationInfo/StreamingContext ctor, // since we want to serialize as ObjectComparer for // back-compat reasons (see below). - [Serializable] internal sealed class Int32EnumComparer<T> : Comparer<T>, ISerializable where T : struct { diff --git a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs index e360eef897..cd33428ca1 100644 --- a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs +++ b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs @@ -17,29 +17,6 @@ ** thread safety. If a reader writer lock is available, then that may be used ** with a Dictionary to get the same thread safety guarantee. ** -** Reader writer locks don't exist in silverlight, so we do the following as a -** result of removing non-generic collections from silverlight: -** 1. If the Hashtable was fully synchronized, then we replace it with a -** Dictionary with full locks around reads/writes (same thread safety -** guarantee). -** 2. Otherwise, the Hashtable has the default MR/SW thread safety behavior, -** so we do one of the following on a case-by-case basis: -** a. If the race condition can be addressed by rearranging the code and using a temp -** variable (for example, it's only populated immediately after created) -** then we address the race condition this way and use Dictionary. -** b. If there's concern about degrading performance with the increased -** locking, we ifdef with FEATURE_NONGENERIC_COLLECTIONS so we can at -** least use Hashtable in the desktop build, but Dictionary with full -** locks in silverlight builds. Note that this is heavier locking than -** MR/SW, but this is the only option without rewriting (or adding back) -** the reader writer lock. -** c. If there's no performance concern (e.g. debug-only code) we -** consistently replace Hashtable with Dictionary plus full locks to -** reduce complexity. -** d. Most of serialization is dead code in silverlight. Instead of updating -** those Hashtable occurences in serialization, we carved out references -** to serialization such that this code doesn't need to build in -** silverlight. ===========================================================*/ namespace System.Collections.Generic @@ -706,22 +683,6 @@ namespace System.Collections.Generic value = default(TValue); return false; } - - // Method similar to TryGetValue that returns the value instead of putting it in an out param. - public TValue GetValueOrDefault(TKey key) => GetValueOrDefault(key, default(TValue)); - - // Method similar to TryGetValue that returns the value instead of putting it in an out param. If the entry - // doesn't exist, returns the defaultValue instead. - public TValue GetValueOrDefault(TKey key, TValue defaultValue) - { - int i = FindEntry(key); - if (i >= 0) - { - return entries[i].value; - } - return defaultValue; - } - public bool TryAdd(TKey key, TValue value) => TryInsert(key, value, InsertionBehavior.None); bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly @@ -947,7 +908,6 @@ namespace System.Collections.Generic } } - [Serializable] public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDictionaryEnumerator { @@ -1076,7 +1036,6 @@ namespace System.Collections.Generic [DebuggerTypeProxy(typeof(Mscorlib_DictionaryKeyCollectionDebugView<,>))] [DebuggerDisplay("Count = {Count}")] - [Serializable] public sealed class KeyCollection : ICollection<TKey>, ICollection, IReadOnlyCollection<TKey> { private Dictionary<TKey, TValue> dictionary; @@ -1227,7 +1186,6 @@ namespace System.Collections.Generic get { return ((ICollection)dictionary).SyncRoot; } } - [Serializable] public struct Enumerator : IEnumerator<TKey>, System.Collections.IEnumerator { private Dictionary<TKey, TValue> dictionary; @@ -1306,7 +1264,6 @@ namespace System.Collections.Generic [DebuggerTypeProxy(typeof(Mscorlib_DictionaryValueCollectionDebugView<,>))] [DebuggerDisplay("Count = {Count}")] - [Serializable] public sealed class ValueCollection : ICollection<TValue>, ICollection, IReadOnlyCollection<TValue> { private Dictionary<TKey, TValue> dictionary; @@ -1455,7 +1412,6 @@ namespace System.Collections.Generic get { return ((ICollection)dictionary).SyncRoot; } } - [Serializable] public struct Enumerator : IEnumerator<TValue>, System.Collections.IEnumerator { private Dictionary<TKey, TValue> dictionary; diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs index 0cd1bc1c12..d6b213c9d7 100644 --- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs @@ -10,6 +10,7 @@ using System.Security; using System.Globalization; using System.Runtime; using System.Runtime.CompilerServices; +using System.Runtime.Serialization; using System.Diagnostics.Contracts; namespace System.Collections.Generic @@ -352,7 +353,7 @@ namespace System.Collections.Generic } [Serializable] - internal class EnumEqualityComparer<T> : EqualityComparer<T> where T : struct + internal class EnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct { [Pure] public override bool Equals(T x, T y) @@ -371,6 +372,9 @@ namespace System.Collections.Generic public EnumEqualityComparer() { } + // This is used by the serialization engine. + protected EnumEqualityComparer(SerializationInfo information, StreamingContext context) { } + // Equals method for the comparer itself. public override bool Equals(Object obj) => obj != null && GetType() == obj.GetType(); @@ -401,6 +405,14 @@ namespace System.Collections.Generic } return -1; } + + 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>)); + } + } } [Serializable] @@ -408,6 +420,9 @@ namespace System.Collections.Generic { public SByteEnumEqualityComparer() { } + // This is used by the serialization engine. + public SByteEnumEqualityComparer(SerializationInfo information, StreamingContext context) { } + [Pure] public override int GetHashCode(T obj) { @@ -417,10 +432,13 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T> where T : struct + internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T>, ISerializable 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) { @@ -430,7 +448,7 @@ namespace System.Collections.Generic } [Serializable] - internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T> where T : struct + internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct { [Pure] public override bool Equals(T x, T y) @@ -479,5 +497,15 @@ namespace System.Collections.Generic } return -1; } + + // 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>)); + } } } diff --git a/src/mscorlib/src/System/Collections/Generic/List.cs b/src/mscorlib/src/System/Collections/Generic/List.cs index 4e480885ef..94e794cfd2 100644 --- a/src/mscorlib/src/System/Collections/Generic/List.cs +++ b/src/mscorlib/src/System/Collections/Generic/List.cs @@ -1254,7 +1254,6 @@ namespace System.Collections.Generic } } - [Serializable] public struct Enumerator : IEnumerator<T>, System.Collections.IEnumerator { private List<T> list; |