LiveIntervalList.cs 988 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace ARMeilleure.CodeGen.RegisterAllocators
  3. {
  4. unsafe struct LiveIntervalList
  5. {
  6. private LiveInterval* _items;
  7. private int _count;
  8. private int _capacity;
  9. public int Count => _count;
  10. public Span<LiveInterval> Span => new(_items, _count);
  11. public void Add(LiveInterval interval)
  12. {
  13. if (_count + 1 > _capacity)
  14. {
  15. var oldSpan = Span;
  16. _capacity = Math.Max(4, _capacity * 2);
  17. _items = Allocators.References.Allocate<LiveInterval>((uint)_capacity);
  18. var newSpan = Span;
  19. oldSpan.CopyTo(newSpan);
  20. }
  21. int position = interval.GetStart();
  22. int i = _count - 1;
  23. while (i >= 0 && _items[i].GetStart() > position)
  24. {
  25. _items[i + 1] = _items[i--];
  26. }
  27. _items[i + 1] = interval;
  28. _count++;
  29. }
  30. }
  31. }