-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Remove CborHelpers*.cs files #126283
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
base: main
Are you sure you want to change the base?
Remove CborHelpers*.cs files #126283
Changes from all commits
41eee75
a6dcb96
ecc325d
261b58d
bcc9caa
fed9d48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Numerics; | ||
|
|
||
| /// <summary>Provides downlevel polyfills for instance methods on <see cref="BigInteger"/>.</summary> | ||
| internal static class BigIntegerPolyfills | ||
| { | ||
| extension(BigInteger self) | ||
| { | ||
| public byte[] ToByteArray(bool isUnsigned, bool isBigEndian) | ||
| { | ||
| if (isUnsigned && self.Sign < 0) | ||
| throw new OverflowException(); | ||
|
|
||
| byte[] littleEndianBytes = self.ToByteArray(); | ||
|
|
||
| if (!isUnsigned && !isBigEndian) | ||
| return littleEndianBytes; | ||
|
|
||
| int length = littleEndianBytes.Length; | ||
|
|
||
| // For unsigned, trim a single most-significant 0x00 sign-extension byte | ||
| // from the end of the little-endian array. | ||
| if (isUnsigned && length > 1 && littleEndianBytes[length - 1] == 0x00) | ||
| length--; | ||
|
|
||
| if (isBigEndian) | ||
| { | ||
| byte[] result = new byte[length]; | ||
|
|
||
| for (int i = 0; i < length; i++) | ||
| { | ||
| result[i] = littleEndianBytes[length - 1 - i]; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| if (length == littleEndianBytes.Length) | ||
| return littleEndianBytes; | ||
|
|
||
| byte[] trimmed = new byte[length]; | ||
| Array.Copy(littleEndianBytes, trimmed, length); | ||
|
|
||
| return trimmed; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Buffers.Binary; | ||
|
|
||
| /// <summary>Provides downlevel polyfills for static methods on <see cref="BinaryPrimitives"/>.</summary> | ||
| internal static class BinaryPrimitivesPolyfills | ||
| { | ||
| extension(BinaryPrimitives) | ||
| { | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static ushort ReadHalfBigEndian(ReadOnlySpan<byte> source) | ||
| { | ||
| return BitConverter.IsLittleEndian | ||
| ? BinaryPrimitives.ReverseEndianness(MemoryMarshal.Read<ushort>(source)) | ||
| : MemoryMarshal.Read<ushort>(source); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void WriteHalfBigEndian(Span<byte> destination, ushort value) | ||
| { | ||
| if (BitConverter.IsLittleEndian) | ||
| { | ||
| ushort tmp = BinaryPrimitives.ReverseEndianness(value); | ||
| MemoryMarshal.Write(destination, ref tmp); | ||
| } | ||
| else | ||
| { | ||
| MemoryMarshal.Write(destination, ref value); | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static float ReadSingleBigEndian(ReadOnlySpan<byte> source) | ||
| { | ||
| return BitConverter.IsLittleEndian | ||
| ? BitConverter.Int32BitsToSingle(BinaryPrimitives.ReverseEndianness(MemoryMarshal.Read<int>(source))) | ||
| : MemoryMarshal.Read<float>(source); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void WriteSingleBigEndian(Span<byte> destination, float value) | ||
| { | ||
| if (BitConverter.IsLittleEndian) | ||
| { | ||
| int tmp = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); | ||
| MemoryMarshal.Write(destination, ref tmp); | ||
| } | ||
| else | ||
| { | ||
| MemoryMarshal.Write(destination, ref value); | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static double ReadDoubleBigEndian(ReadOnlySpan<byte> source) | ||
| { | ||
| return BitConverter.IsLittleEndian | ||
| ? BitConverter.Int64BitsToDouble(BinaryPrimitives.ReverseEndianness(MemoryMarshal.Read<long>(source))) | ||
| : MemoryMarshal.Read<double>(source); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void WriteDoubleBigEndian(Span<byte> destination, double value) | ||
| { | ||
| if (BitConverter.IsLittleEndian) | ||
| { | ||
| long tmp = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); | ||
| MemoryMarshal.Write(destination, ref tmp); | ||
| } | ||
| else | ||
| { | ||
| MemoryMarshal.Write(destination, ref value); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System; | ||
|
|
||
| /// <summary>Provides downlevel polyfills for static methods on <see cref="decimal"/>.</summary> | ||
| internal static class DecimalPolyfills | ||
| { | ||
| extension(decimal) | ||
| { | ||
| public static void GetBits(decimal d, Span<int> destination) | ||
| { | ||
| decimal.GetBits(d).CopyTo(destination); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // 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.CodeAnalysis; | ||
|
|
||
| namespace System.Collections.Generic; | ||
|
|
||
| /// <summary>Provides downlevel polyfills for instance methods on <see cref="Stack{T}"/>.</summary> | ||
| internal static class StackPolyfills | ||
| { | ||
| extension<T>(Stack<T> stack) | ||
| { | ||
| public bool TryPop([MaybeNullWhen(false)] out T result) | ||
| { | ||
| if (stack.Count > 0) | ||
| { | ||
| result = stack.Pop(); | ||
| return true; | ||
| } | ||
|
|
||
| result = default; | ||
| return false; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,19 @@ | |
|
|
||
| public static bool Contains(this string s, char value) => | ||
| s.IndexOf(value) >= 0; | ||
|
|
||
| internal delegate void SpanAction<T, in TArg>(Span<T> span, TArg arg); | ||
|
Check failure on line 20 in src/libraries/Common/src/System/StringPolyfills.cs
|
||
|
|
||
| extension(string) | ||
| { | ||
| public static string Create<TState>(int length, TState state, SpanAction<char, TState> action) | ||
| { | ||
| char[] arr = new char[length]; | ||
| action(arr, state); | ||
|
|
||
| return new string(arr); | ||
| } | ||
|
Comment on lines
18
to
+30
|
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a lot of local-type-name collisions, but I wouldn't be surprised if we end up with some.
It'd be more defensive to do Common/src/Polyfills/System/Numerics/BigIntegerPolyfills.cs, and that better matches our file naming conventions: