Improve symbol/span access speeds

This commit is contained in:
Adrian Conlon
2024-09-17 10:54:22 +01:00
parent de309e90db
commit a2b3427b5c
3 changed files with 20 additions and 9 deletions

View File

@@ -15,8 +15,7 @@
public bool Parsed { get; private set; }
// Section -> Unique ID list of dictionary entries
// Being sorted allows us to verify IDs as they arrive
private readonly Dictionary<string, SortedDictionary<int, Dictionary<string, string>>> _parsed = [];
private readonly Dictionary<string, List<Dictionary<string, string>>> _parsed = [];
private Version? _version;
private Information? _information;
@@ -271,14 +270,17 @@
Debug.Assert(into.Count == 0);
into.Capacity = parsed.Count;
foreach (var (id, information) in parsed)
for (var id = 0; id < parsed.Count; ++id)
{
Debug.Assert(into.Count == id);
var entry = (T?)Activator.CreateInstance(typeof(T), this);
Debug.Assert(entry != null);
var information = parsed[id];
entry.Parse(information);
into.Add(entry);
}
Debug.Assert(into.Count == parsed.Count);
this.VerifyInformationCount(key, into.Count);
}
@@ -400,10 +402,7 @@
throw new InvalidOperationException($"Invalid symbol file format (No count information available for {section})");
}
if (!section.TryAdd(identifier, dictionary))
{
throw new InvalidOperationException($"Invalid symbol file format (definition id ({identifier}) has clashed)");
}
section.Add(dictionary);
}
private static Dictionary<string, string> BuildDictionary(string[] parts)

View File

@@ -16,7 +16,7 @@
public string? Type => this.MaybeTakeString("type");
[SectionProperty("size")]
public int Size => this.TakeInteger("size");
public int Size { get; private set; }
[SectionReference("parent")]
public Scope? Parent => this.MaybeTakeParentReference();
@@ -40,6 +40,12 @@
[SectionReferences("span")]
public List<Span> Spans => this.TakeSpanReferences();
public override void Parse(IDictionary<string, string> entries)
{
base.Parse(entries);
this.Size = this.TakeInteger("size");
}
}
}
}

View File

@@ -25,13 +25,19 @@
public List<Line> References => this.TakeLineReferences("ref"); // Guess
[SectionProperty("val", hexadecimal: true)]
public int Value => this.TakeInteger("val");
public int Value { get; private set; }
[SectionReference("seg")]
public Symbols.Segment Segment => this.TakeSegmentReference();
[SectionEnumeration("type")]
public string Type => this.TakeString("type");
public override void Parse(IDictionary<string, string> entries)
{
base.Parse(entries);
this.Value = this.TakeInteger("val");
}
}
}
}