Some performance updates

This commit is contained in:
Adrian Conlon
2025-10-13 17:36:32 +01:00
parent ceacac4741
commit 33fce45cc8
3 changed files with 33 additions and 10 deletions

View File

@@ -4,21 +4,43 @@
namespace EightBit
{
public sealed class MemoryMapping(Memory memory, ushort begin, ushort mask, AccessLevel access)
public sealed class MemoryMapping
{
public MemoryMapping(Memory memory, ushort begin, ushort mask, AccessLevel access)
{
this._memory = memory;
this._begin = begin;
this._mask = mask;
this._access = access;
for (int i = ushort.MinValue; i < ushort.MaxValue + 1; ++i)
{
System.Diagnostics.Debug.Assert(i >= ushort.MinValue);
System.Diagnostics.Debug.Assert(i <= ushort.MaxValue);
this._offsets[i] = this.CalculateOffset((ushort)i);
}
}
public MemoryMapping(Memory memory, ushort begin, Mask mask, AccessLevel access)
: this(memory, begin, (ushort)mask, access)
{
}
public Memory Memory { get; set; } = memory;
private readonly int[] _offsets = new int[ushort.MaxValue + 1];
private readonly Memory _memory;
private readonly ushort _begin;
private readonly ushort _mask;
private readonly AccessLevel _access;
public ushort Begin { get; set; } = begin;
public Memory Memory => this._memory;
public ushort Mask { get; set; } = mask;
public ushort Begin => this._begin;
public AccessLevel Access { get; set; } = access;
public ushort Mask => this._mask;
public int Offset(ushort absolute) => (absolute - this.Begin) & this.Mask;
public AccessLevel Access => this._access;
private int CalculateOffset(ushort absolute) => (absolute - this.Begin) & this.Mask;
public int Offset(ushort absolute) => this._offsets[absolute];
}
}