From a7e232f4f48cf7ac72611873079cf6e13898ca4f Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 4 Apr 2024 23:05:56 +0200 Subject: [PATCH] Remove ImmutableArray integration --- .../Badeend.ValueCollections.Tests.csproj | 1 - .../Reference/ValueList.Tests.IndexOf.cs | 1 - .../ValueListTests.cs | 16 ------------- .../ValueSliceTests.cs | 16 ------------- .../Badeend.ValueCollections.csproj | 1 - Badeend.ValueCollections/UnsafeHelpers.cs | 13 ---------- .../ValueCollectionExtensions.cs | 24 ------------------- Badeend.ValueCollections/ValueList.cs | 6 ----- Badeend.ValueCollections/ValueSlice.cs | 22 ----------------- 9 files changed, 100 deletions(-) diff --git a/Badeend.ValueCollections.Tests/Badeend.ValueCollections.Tests.csproj b/Badeend.ValueCollections.Tests/Badeend.ValueCollections.Tests.csproj index ea7da46..adb0584 100644 --- a/Badeend.ValueCollections.Tests/Badeend.ValueCollections.Tests.csproj +++ b/Badeend.ValueCollections.Tests/Badeend.ValueCollections.Tests.csproj @@ -15,7 +15,6 @@ - runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Badeend.ValueCollections.Tests/Reference/ValueList.Tests.IndexOf.cs b/Badeend.ValueCollections.Tests/Reference/ValueList.Tests.IndexOf.cs index 139f29a..9e26995 100644 --- a/Badeend.ValueCollections.Tests/Reference/ValueList.Tests.IndexOf.cs +++ b/Badeend.ValueCollections.Tests/Reference/ValueList.Tests.IndexOf.cs @@ -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; diff --git a/Badeend.ValueCollections.Tests/ValueListTests.cs b/Badeend.ValueCollections.Tests/ValueListTests.cs index 4b83329..2885885 100644 --- a/Badeend.ValueCollections.Tests/ValueListTests.cs +++ b/Badeend.ValueCollections.Tests/ValueListTests.cs @@ -118,22 +118,6 @@ public void HashCode() Assert.True(hashCodes.Count() == hashCodes.Distinct().Count()); } - /// - /// FYI, this is not something we publicly promise, but we test for it anyways. - /// - [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() { diff --git a/Badeend.ValueCollections.Tests/ValueSliceTests.cs b/Badeend.ValueCollections.Tests/ValueSliceTests.cs index cfd25da..f7a7f78 100644 --- a/Badeend.ValueCollections.Tests/ValueSliceTests.cs +++ b/Badeend.ValueCollections.Tests/ValueSliceTests.cs @@ -164,22 +164,6 @@ public void HashCode() Assert.True(hashCodes.Count() == hashCodes.Distinct().Count()); } - /// - /// FYI, this is not something we publicly promise, but we test for it anyways. - /// - [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() { diff --git a/Badeend.ValueCollections/Badeend.ValueCollections.csproj b/Badeend.ValueCollections/Badeend.ValueCollections.csproj index fd792b6..da24a5a 100644 --- a/Badeend.ValueCollections/Badeend.ValueCollections.csproj +++ b/Badeend.ValueCollections/Badeend.ValueCollections.csproj @@ -6,7 +6,6 @@ - diff --git a/Badeend.ValueCollections/UnsafeHelpers.cs b/Badeend.ValueCollections/UnsafeHelpers.cs index 990577e..dbe9136 100644 --- a/Badeend.ValueCollections/UnsafeHelpers.cs +++ b/Badeend.ValueCollections/UnsafeHelpers.cs @@ -1,4 +1,3 @@ -using System.Collections.Immutable; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -33,18 +32,6 @@ private static void PlatformAssert(bool condition) } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static T[] AsArray(ImmutableArray items) - { - return Unsafe.As, T[]>(ref items); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ImmutableArray AsImmutableArray(T[] items) - { - return Unsafe.As>(ref items); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Span AsSpan(List items) { diff --git a/Badeend.ValueCollections/ValueCollectionExtensions.cs b/Badeend.ValueCollections/ValueCollectionExtensions.cs index bb9079e..bf576b2 100644 --- a/Badeend.ValueCollections/ValueCollectionExtensions.cs +++ b/Badeend.ValueCollections/ValueCollectionExtensions.cs @@ -1,4 +1,3 @@ -using System.Collections.Immutable; using System.ComponentModel; using System.Runtime.CompilerServices; @@ -9,29 +8,6 @@ namespace Badeend.ValueCollections; /// public static class ValueCollectionExtensions { - /// - /// Reinterpret the as a . - /// This does not allocate any memory. - /// - public static ValueSlice AsValueSlice(this ImmutableArray items) => new(UnsafeHelpers.AsArray(items)); - - /// - /// Create a new that reuses the backing allocation - /// of the . - /// - /// This method allocates a new fixed-size ValueList instance. The items - /// are not copied. - /// - public static ValueList AsValueList(this ImmutableArray items) => ValueList.FromArrayUnsafe(UnsafeHelpers.AsArray(items)); - - /// - /// Copy the into a new . - /// - [Obsolete("Use .AsValueList() instead.")] - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public static ValueList ToValueList(this ImmutableArray items) => ValueList.FromArrayUnsafe(items.ToArray()); - /// /// Copy the into a new . /// diff --git a/Badeend.ValueCollections/ValueList.cs b/Badeend.ValueCollections/ValueList.cs index dd38fd3..9a1e2c5 100644 --- a/Badeend.ValueCollections/ValueList.cs +++ b/Badeend.ValueCollections/ValueList.cs @@ -1,5 +1,4 @@ using System.Collections; -using System.Collections.Immutable; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Text; @@ -225,11 +224,6 @@ internal static ValueList FromArrayUnsafe(T[] items, int count) /// public bool TryCopyTo(Span destination) => this.AsValueSlice().TryCopyTo(destination); - /// - /// Copy the list into a new . - /// - public ImmutableArray ToImmutableArray() => this.AsValueSlice().ToImmutableArray(); - /// /// Create a new with this list as its /// initial content. This builder can then be used to efficiently construct diff --git a/Badeend.ValueCollections/ValueSlice.cs b/Badeend.ValueCollections/ValueSlice.cs index e31dc41..42a2bff 100644 --- a/Badeend.ValueCollections/ValueSlice.cs +++ b/Badeend.ValueCollections/ValueSlice.cs @@ -1,5 +1,4 @@ using System.Collections; -using System.Collections.Immutable; using System.ComponentModel; using System.Diagnostics; using System.Runtime.CompilerServices; @@ -217,27 +216,6 @@ public ValueList ToValueList() return ValueList.FromArrayUnsafe(this.ToArray()); } - /// - /// Copy the slice into a new . - /// - public ImmutableArray ToImmutableArray() - { - if (this.items is null) - { - return ImmutableArray.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); - } - } - /// /// Copy the contents of the slice into a new array. ///