Skip to content

Commit

Permalink
Add NetFabric.Hyperlinq.Immutable project (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Mar 5, 2021
1 parent 89c364f commit c65f579
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 14 deletions.
56 changes: 56 additions & 0 deletions NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<PackageId>NetFabric.Hyperlinq.Immutable</PackageId>
<Title>NetFabric.Hyperlinq.Immutable</Title>
<Description> High performance LINQ implementation with minimal heap allocations. Supports all collections in System.Collections.Immutable.</Description>
<Version>1.0.0-beta01</Version>
<PackageIcon>Icon.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageTags>netfabric, hyperlinq, linq, enumeration, extensions, performance</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<Nullable>enable</Nullable>
<!-- <TreatWarningsAsErrors>true</TreatWarningsAsErrors> -->
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<None Include="..\Icon.png" Pack="true" PackagePath="" />
<None Include="..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NetFabric.Hyperlinq\NetFabric.Hyperlinq.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
<PackageReference Include="Nullable" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Analyzer" Version="1.0.645">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Compile Include="..\NetFabric.Hyperlinq\Conversion\AsValueEnumerable\Bindings\System\Collections\Immutable\ImmutableArrayExtensions.cs" Link="ImmutableArrayExtensions.cs" />
<Compile Include="..\NetFabric.Hyperlinq\Conversion\AsValueEnumerable\Bindings\System\Collections\Immutable\ImmutableDictionaryExtensions.cs" Link="ImmutableDictionaryExtensions.cs" />
<Compile Include="..\NetFabric.Hyperlinq\Conversion\AsValueEnumerable\Bindings\System\Collections\Immutable\ImmutableHashSetExtensions.cs" Link="ImmutableHashSetExtensions.cs" />
<Compile Include="..\NetFabric.Hyperlinq\Conversion\AsValueEnumerable\Bindings\System\Collections\Immutable\ImmutableListExtensions.cs" Link="ImmutableListExtensions.cs" />
<Compile Include="..\NetFabric.Hyperlinq\Conversion\AsValueEnumerable\Bindings\System\Collections\Immutable\ImmutableQueueExtensions.cs" Link="ImmutableQueueExtensions.cs" />
<Compile Include="..\NetFabric.Hyperlinq\Conversion\AsValueEnumerable\Bindings\System\Collections\Immutable\ImmutableSortedDictionaryExtensions.cs" Link="ImmutableSortedDictionaryExtensions.cs" />
<Compile Include="..\NetFabric.Hyperlinq\Conversion\AsValueEnumerable\Bindings\System\Collections\Immutable\ImmutableStackExtensions.cs" Link="ImmutableStackExtensions.cs" />
</ItemGroup>

</Project>
9 changes: 8 additions & 1 deletion NetFabric.Hyperlinq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
coverlet.runsettings = coverlet.runsettings
Directory.Build.props = Directory.Build.props
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
global.json = global.json
Icon.png = Icon.png
LICENSE = LICENSE
NuGet.config = NuGet.config
README.md = README.md
coverlet.runsettings = coverlet.runsettings
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Benchmarks", "NetFabric.Hyperlinq.Benchmarks\NetFabric.Hyperlinq.Benchmarks.csproj", "{02EE275F-6E2D-444A-AB1F-9BCD02DEA204}"
Expand All @@ -29,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.SourceG
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Abstractions", "NetFabric.Hyperlinq.Abstractions\NetFabric.Hyperlinq.Abstractions.csproj", "{6981E761-E698-437D-AF63-0E80844B7D41}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Immutable", "NetFabric.Hyperlinq.Immutable\NetFabric.Hyperlinq.Immutable.csproj", "{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,6 +62,10 @@ Global
{6981E761-E698-437D-AF63-0E80844B7D41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.Build.0 = Release|Any CPU
{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace NetFabric.Hyperlinq
{
public static class ListBindings
public static partial class ListExtensions
{
// List<TSource> is simply converted to ArraySegment<TSource> and share its IValueEnumerable<TSource> wrapper.
// It's not converted to ReadOnlySpan<TSource> because its enumerables cannot be casted to IEnumerable<TSource>, restricting its use.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Immutable;
using System.Net.Http.Headers;
using System.Runtime.CompilerServices;

namespace NetFabric.Hyperlinq
Expand Down
6 changes: 0 additions & 6 deletions NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,4 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Folder Include="Filtering\Where" />
<Folder Include="Filtering\WhereSelect" />
<Folder Include="Projection\Select" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions NetFabric.Hyperlinq/Utils/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

namespace NetFabric.Hyperlinq
{
static class ListExtensions
public static partial class ListExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ArraySegment<TSource> AsArraySegment<TSource>(this List<TSource> source)
internal static ArraySegment<TSource> AsArraySegment<TSource>(this List<TSource> source)
=> new(source.GetItems(), 0, source.Count);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<TSource> AsSpan<TSource>(this List<TSource> source)
internal static Span<TSource> AsSpan<TSource>(this List<TSource> source)
#if NET5_0_OR_GREATER
=> CollectionsMarshal.AsSpan(source);
#else
=> source.GetItems().AsSpan().Slice(0, source.Count);
#endif

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Memory<TSource> AsMemory<TSource>(this List<TSource> source)
internal static Memory<TSource> AsMemory<TSource>(this List<TSource> source)
=> source.GetItems().AsMemory().Slice(0, source.Count);


public static List<TSource> AsList<TSource>(this TSource[] source)
internal static List<TSource> AsList<TSource>(this TSource[] source)
{
var result = new List<TSource>();
var layout = Unsafe.As<List<TSource>, ListLayout<TSource>>(ref result);
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public static void Example(IReadOnlyList<int> list)
}
```

- `Netfabric.Hyperlinq` contains special versions of `AsValueEnumerable()` for better performance with all collections in the `System.Collections.Immutable` namespace. Projects targetting .NET Framework, `netcoreapp2.1` or `netstandard2.0`, require the addition of the [`NetFabric.Hyperlinq.Immutable` NuGet package](https://www.nuget.org/packages/NetFabric.Hyperlinq.Immutable/) dependency.

- All enumerables returned by `NetFabric.Hyperlinq` are compatible with `System.Linq`.

`OrderByDescending()` is not yet available in `Netfabric.Hyperlinq` but can still be used without requiring any conversion:
Expand Down

0 comments on commit c65f579

Please sign in to comment.