Skip to content
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ foreach (ref readonly HeavyStruct s in view)
{
...
}

```
## Changelog

Expand All @@ -68,4 +69,6 @@ foreach (ref readonly HeavyStruct s in view)
Bug reports and contributions are welcome.

## License
This package is released as open source under the **MIT License**. See the [LICENSE](LICENSE) file for more details.
This package is released as open source under the **MIT License**.

See the [LICENSE](LICENSE) file for more details.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Ramstack.Collections;
namespace Ramstack.Collections;

[TestFixture]
public class ArrayViewExtensionsTests
Expand Down
2 changes: 0 additions & 2 deletions Ramstack.Structures.Tests/Collections/ArrayViewTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Ramstack.Collections;

Expand Down
3 changes: 0 additions & 3 deletions Ramstack.Structures.Tests/Collections/ReadOnlyArrayTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Ramstack.Collections;

Expand Down
12 changes: 9 additions & 3 deletions Ramstack.Structures.Tests/Ramstack.Structures.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
<ItemGroup>
<Using Include="NUnit" />
<Using Include="NUnit.Framework" />
<Using Include="System.ComponentModel" />
<Using Include="System.Diagnostics" />
<Using Include="System.Diagnostics.CodeAnalysis" />
<Using Include="System.Globalization" />
<Using Include="System.Runtime.CompilerServices" />
<Using Include="System.Runtime.InteropServices" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions Ramstack.Structures.Tests/Text/StringViewComparerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Globalization;

namespace Ramstack.Text;

[TestFixture]
Expand Down
4 changes: 0 additions & 4 deletions Ramstack.Structures.Tests/Text/StringViewTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace Ramstack.Text;

[TestFixture]
Expand Down
2 changes: 0 additions & 2 deletions Ramstack.Structures/Collections/ArrayViewDebugView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Diagnostics;

namespace Ramstack.Collections;

/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions Ramstack.Structures/Collections/ArrayViewExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;

namespace Ramstack.Collections;

/// <summary>
Expand Down Expand Up @@ -150,10 +148,10 @@ public static ArrayView<T> AsView<T>(this List<T>? list)
{
if (list is not null)
{
var count = list.Count;
var array = ListAccessor<T>.GetBuffer(list);
var count = Math.Min(list.Count, array.Length);

return new ArrayView<T>(array, 0, Math.Min(count, array.Length));
return new ArrayView<T>(array, 0, count);
}

return ArrayView<T>.Empty;
Expand Down
3 changes: 0 additions & 3 deletions Ramstack.Structures/Collections/ArrayView`1.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Collections;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using Ramstack.Internal;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Immutable;
using System.Runtime.InteropServices;

namespace Ramstack.Collections;

Expand Down
2 changes: 0 additions & 2 deletions Ramstack.Structures/Collections/ReadOnlyArray.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using JetBrains.Annotations;

namespace Ramstack.Collections;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Runtime.CompilerServices;

using JetBrains.Annotations;

namespace Ramstack.Collections;

public static partial class ReadOnlyArrayExtensions
Expand Down
4 changes: 0 additions & 4 deletions Ramstack.Structures/Collections/ReadOnlyArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

using JetBrains.Annotations;

namespace Ramstack.Collections;

Expand Down
10 changes: 4 additions & 6 deletions Ramstack.Structures/Collections/ReadOnlyArray`1.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System.Collections;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Ramstack.Collections;

Expand Down Expand Up @@ -105,8 +101,10 @@ public ReadOnlyArray(T item1, T item2, T item3, T item4) =>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ReadOnlyArray(ReadOnlySpan<T> items)
{
//
// Avoid address exposure in cases where the destination local does not actually end up escaping in any way.
// https://github.com/dotnet/runtime/pull/102808
//

// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (items.Length != 0)
Expand Down Expand Up @@ -306,8 +304,10 @@ public static explicit operator ReadOnlyArray<T>(T[]? array) =>
/// A read-only array.
/// </returns>
public static implicit operator ReadOnlyArray<T>(ImmutableArray<T> array) =>
//
// https://github.com/dotnet/runtime/issues/83141#issuecomment-1460324087
// Unsafe.As<ImmutableArray<T>, ReadOnlyArray<T>>(ref array);
//
new(ImmutableCollectionsMarshal.AsArray(array)!);

/// <summary>
Expand All @@ -318,8 +318,6 @@ public static implicit operator ReadOnlyArray<T>(ImmutableArray<T> array) =>
/// A read-only array.
/// </returns>
public static implicit operator ImmutableArray<T>(ReadOnlyArray<T> array) =>
// https://github.com/dotnet/runtime/issues/83141#issuecomment-1460324087
// Unsafe.As<ReadOnlyArray<T>, ImmutableArray<T>>(ref array);
ImmutableCollectionsMarshal.AsImmutableArray(array.Inner);

/// <summary>
Expand Down
3 changes: 0 additions & 3 deletions Ramstack.Structures/Internal/JitHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Ramstack.Internal;

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions Ramstack.Structures/Internal/ThrowHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Diagnostics.CodeAnalysis;

namespace Ramstack.Internal;

internal static class ThrowHelper
Expand Down
12 changes: 11 additions & 1 deletion Ramstack.Structures/Ramstack.Structures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ Ramstack.Collections.ReadOnlyArray&lt;T&gt;</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<Using Include="System.ComponentModel" />
<Using Include="System.Diagnostics" />
<Using Include="System.Diagnostics.CodeAnalysis" />
<Using Include="System.Globalization" />
<Using Include="System.Runtime.CompilerServices" />
<Using Include="System.Runtime.InteropServices" />
<Using Include="JetBrains.Annotations" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MinVer" Version="5.0.0">
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 0 additions & 5 deletions Ramstack.Structures/Text/StringView.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using Ramstack.Internal;

namespace Ramstack.Text;
Expand Down
2 changes: 0 additions & 2 deletions Ramstack.Structures/Text/StringViewComparer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Globalization;

namespace Ramstack.Text;

/// <summary>
Expand Down