aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Common
diff options
context:
space:
mode:
Diffstat (limited to 'ARMeilleure/Common')
-rw-r--r--ARMeilleure/Common/BitMap.cs14
-rw-r--r--ARMeilleure/Common/SortedIntegerList.cs73
2 files changed, 10 insertions, 77 deletions
diff --git a/ARMeilleure/Common/BitMap.cs b/ARMeilleure/Common/BitMap.cs
index 4872c442..27ef031f 100644
--- a/ARMeilleure/Common/BitMap.cs
+++ b/ARMeilleure/Common/BitMap.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
+using System.Runtime.CompilerServices;
namespace ARMeilleure.Common
{
@@ -170,12 +171,12 @@ namespace ARMeilleure.Common
public struct Enumerator : IEnumerator<int>
{
- private int _index;
+ private long _index;
private long _mask;
private int _bit;
private readonly BitMap _map;
- public int Current => _index * IntSize + _bit;
+ public int Current => (int)_index * IntSize + _bit;
object IEnumerator.Current => Current;
public Enumerator(BitMap map)
@@ -186,6 +187,7 @@ namespace ARMeilleure.Common
_map = map;
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext()
{
if (_mask != 0)
@@ -193,14 +195,18 @@ namespace ARMeilleure.Common
_mask &= ~(1L << _bit);
}
+ // Manually hoist these loads, because RyuJIT does not.
+ long count = (uint)_map._count;
+ long* masks = _map._masks;
+
while (_mask == 0)
{
- if (++_index >= _map._count)
+ if (++_index >= count)
{
return false;
}
- _mask = _map._masks[_index];
+ _mask = masks[_index];
}
_bit = BitOperations.TrailingZeroCount(_mask);
diff --git a/ARMeilleure/Common/SortedIntegerList.cs b/ARMeilleure/Common/SortedIntegerList.cs
deleted file mode 100644
index cceab62b..00000000
--- a/ARMeilleure/Common/SortedIntegerList.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace ARMeilleure.Common
-{
- public class SortedIntegerList
- {
- private List<int> _items;
-
- public int Count => _items.Count;
-
- public int this[int index]
- {
- get
- {
- return _items[index];
- }
- set
- {
- _items[index] = value;
- }
- }
-
- public SortedIntegerList()
- {
- _items = new List<int>();
- }
-
- public bool Add(int value)
- {
- if (_items.Count == 0 || value > Last())
- {
- _items.Add(value);
- return true;
- }
- else
- {
- int index = _items.BinarySearch(value);
- if (index >= 0)
- {
- return false;
- }
-
- _items.Insert(-1 - index, value);
- return true;
- }
- }
-
- public int FindLessEqualIndex(int value)
- {
- int index = _items.BinarySearch(value);
- return (index < 0) ? (-2 - index) : index;
- }
-
- public void RemoveRange(int index, int count)
- {
- if (count > 0)
- {
- _items.RemoveRange(index, count);
- }
- }
-
- public int Last()
- {
- return _items[Count - 1];
- }
-
- public List<int> GetList()
- {
- return _items;
- }
- }
-}