Add SpanToRef.GetOrNull

wip/no-type-lookup
copygirl 2 years ago
parent 46e171940e
commit 6bc3ab8bfb
  1. 3
      src/gaemstone.ECS/Iterator.cs
  2. 2
      src/gaemstone.Utility/SpanExtensions.cs

@ -144,7 +144,8 @@ public unsafe class Iterator
public static SpanToRef<T> Empty => default; public static SpanToRef<T> Empty => default;
private readonly Span<ReferenceHandle> _span; private readonly Span<ReferenceHandle> _span;
public int Length => _span.Length; public int Length => _span.Length;
public T? this[int index] => (T?)_span[index].Target; public T this[int index] => (T)_span[index].Target!;
public T? GetOrNull(int index) => ((index >= 0) && (index < Length)) ? this[index] : null;
internal SpanToRef(Span<ReferenceHandle> span) => _span = span; internal SpanToRef(Span<ReferenceHandle> span) => _span = span;
} }
} }

@ -7,7 +7,7 @@ public static class SpanExtensions
public static T? GetOrNull<T>(this Span<T> span, int index) public static T? GetOrNull<T>(this Span<T> span, int index)
where T : struct => GetOrNull((ReadOnlySpan<T>)span, index); where T : struct => GetOrNull((ReadOnlySpan<T>)span, index);
public static T? GetOrNull<T>(this ReadOnlySpan<T> span, int index) public static T? GetOrNull<T>(this ReadOnlySpan<T> span, int index)
where T : struct => (index >= 0 && index < span.Length) ? span[index] : null; where T : struct => ((index >= 0) && (index < span.Length)) ? span[index] : null;
public static ReadOnlySpanSplitEnumerator<T> Split<T>(this ReadOnlySpan<T> span, T splitOn) public static ReadOnlySpanSplitEnumerator<T> Split<T>(this ReadOnlySpan<T> span, T splitOn)

Loading…
Cancel
Save