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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private FlatArray(T[] items, int _)
// the caller MUST ensure the length is GREATER than zero
//
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal FlatArray(int length, T[] items)
private FlatArray(int length, T[] items)
{
Debug.Assert(items is not null);
Debug.Assert(length > 0 && length <= items.Length);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace System;

partial struct FlatArray<T>
{
// Initializes an instance without creation of a defensive copy
// When the input array is empty, the default is returned
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static FlatArray<T> InternalCreateOrDefault(T[] items)
{
Debug.Assert(items is not null);

if (items.Length == default)
{
return default;
}

return new(items, default);
}
}
2 changes: 1 addition & 1 deletion src/flatcollections-array/FlatArray/FlatArray.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Description>PrimeFuncPack Core.FlatArray is a core library for .NET consisting of immutable FlatArray targeted for use in functional programming.</Description>
<RootNamespace>System</RootNamespace>
<AssemblyName>PrimeFuncPack.Core.FlatArray</AssemblyName>
<Version>1.6.0-preview.1</Version>
<Version>1.6.0-rc.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separator, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}

public static FlatArray<string> SplitToFlatArray(
Expand All @@ -28,11 +24,7 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separator, count, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separators, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}

public static FlatArray<string> SplitToFlatArray(
Expand All @@ -28,11 +24,7 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separators, count, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separator, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}

public static FlatArray<string> SplitToFlatArray(
Expand All @@ -28,11 +24,7 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separator, count, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separators, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}

public static FlatArray<string> SplitToFlatArray(
Expand All @@ -28,11 +24,7 @@ public static FlatArray<string> SplitToFlatArray(
}

var array = source.Split(separators, count, options);
if (array.Length is 0)
{
return default;
}

return new(array.Length, array);
return FlatArray<string>.InternalCreateOrDefault(array);
}
}
2 changes: 1 addition & 1 deletion src/flatcollections/FlatCollections/FlatCollections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Description>PrimeFuncPack Core.FlatCollections is a set of immutable Flat collections for .NET designed for developing business applications based on functional programming.</Description>
<RootNamespace>System</RootNamespace>
<AssemblyName>PrimeFuncPack.Core.FlatCollections</AssemblyName>
<Version>1.6.0-preview.1</Version>
<Version>1.6.0-rc.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down