using System; using System.Runtime.CompilerServices; namespace MoonTools.ECS { public ref struct ReverseSpanEnumerator { private ReadOnlySpan Span; private int index; public ReverseSpanEnumerator GetEnumerator() => this; public T Current => Span[index]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { if (index > 0) { index -= 1; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReverseSpanEnumerator(Span span) { Span = span; index = span.Length; } public static ReverseSpanEnumerator Empty => new ReverseSpanEnumerator(); } }