Move types to shared corelib partition (#15768)
authorJan Kotas <jkotas@microsoft.com>
Sat, 6 Jan 2018 17:14:22 +0000 (09:14 -0800)
committerGitHub <noreply@github.com>
Sat, 6 Jan 2018 17:14:22 +0000 (09:14 -0800)
- YieldAwaitable: Fixed readonly mismatch
- Comparer: Made public to fix https://github.com/dotnet/corefx/issues/25973

src/mscorlib/System.Private.CoreLib.csproj
src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
src/mscorlib/shared/System/Collections/Comparer.cs [moved from src/mscorlib/src/System/Collections/Comparer.cs with 50% similarity]
src/mscorlib/shared/System/Collections/Generic/NonRandomizedStringEqualityComparer.cs
src/mscorlib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
src/mscorlib/shared/System/Runtime/CompilerServices/YieldAwaitable.cs [moved from src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs with 98% similarity]
src/mscorlib/src/System/Globalization/CultureInfo.cs

index 7dbe910..c28bb6e 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\ConditionalWeakTable.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\AsyncMethodBuilder.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\TaskAwaiter.cs" />
-    <Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\YieldAwaitable.cs" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="$(BclSourcesRoot)\System\Runtime\Reliability\CriticalFinalizerObject.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\GcSettings.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="$(BclSourcesRoot)\System\Collections\Comparer.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Collections\CompatibleComparer.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Collections\EmptyReadOnlyDictionaryInternal.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Collections\Hashtable.cs" />
index aaf6bfc..344f8eb 100644 (file)
@@ -54,6 +54,7 @@
     <Compile Include="$(MSBuildThisFileDirectory)System\Char.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\CharEnumerator.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\CLSCompliantAttribute.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Comparer.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\DictionaryEntry.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\Dictionary.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ICollection.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TypeForwardedToAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\UnsafeValueTypeAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ValueTaskAwaiter.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\YieldAwaitable.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Cer.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Consistency.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\ReliabilityContractAttribute.cs" />
@@ -4,58 +4,64 @@
 
 /*============================================================
 **
-** 
-** 
-**
-**
 ** Purpose: Default IComparer implementation.
 **
-** 
 ===========================================================*/
 
 using System.Globalization;
+using System.Runtime.Serialization;
 
 namespace System.Collections
 {
-    internal sealed class Comparer : IComparer
+    [Serializable]
+    [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+    public sealed class Comparer : IComparer, ISerializable
     {
-        private CompareInfo m_compareInfo;
+        private CompareInfo _compareInfo;
+
         public static readonly Comparer Default = new Comparer(CultureInfo.CurrentCulture);
         public static readonly Comparer DefaultInvariant = new Comparer(CultureInfo.InvariantCulture);
 
-        private Comparer()
-        {
-            m_compareInfo = null;
-        }
-
         public Comparer(CultureInfo culture)
         {
             if (culture == null)
-            {
                 throw new ArgumentNullException(nameof(culture));
-            }
-            m_compareInfo = culture.CompareInfo;
+
+            _compareInfo = culture.CompareInfo;
+        }
+
+        private Comparer(SerializationInfo info, StreamingContext context)
+        {
+            if (info == null)
+                throw new ArgumentNullException(nameof(info));
+
+            _compareInfo = (CompareInfo)info.GetValue("CompareInfo", typeof(CompareInfo));
+        }
+
+        public void GetObjectData(SerializationInfo info, StreamingContext context)
+        {
+            if (info == null)
+                throw new ArgumentNullException(nameof(info));
+
+            info.AddValue("CompareInfo", _compareInfo);
         }
 
-        // Compares two Objects by calling CompareTo.  If a == 
-        // b,0 is returned.  If a implements 
-        // IComparable, a.CompareTo(b) is returned.  If a 
-        // doesn't implement IComparable and b does, 
-        // -(b.CompareTo(a)) is returned, otherwise an 
-        // exception is thrown.
+        // Compares two Objects by calling CompareTo.
+        // If a == b, 0 is returned.
+        // If a implements IComparable, a.CompareTo(b) is returned.
+        // If a doesn't implement IComparable and b does, -(b.CompareTo(a)) is returned.
+        // Otherwise an exception is thrown.
         // 
         public int Compare(Object a, Object b)
         {
             if (a == b) return 0;
             if (a == null) return -1;
             if (b == null) return 1;
-            if (m_compareInfo != null)
-            {
-                String sa = a as String;
-                String sb = b as String;
-                if (sa != null && sb != null)
-                    return m_compareInfo.Compare(sa, sb);
-            }
+
+            string sa = a as string;
+            string sb = b as string;
+            if (sa != null && sb != null)
+                return _compareInfo.Compare(sa, sb);
 
             IComparable ia = a as IComparable;
             if (ia != null)
index ef44fef..72f62c2 100644 (file)
@@ -11,10 +11,10 @@ namespace System.Collections.Generic
     // keeps the performance not affected till we hit collision threshold and then we switch to the comparer which is using 
     // randomized string hashing.
     [Serializable] // Required for compatibility with .NET Core 2.0 as we exposed the NonRandomizedStringEqualityComparer inside the serialization blob
-#if CORECLR
-    internal
-#else
+#if CORERT
     public
+#else
+    internal
 #endif
     sealed class NonRandomizedStringEqualityComparer : EqualityComparer<string>, ISerializable
     {
index c38e7a2..d3c3aac 100644 (file)
@@ -24,14 +24,6 @@ using System.Text;
 
 namespace System.Globalization
 {
-#if CORECLR
-    using StringStringDictionary = Dictionary<string, string>;
-    using StringList = List<string>;
-#else
-    using StringStringDictionary = LowLevelDictionary<string, string>;
-    using StringList = LowLevelList<string>;
-#endif
-
     //
     // from LocaleEx.txt header
     //
@@ -121,17 +113,17 @@ namespace System.Globalization
         internal const String CJKSecondSuff = "\u79d2";
 
         // The collection fo date words & postfix.
-        internal StringList m_dateWords = new StringList();
+        internal List<string> m_dateWords = new List<string>();
         // Hashtable for the known words.
-        private static volatile StringStringDictionary s_knownWords;
+        private static volatile Dictionary<string, string> s_knownWords;
 
-        static StringStringDictionary KnownWords
+        static Dictionary<string, string> KnownWords
         {
             get
             {
                 if (s_knownWords == null)
                 {
-                    StringStringDictionary temp = new StringStringDictionary();
+                    Dictionary<string, string> temp = new Dictionary<string, string>();
                     // Add known words into the hash table.
 
                     // Skip these special symbols.                        
@@ -234,7 +226,7 @@ namespace System.Globalization
                 {
                     if (m_dateWords == null)
                     {
-                        m_dateWords = new StringList();
+                        m_dateWords = new List<string>();
                     }
                     if (formatPostfix == "MMMM")
                     {
@@ -380,7 +372,7 @@ namespace System.Globalization
             if (m_dateWords == null)
             {
                 // Create the date word array.
-                m_dateWords = new StringList();
+                m_dateWords = new List<string>();
             }
             // Add the ignorable symbol into the ArrayList.
             String temp = IgnorableSymbolChar + text;
@@ -735,4 +727,3 @@ namespace System.Globalization
         }
     }
 }
-
@@ -117,6 +117,10 @@ namespace System.Runtime.CompilerServices
 
             private static Action OutputCorrelationEtwEvent(Action continuation)
             {
+#if CORERT
+                // TODO
+                return continuation;
+#else
                 int continuationId = Task.NewId();
                 Task currentTask = Task.InternalCurrent;
                 // fire the correlation ETW event
@@ -141,7 +145,8 @@ namespace System.Runtime.CompilerServices
                         EventSource.SetCurrentThreadActivityId(prevActivityId);
 
                     etwLog.TaskWaitContinuationComplete(((Task<int>)continuationIdTask).Result);
-                }, Task.FromResult(continuationId)); // pass the ID in a task to avoid a closure
+                }, Task.FromResult(continuationId)); // pass the ID in a task to avoid a closure\
+#endif
             }
 
             /// <summary>WaitCallback that invokes the Action supplied as object state.</summary>
index f700678..bb6e8f9 100644 (file)
@@ -734,30 +734,14 @@ namespace System.Globalization
                 {
                     // Since CompareInfo's don't have any overrideable properties, get the CompareInfo from
                     // the Non-Overridden CultureInfo so that we only create one CompareInfo per culture
-                    CompareInfo temp = UseUserOverride
+                    this.compareInfo = UseUserOverride
                                         ? GetCultureInfo(this._name).CompareInfo
                                         : new CompareInfo(this);
-                    if (OkayToCacheClassWithCompatibilityBehavior)
-                    {
-                        this.compareInfo = temp;
-                    }
-                    else
-                    {
-                        return temp;
-                    }
                 }
                 return (compareInfo);
             }
         }
 
-        private static bool OkayToCacheClassWithCompatibilityBehavior
-        {
-            get
-            {
-                return true;
-            }
-        }
-
         ////////////////////////////////////////////////////////////////////////
         //
         //  TextInfo
@@ -774,15 +758,7 @@ namespace System.Globalization
                     // Make a new textInfo
                     TextInfo tempTextInfo = new TextInfo(_cultureData);
                     tempTextInfo.SetReadOnlyState(_isReadOnly);
-
-                    if (OkayToCacheClassWithCompatibilityBehavior)
-                    {
-                        textInfo = tempTextInfo;
-                    }
-                    else
-                    {
-                        return tempTextInfo;
-                    }
+                    textInfo = tempTextInfo;
                 }
                 return (textInfo);
             }