Switch entirely to fast lookups. Around 10 times faster than original code!

This commit is contained in:
Adrian Conlon 2024-06-06 21:30:49 +01:00
parent 71ce8cde51
commit 0089bde117
9 changed files with 53 additions and 80 deletions

View File

@ -7,10 +7,9 @@
// file id=0,name="sudoku.s",size=9141,mtime=0x6027C7F0,mod=0
public class File : NamedSection
{
public int Size => this.TakeInteger("size");
public long ModificationTime => this.TakeLong("mtime");
public int Size { get; private set; }
public long ModificationTime { get; private set; }
public Symbols.Module Module => this.TakeModuleReference();
public File()
@ -19,6 +18,13 @@
_ = this._hex_long_keys.Add("mtime");
_ = this._integer_keys.Add("mod");
}
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
this.Size = this.TakeInteger("size");
this.ModificationTime = this.TakeLong("mtime");
}
}
}
}

View File

@ -1,6 +1,4 @@
#define FAST_ID_LOOKUP
namespace EightBit
namespace EightBit
{
namespace Files
{
@ -8,21 +6,14 @@ namespace EightBit
{
public class IdentifiableSection : Section
{
#if FAST_ID_LOOKUP
public int ID { get; private set; }
#else
public int ID => this.TakeInteger("id");
#endif
protected IdentifiableSection() => _ = this._integer_keys.Add("id");
#if FAST_ID_LOOKUP
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
this.ID = this.TakeInteger("id");
}
#endif
#region Foreign key constraints

View File

@ -9,12 +9,10 @@
{
public Symbols.File File => this.TakeFileReference();
public int LineNumber => this.TakeInteger("line");
public int LineNumber { get; private set; }
public Symbols.Type Type => this.TakeTypeReference();
public int Count => this.TakeInteger("count");
public int? Count { get; private set; }
public List<Span> Spans => this.TakeSpanReferences();
public Line()
@ -25,6 +23,13 @@
_ = this._integer_keys.Add("count");
_ = this._multiple_keys.Add("span");
}
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
this.LineNumber = this.TakeInteger("line");
this.Count = this.MaybeTakeInteger("count");
}
}
}
}

View File

@ -1,6 +1,4 @@
#define FAST_NAME_LOOKUP
namespace EightBit
namespace EightBit
{
namespace Files
{
@ -8,21 +6,15 @@ namespace EightBit
{
public class NamedSection : IdentifiableSection
{
#if FAST_NAME_LOOKUP
public string? Name { get; private set; }
#else
public string Name => this.TakeString("name");
#endif
protected NamedSection() => _ = this._string_keys.Add("name");
#if FAST_NAME_LOOKUP
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
this.Name = this.TakeString("name");
}
#endif
}
}
}

View File

@ -1,7 +1,4 @@
#define BINARY_SCOPE_SEARCH
//#define LINEAR_SCOPE_SEARCH
namespace EightBit
namespace EightBit
{
namespace Files
{
@ -170,7 +167,6 @@ namespace EightBit
private static bool AddressContained(int address, Scope scope) => AddressContained(address, AddressRange(scope));
#if BINARY_SCOPE_SEARCH
private int LocateScope(int address)
{
var low = 0;
@ -205,27 +201,14 @@ namespace EightBit
// If we reach here, then element was not present
return -1;
}
#endif
public Scope? LookupScope(int address)
{
#if BINARY_SCOPE_SEARCH
var index = this.LocateScope(address);
return index == -1 ? null : this.AddressableScopes[index];
#endif
#if LINEAR_SCOPE_SEARCH
foreach (var scope in this.AddressableScopes)
{
if (AddressContained(address, scope))
{
return scope;
}
}
return null;
#endif
}
#endregion
#endregion
#region Scope evaluation
@ -253,7 +236,7 @@ namespace EightBit
{
var scope = scopes[i];
var name = scope.Name;
Debug.Assert(name.Length > 0);
Debug.Assert(!string.IsNullOrEmpty(name));
returned += name;
var last = i == 0;
if (!last)
@ -272,6 +255,7 @@ namespace EightBit
}
var prefix = BuildNamespace(symbol);
var name = symbol.Name;
Debug.Assert(!string.IsNullOrEmpty(name));
return string.IsNullOrEmpty(prefix) ? name : $"{prefix}.{name}";
}
@ -297,7 +281,7 @@ namespace EightBit
#endregion
#endregion
#endregion
#region Metadata lookup

View File

@ -1,7 +1,4 @@
#define FAST_SYMBOL_LOOKUP
#define FAST_SIZE_LOOKUP
namespace EightBit
namespace EightBit
{
namespace Files
{
@ -13,18 +10,12 @@ namespace EightBit
public class Scope : NamedSection
{
public Symbols.Module Module => this.TakeModuleReference();
public string? Type => this.MaybeTakeString("type");
#if FAST_SIZE_LOOKUP
public int Size;
#else
public int Size => this.TakeInteger("size");
#endif
public int Size { get; private set; }
public Scope? Parent => this.MaybeTakeParentReference();
#if FAST_SYMBOL_LOOKUP
private bool _symbolAvailable;
private Symbols.Symbol? _symbol;
public Symbols.Symbol? Symbol
@ -39,9 +30,6 @@ namespace EightBit
return this._symbol;
}
}
#else
public Symbols.Symbol? Symbol => this.MaybeTakeSymbolReference();
#endif
public List<Span> Spans => this.TakeSpanReferences();
public Scope()
@ -54,14 +42,11 @@ namespace EightBit
_ = this._multiple_keys.Add("span");
}
#if FAST_SIZE_LOOKUP
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
this.Size = this.TakeInteger("size");
}
#endif
}
}
}

View File

@ -7,12 +7,12 @@
// seg id=1,name="RODATA",start=0x00F471,size=0x0000,addrsize=absolute,type=ro,oname="sudoku.65b",ooffs=1137
public class Segment : NamedSection
{
public int Start => this.TakeInteger("start");
public int Size => this.TakeInteger("size");
public int Start { get; private set; }
public int Size { get; private set; }
public string AddressSize => this.TakeString("addrsize");
public string Type => this.TakeString("type");
public string OName => this.TakeString("oname");
public int OOFFS => this.TakeInteger("ooffs"); // ?? Offsets, perhaps?
public int? OOFFS { get; private set; } // ?? Offsets, perhaps?
public Segment()
{
@ -23,6 +23,14 @@
_ = this._string_keys.Add("oname");
_ = this._integer_keys.Add("ooffs");
}
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
this.Start = this.TakeInteger("start");
this.Size = this.TakeInteger("size");
this.OOFFS = this.MaybeTakeInteger("ooffs");
}
}
}
}

View File

@ -8,8 +8,8 @@
public class Span : IdentifiableSection
{
public Symbols.Segment Segment => this.TakeSegmentReference();
public int Start => this.TakeInteger("start");
public int Size => this.TakeInteger("size");
public int Start { get; private set; }
public int Size { get; private set; }
public Symbols.Type Type => this.TakeTypeReference();
public Span()
@ -19,6 +19,13 @@
_ = this._integer_keys.Add("size");
_ = this._integer_keys.Add("type");
}
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
this.Start = this.TakeInteger("start");
this.Size = this.TakeInteger("size");
}
}
}
}

View File

@ -1,6 +1,4 @@
#define FAST_VALUE_LOOKUP
namespace EightBit
namespace EightBit
{
namespace Files
{
@ -13,7 +11,7 @@ namespace EightBit
{
public string AddressSize => this.TakeString("addrsize");
public int Size => this.TakeInteger("size");
public int? Size { get; private set; }
public Symbols.Scope Scope => this.TakeScopeReference();
@ -21,11 +19,7 @@ namespace EightBit
public List<Line> References => this.TakeLineReferences("ref"); // Guess
#if FAST_VALUE_LOOKUP
public int Value;
#else
public int Value => this.TakeInteger("val");
#endif
public int Value { get; private set; }
public Symbols.Segment Segment => this.TakeSegmentReference();
@ -46,9 +40,10 @@ namespace EightBit
public override void Parse(Parser parent, Dictionary<string, string> entries)
{
base.Parse(parent, entries);
#if FAST_VALUE_LOOKUP
this.Value = this.TakeInteger("val");
#endif
this.Size = this.MaybeTakeInteger("size");
if (this.Type is "lab")
{
this._parent?.AddLabel(this);