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