IntegerSequence.cs 835 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.CompilerServices;
  4. using System.Runtime.InteropServices;
  5. namespace Ryujinx.Graphics.Texture.Astc
  6. {
  7. [StructLayout(LayoutKind.Sequential, Size = IntegerEncoded.StructSize * Capacity + sizeof(int))]
  8. internal struct IntegerSequence
  9. {
  10. private const int Capacity = 100;
  11. private int _length;
  12. private IntegerEncoded _start;
  13. public Span<IntegerEncoded> List => MemoryMarshal.CreateSpan(ref _start, _length);
  14. public void Reset() => _length = 0;
  15. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  16. public void Add(ref IntegerEncoded item)
  17. {
  18. Debug.Assert(_length < Capacity);
  19. int oldLength = _length;
  20. _length++;
  21. List[oldLength] = item;
  22. }
  23. }
  24. }