Skip to content

Commit

Permalink
Remove ImmutableArray integration
Browse files Browse the repository at this point in the history
  • Loading branch information
badeend committed Apr 4, 2024
1 parent 2a95561 commit a7e232f
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Xunit;

Expand Down
16 changes: 0 additions & 16 deletions Badeend.ValueCollections.Tests/ValueListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,6 @@ public void HashCode()
Assert.True(hashCodes.Count() == hashCodes.Distinct().Count());
}

/// <summary>
/// FYI, this is not something we publicly promise, but we test for it anyways.
/// </summary>
[Fact]
public void ImmutableArrayRoundtrip()
{
int[] unsafeItems = [1, 2, 3, 4];

var list = ValueCollectionsMarshal.AsValueList(unsafeItems)
.ToImmutableArray()
.AsValueList();

unsafeItems[1] = 42;
Assert.True(list[1] == 42);
}

[Fact]
public void MarshalAsValueList()
{
Expand Down
16 changes: 0 additions & 16 deletions Badeend.ValueCollections.Tests/ValueSliceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,6 @@ public void HashCode()
Assert.True(hashCodes.Count() == hashCodes.Distinct().Count());
}

/// <summary>
/// FYI, this is not something we publicly promise, but we test for it anyways.
/// </summary>
[Fact]
public void ImmutableArrayRoundtrip()
{
int[] unsafeItems = [1, 2, 3, 4];

var slice = ValueCollectionsMarshal.AsValueSlice(unsafeItems)
.ToImmutableArray()
.AsValueSlice();

unsafeItems[1] = 42;
Assert.True(slice[1] == 42);
}

[Fact]
public void MarshalAsValueSlice()
{
Expand Down
1 change: 0 additions & 1 deletion Badeend.ValueCollections/Badeend.ValueCollections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="System.Collections.Immutable" Version="1.2.0" />
<PackageReference Include="System.Memory" Version="4.5.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.0" Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netcoreapp2.1'" />
</ItemGroup>
Expand Down
13 changes: 0 additions & 13 deletions Badeend.ValueCollections/UnsafeHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -33,18 +32,6 @@ private static void PlatformAssert(bool condition)
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static T[] AsArray<T>(ImmutableArray<T> items)
{
return Unsafe.As<ImmutableArray<T>, T[]>(ref items);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ImmutableArray<T> AsImmutableArray<T>(T[] items)
{
return Unsafe.As<T[], ImmutableArray<T>>(ref items);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Span<T> AsSpan<T>(List<T> items)
{
Expand Down
24 changes: 0 additions & 24 deletions Badeend.ValueCollections/ValueCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Immutable;
using System.ComponentModel;
using System.Runtime.CompilerServices;

Expand All @@ -9,29 +8,6 @@ namespace Badeend.ValueCollections;
/// </summary>
public static class ValueCollectionExtensions
{
/// <summary>
/// Reinterpret the <see cref="ImmutableArray{T}"/> as a <see cref="ValueSlice{T}"/>.
/// This does not allocate any memory.
/// </summary>
public static ValueSlice<T> AsValueSlice<T>(this ImmutableArray<T> items) => new(UnsafeHelpers.AsArray(items));

/// <summary>
/// Create a new <see cref="ValueList{T}"/> that reuses the backing allocation
/// of the <see cref="ImmutableArray{T}"/>.
///
/// This method allocates a new fixed-size ValueList instance. The items
/// are not copied.
/// </summary>
public static ValueList<T> AsValueList<T>(this ImmutableArray<T> items) => ValueList<T>.FromArrayUnsafe(UnsafeHelpers.AsArray(items));

/// <summary>
/// Copy the <paramref name="items"/> into a new <see cref="ValueList{T}"/>.
/// </summary>
[Obsolete("Use .AsValueList() instead.")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static ValueList<T> ToValueList<T>(this ImmutableArray<T> items) => ValueList<T>.FromArrayUnsafe(items.ToArray());

/// <summary>
/// Copy the <paramref name="items"/> into a new <see cref="ValueList{T}"/>.
/// </summary>
Expand Down
6 changes: 0 additions & 6 deletions Badeend.ValueCollections/ValueList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down Expand Up @@ -225,11 +224,6 @@ internal static ValueList<T> FromArrayUnsafe(T[] items, int count)
/// </summary>
public bool TryCopyTo(Span<T> destination) => this.AsValueSlice().TryCopyTo(destination);

/// <summary>
/// Copy the list into a new <see cref="ImmutableArray{T}"/>.
/// </summary>
public ImmutableArray<T> ToImmutableArray() => this.AsValueSlice().ToImmutableArray();

/// <summary>
/// Create a new <see cref="ValueListBuilder{T}"/> with this list as its
/// initial content. This builder can then be used to efficiently construct
Expand Down
22 changes: 0 additions & 22 deletions Badeend.ValueCollections/ValueSlice.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -217,27 +216,6 @@ public ValueList<T> ToValueList()
return ValueList<T>.FromArrayUnsafe(this.ToArray());
}

/// <summary>
/// Copy the slice into a new <see cref="ImmutableArray{T}"/>.
/// </summary>
public ImmutableArray<T> ToImmutableArray()
{
if (this.items is null)
{
return ImmutableArray<T>.Empty;
}
else if (this.length == this.items.Length)
{
Debug.Assert(this.offset == 0);

return UnsafeHelpers.AsImmutableArray(this.items);
}
else
{
return ImmutableArray.Create(this.items, this.offset, this.length);
}
}

/// <summary>
/// Copy the contents of the slice into a new array.
///
Expand Down

0 comments on commit a7e232f

Please sign in to comment.