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

System.Text.Encodings.Web refactoring and code modernization #49373

Merged
merged 13 commits into from
Mar 19, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix broken tests & x86 edge case detection
- Update test csproj to include missing polyfills
- Fix net461 test compilation failures
GrabYourPitchforks committed Mar 10, 2021
commit ee279d43eff0f1dc1984fd65d15b116cbec98e1b
Original file line number Diff line number Diff line change
@@ -239,10 +239,11 @@ public static bool TryWriteUInt64LittleEndian(Span<byte> span, int offset, ulong
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool AreValidIndexAndLength(int spanRealLength, int requestedOffset, int requestedLength)
{
// Logic here is copied from Span<T>.Slice.
if (IntPtr.Size == 4)
{
if ((uint)requestedOffset > (uint)spanRealLength) { return false; }
if ((uint)(spanRealLength - requestedLength) > (uint)requestedOffset) { return false; }
if ((uint)requestedLength > (uint)(spanRealLength - requestedOffset)) { return false; }
}
else
{
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public void Allow_Forbid_ZigZag()
{
// Arrange - we'll use BoundedMemory in this test to guard against
// out-of-bounds accesses on the bitmap instance.
var boundedMem = BoundedMemory.Allocate<AllowedBmpCodePointsBitmap>(1);
using var boundedMem = BoundedMemory.Allocate<AllowedBmpCodePointsBitmap>(1);
boundedMem.Span.Clear();
ref var bitmap = ref boundedMem.Span[0];

@@ -112,7 +112,7 @@ public void IsCodePointAllowed_NonBmpCodePoints_ReturnsFalse()
{
// Arrange - we'll use BoundedMemory in this test to guard against
// out-of-bounds accesses on the bitmap instance.
var boundedMem = BoundedMemory.Allocate<AllowedBmpCodePointsBitmap>(1);
using var boundedMem = BoundedMemory.Allocate<AllowedBmpCodePointsBitmap>(1);
ref var bitmap = ref boundedMem.Span[0];

Assert.False(bitmap.IsCodePointAllowed(0x10000)); // start of supplementary plane
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public void MapEntries_ZigZag()
{
// Arrange - we'll use BoundedMemory in this test to guard against
// out-of-bounds accesses on the byte map instance.
var boundedMem = BoundedMemory.Allocate<AsciiByteMap>(1);
using var boundedMem = BoundedMemory.Allocate<AsciiByteMap>(1);
boundedMem.Span.Clear();
ref var byteMap = ref boundedMem.Span[0];

@@ -62,7 +62,7 @@ public void TryLookup_NonAsciiCodePoints_ReturnsFalse()
{
// Arrange - we'll use BoundedMemory in this test to guard against
// out-of-bounds accesses on the bitmap instance.
var boundedMem = BoundedMemory.Allocate<AsciiByteMap>(1);
using var boundedMem = BoundedMemory.Allocate<AsciiByteMap>(1);
ref var byteMap = ref boundedMem.Span[0];

Assert.False(byteMap.TryLookup(new Rune(128), out _)); // start of non-ASCII
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Compile Include="..\src\Polyfills\System.Text.Rune.netstandard20.cs" Link="Polyfills\System.Text.Rune.netstandard20.cs" />
<Compile Include="..\src\System\Text\Encodings\Web\ThrowHelper.cs" Link="System\Text\Encodings\Web\ThrowHelper.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Private.Runtime.UnicodeData" Version="$(SystemPrivateRuntimeUnicodeDataVersion)" ExcludeAssets="contentFiles" GeneratePathProperty="true" />
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ namespace System.Text.Unicode
{
internal static class UnicodeTestHelpers
{
private static Lazy<StrongBox<AllowedBmpCodePointsBitmap>> _lazyBitmap = new Lazy<StrongBox<AllowedBmpCodePointsBitmap>>(InitializeLazyBitmap());
private static Lazy<StrongBox<AllowedBmpCodePointsBitmap>> _lazyBitmap = new Lazy<StrongBox<AllowedBmpCodePointsBitmap>>(InitializeLazyBitmap);

/// <summary>
/// Returns a value stating whether a character is defined per the checked-in version