Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant follows naming convention of SYSTEM_PRIVATE_CORELIB

</PropertyGroup>

<ItemGroup>
Expand Down
Loading
Loading