Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 2c254c4

Browse files
authored
Move types to shared corelib partition (#15768)
- YieldAwaitable: Fixed readonly mismatch - Comparer: Made public to fix https://github.com/dotnet/corefx/issues/25973
1 parent f1d8831 commit 2c254c4

File tree

7 files changed

+53
-75
lines changed

7 files changed

+53
-75
lines changed

src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\ConditionalWeakTable.cs" />
126126
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\AsyncMethodBuilder.cs" />
127127
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\TaskAwaiter.cs" />
128-
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\YieldAwaitable.cs" />
129128
</ItemGroup>
130129
<ItemGroup>
131130
<Compile Include="$(BclSourcesRoot)\System\Runtime\Reliability\CriticalFinalizerObject.cs" />
@@ -135,7 +134,6 @@
135134
<Compile Include="$(BclSourcesRoot)\System\Runtime\GcSettings.cs" />
136135
</ItemGroup>
137136
<ItemGroup>
138-
<Compile Include="$(BclSourcesRoot)\System\Collections\Comparer.cs" />
139137
<Compile Include="$(BclSourcesRoot)\System\Collections\CompatibleComparer.cs" />
140138
<Compile Include="$(BclSourcesRoot)\System\Collections\EmptyReadOnlyDictionaryInternal.cs" />
141139
<Compile Include="$(BclSourcesRoot)\System\Collections\Hashtable.cs" />

src/mscorlib/shared/System.Private.CoreLib.Shared.projitems

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Compile Include="$(MSBuildThisFileDirectory)System\Char.cs" />
5555
<Compile Include="$(MSBuildThisFileDirectory)System\CharEnumerator.cs" />
5656
<Compile Include="$(MSBuildThisFileDirectory)System\CLSCompliantAttribute.cs" />
57+
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Comparer.cs" />
5758
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\DictionaryEntry.cs" />
5859
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\Dictionary.cs" />
5960
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ICollection.cs" />
@@ -407,6 +408,7 @@
407408
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TypeForwardedToAttribute.cs" />
408409
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\UnsafeValueTypeAttribute.cs" />
409410
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ValueTaskAwaiter.cs" />
411+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\YieldAwaitable.cs" />
410412
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Cer.cs" />
411413
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Consistency.cs" />
412414
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\ReliabilityContractAttribute.cs" />

src/mscorlib/src/System/Collections/Comparer.cs renamed to src/mscorlib/shared/System/Collections/Comparer.cs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,64 @@
44

55
/*============================================================
66
**
7-
**
8-
**
9-
**
10-
**
117
** Purpose: Default IComparer implementation.
128
**
13-
**
149
===========================================================*/
1510

1611
using System.Globalization;
12+
using System.Runtime.Serialization;
1713

1814
namespace System.Collections
1915
{
20-
internal sealed class Comparer : IComparer
16+
[Serializable]
17+
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
18+
public sealed class Comparer : IComparer, ISerializable
2119
{
22-
private CompareInfo m_compareInfo;
20+
private CompareInfo _compareInfo;
21+
2322
public static readonly Comparer Default = new Comparer(CultureInfo.CurrentCulture);
2423
public static readonly Comparer DefaultInvariant = new Comparer(CultureInfo.InvariantCulture);
2524

26-
private Comparer()
27-
{
28-
m_compareInfo = null;
29-
}
30-
3125
public Comparer(CultureInfo culture)
3226
{
3327
if (culture == null)
34-
{
3528
throw new ArgumentNullException(nameof(culture));
36-
}
37-
m_compareInfo = culture.CompareInfo;
29+
30+
_compareInfo = culture.CompareInfo;
31+
}
32+
33+
private Comparer(SerializationInfo info, StreamingContext context)
34+
{
35+
if (info == null)
36+
throw new ArgumentNullException(nameof(info));
37+
38+
_compareInfo = (CompareInfo)info.GetValue("CompareInfo", typeof(CompareInfo));
39+
}
40+
41+
public void GetObjectData(SerializationInfo info, StreamingContext context)
42+
{
43+
if (info == null)
44+
throw new ArgumentNullException(nameof(info));
45+
46+
info.AddValue("CompareInfo", _compareInfo);
3847
}
3948

40-
// Compares two Objects by calling CompareTo. If a ==
41-
// b,0 is returned. If a implements
42-
// IComparable, a.CompareTo(b) is returned. If a
43-
// doesn't implement IComparable and b does,
44-
// -(b.CompareTo(a)) is returned, otherwise an
45-
// exception is thrown.
49+
// Compares two Objects by calling CompareTo.
50+
// If a == b, 0 is returned.
51+
// If a implements IComparable, a.CompareTo(b) is returned.
52+
// If a doesn't implement IComparable and b does, -(b.CompareTo(a)) is returned.
53+
// Otherwise an exception is thrown.
4654
//
4755
public int Compare(Object a, Object b)
4856
{
4957
if (a == b) return 0;
5058
if (a == null) return -1;
5159
if (b == null) return 1;
52-
if (m_compareInfo != null)
53-
{
54-
String sa = a as String;
55-
String sb = b as String;
56-
if (sa != null && sb != null)
57-
return m_compareInfo.Compare(sa, sb);
58-
}
60+
61+
string sa = a as string;
62+
string sb = b as string;
63+
if (sa != null && sb != null)
64+
return _compareInfo.Compare(sa, sb);
5965

6066
IComparable ia = a as IComparable;
6167
if (ia != null)

src/mscorlib/shared/System/Collections/Generic/NonRandomizedStringEqualityComparer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace System.Collections.Generic
1111
// keeps the performance not affected till we hit collision threshold and then we switch to the comparer which is using
1212
// randomized string hashing.
1313
[Serializable] // Required for compatibility with .NET Core 2.0 as we exposed the NonRandomizedStringEqualityComparer inside the serialization blob
14-
#if CORECLR
15-
internal
16-
#else
14+
#if CORERT
1715
public
16+
#else
17+
internal
1818
#endif
1919
sealed class NonRandomizedStringEqualityComparer : EqualityComparer<string>, ISerializable
2020
{

src/mscorlib/shared/System/Globalization/DateTimeFormatInfoScanner.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424

2525
namespace System.Globalization
2626
{
27-
#if CORECLR
28-
using StringStringDictionary = Dictionary<string, string>;
29-
using StringList = List<string>;
30-
#else
31-
using StringStringDictionary = LowLevelDictionary<string, string>;
32-
using StringList = LowLevelList<string>;
33-
#endif
34-
3527
//
3628
// from LocaleEx.txt header
3729
//
@@ -121,17 +113,17 @@ internal class DateTimeFormatInfoScanner
121113
internal const String CJKSecondSuff = "\u79d2";
122114

123115
// The collection fo date words & postfix.
124-
internal StringList m_dateWords = new StringList();
116+
internal List<string> m_dateWords = new List<string>();
125117
// Hashtable for the known words.
126-
private static volatile StringStringDictionary s_knownWords;
118+
private static volatile Dictionary<string, string> s_knownWords;
127119

128-
static StringStringDictionary KnownWords
120+
static Dictionary<string, string> KnownWords
129121
{
130122
get
131123
{
132124
if (s_knownWords == null)
133125
{
134-
StringStringDictionary temp = new StringStringDictionary();
126+
Dictionary<string, string> temp = new Dictionary<string, string>();
135127
// Add known words into the hash table.
136128

137129
// Skip these special symbols.
@@ -234,7 +226,7 @@ internal void AddDateWordOrPostfix(String formatPostfix, String str)
234226
{
235227
if (m_dateWords == null)
236228
{
237-
m_dateWords = new StringList();
229+
m_dateWords = new List<string>();
238230
}
239231
if (formatPostfix == "MMMM")
240232
{
@@ -380,7 +372,7 @@ internal void AddIgnorableSymbols(String text)
380372
if (m_dateWords == null)
381373
{
382374
// Create the date word array.
383-
m_dateWords = new StringList();
375+
m_dateWords = new List<string>();
384376
}
385377
// Add the ignorable symbol into the ArrayList.
386378
String temp = IgnorableSymbolChar + text;
@@ -735,4 +727,3 @@ private static bool ArrayElementsBeginWithDigit(string[] array)
735727
}
736728
}
737729
}
738-

src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs renamed to src/mscorlib/shared/System/Runtime/CompilerServices/YieldAwaitable.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ private static void QueueContinuation(Action continuation, bool flowContext)
117117

118118
private static Action OutputCorrelationEtwEvent(Action continuation)
119119
{
120+
#if CORERT
121+
// TODO
122+
return continuation;
123+
#else
120124
int continuationId = Task.NewId();
121125
Task currentTask = Task.InternalCurrent;
122126
// fire the correlation ETW event
@@ -141,7 +145,8 @@ private static Action OutputCorrelationEtwEvent(Action continuation)
141145
EventSource.SetCurrentThreadActivityId(prevActivityId);
142146

143147
etwLog.TaskWaitContinuationComplete(((Task<int>)continuationIdTask).Result);
144-
}, Task.FromResult(continuationId)); // pass the ID in a task to avoid a closure
148+
}, Task.FromResult(continuationId)); // pass the ID in a task to avoid a closure\
149+
#endif
145150
}
146151

147152
/// <summary>WaitCallback that invokes the Action supplied as object state.</summary>

src/mscorlib/src/System/Globalization/CultureInfo.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -734,30 +734,14 @@ public virtual CompareInfo CompareInfo
734734
{
735735
// Since CompareInfo's don't have any overrideable properties, get the CompareInfo from
736736
// the Non-Overridden CultureInfo so that we only create one CompareInfo per culture
737-
CompareInfo temp = UseUserOverride
737+
this.compareInfo = UseUserOverride
738738
? GetCultureInfo(this._name).CompareInfo
739739
: new CompareInfo(this);
740-
if (OkayToCacheClassWithCompatibilityBehavior)
741-
{
742-
this.compareInfo = temp;
743-
}
744-
else
745-
{
746-
return temp;
747-
}
748740
}
749741
return (compareInfo);
750742
}
751743
}
752744

753-
private static bool OkayToCacheClassWithCompatibilityBehavior
754-
{
755-
get
756-
{
757-
return true;
758-
}
759-
}
760-
761745
////////////////////////////////////////////////////////////////////////
762746
//
763747
// TextInfo
@@ -774,15 +758,7 @@ public virtual TextInfo TextInfo
774758
// Make a new textInfo
775759
TextInfo tempTextInfo = new TextInfo(_cultureData);
776760
tempTextInfo.SetReadOnlyState(_isReadOnly);
777-
778-
if (OkayToCacheClassWithCompatibilityBehavior)
779-
{
780-
textInfo = tempTextInfo;
781-
}
782-
else
783-
{
784-
return tempTextInfo;
785-
}
761+
textInfo = tempTextInfo;
786762
}
787763
return (textInfo);
788764
}

0 commit comments

Comments
 (0)