Skip to content

Commit

Permalink
Replace the bespoke OrderedDictionary with a backport of System.Colle…
Browse files Browse the repository at this point in the history
…ctions.Generic.OrderedDictionary (#105016)

* Replace the bespoke OrderedDictionary with a backport of System.Collections.Generic.OrderedDictionary.

* Address feedback
  • Loading branch information
eiriktsarpalis authored Jul 18, 2024
1 parent 9cbd699 commit a5c0dec
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 551 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;

namespace System.Collections.Generic
{
/// <summary>
Expand All @@ -25,6 +27,11 @@ internal static IEnumerator<T> GetEmptyEnumerator<T>() =>
/// </returns>
internal static T[] ToArray<T>(IEnumerable<T> source, out int length)
{
// Copied from Array.MaxLength in System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Array.cs
const int ArrayMaxLength = 0X7FFFFFC7;
#if NET6_0_OR_GREATER
Debug.Assert(Array.MaxLength == ArrayMaxLength);
#endif
if (source is ICollection<T> ic)
{
int count = ic.Count;
Expand Down Expand Up @@ -64,9 +71,9 @@ internal static T[] ToArray<T>(IEnumerable<T> source, out int length)
// constrain the length to be Array.MaxLength (this overflow check works because of the
// cast to uint).
int newLength = count << 1;
if ((uint)newLength > Array.MaxLength)
if ((uint)newLength > ArrayMaxLength)
{
newLength = Array.MaxLength <= count ? count + 1 : Array.MaxLength;
newLength = ArrayMaxLength <= count ? count + 1 : ArrayMaxLength;
}

Array.Resize(ref arr, newLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<ContractTypesPartiallyMoved>true</ContractTypesPartiallyMoved>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<DefineConstants>SYSTEM_COLLECTIONS;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit a5c0dec

Please sign in to comment.