Some code simplifications

This commit is contained in:
Adrian Conlon 2024-06-12 16:36:54 +01:00
parent ef8f9f476b
commit 30f8b8a600
3 changed files with 7 additions and 19 deletions

View File

@ -132,10 +132,8 @@ namespace EightBit
protected void LoadHexFile(string path)
{
using var file = new IntelHexFile(path);
foreach (var chunk in file.Parse())
foreach (var (address, content) in file.Parse())
{
var address = chunk.Item1;
var content = chunk.Item2;
var mapped = this.Mapping(address);
var offset = address - mapped.Begin;
mapped.Memory.Load(content, offset);

View File

@ -302,11 +302,9 @@
Debug.Assert(into.Count == 0);
into.Capacity = parsed.Count;
foreach (var element in parsed)
foreach (var (id, information) in parsed)
{
var id = element.Key;
Debug.Assert(into.Count == id);
var information = element.Value;
var entry = new T();
entry.Parse(this, information);
into.Add(entry);

View File

@ -4,11 +4,11 @@
public sealed class Profiler
{
private readonly int[] instructionCounts;
private readonly int[] addressProfiles;
private readonly int[] addressCounts;
private readonly int[] instructionCounts = new int[0x100];
private readonly int[] addressProfiles = new int[0x10000];
private readonly int[] addressCounts = new int[0x10000];
private readonly Dictionary<string, int> scopeCycles;
private readonly Dictionary<string, int> scopeCycles = [];
private readonly M6502 processor;
private readonly Disassembler disassembler;
@ -31,12 +31,6 @@
this.processor.RaisingSYNC += this.Processor_RaisingSYNC;
this.processor.ExecutedInstruction += this.Processor_ExecutedInstruction;
}
this.instructionCounts = new int[0x100];
this.addressProfiles = new int[0x10000];
this.addressCounts = new int[0x10000];
this.scopeCycles = [];
}
public event EventHandler<EventArgs>? StartingOutput;
@ -100,11 +94,9 @@
this.OnStartingScopeOutput();
try
{
foreach (var scopeCycle in this.scopeCycles)
foreach (var (name, cycles) in this.scopeCycles)
{
var name = scopeCycle.Key;
Debug.Assert(name != null);
var cycles = scopeCycle.Value;
var symbol = this.symbols.LookupLabel(name);
Debug.Assert(symbol != null);
var count = this.addressCounts[symbol.Value];