Skip to content

Commit

Permalink
Add Cast method
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Jan 11, 2024
1 parent 2814b0d commit 857e815
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace System;

partial struct FlatArray<T>
{
// TODO: Add the tests and make public
internal FlatArray<TResult> Cast<TResult>()
{
if (length == default)
{
return default;
}

if (items is TResult[] resultItems)
{
return new(length, resultItems);
}

resultItems = new TResult[length];

var counter = 0;
do
{
resultItems[counter] = (TResult)(object)items![counter]!;
}
while (++counter < resultItems.Length);

return new(resultItems, default);
}
}

0 comments on commit 857e815

Please sign in to comment.