Deduplicate disassembly imports

This commit is contained in:
Yoshi Askharoun
2024-02-07 09:42:18 -06:00
parent e18d3ebdd7
commit 9e8ffe786b
+5 -8
View File
@@ -19,16 +19,14 @@ public class Disassembler
public IEnumerable<IImport> GetImports() public IEnumerable<IImport> GetImports()
{ {
// Keep track of which namespaces have already been imported,
// and skip self and default UIX namespace
HashSet<string> importedUris = [_loadResult.Uri, "http://schemas.microsoft.com/2007/uix"];
foreach (var typeImport in _loadResult.ImportTables.TypeImports) foreach (var typeImport in _loadResult.ImportTables.TypeImports)
{ {
var uri = typeImport.Owner.Uri; var uri = typeImport.Owner.Uri;
if (importedUris.Contains(uri))
// Skip default UIX namespace
if (uri == "http://schemas.microsoft.com/2007/uix")
continue;
// Skip self
if (uri == _loadResult.Uri)
continue; continue;
string name = uri; string name = uri;
@@ -61,7 +59,6 @@ public class Disassembler
var reader = _loadResult.ObjectSection; var reader = _loadResult.ObjectSection;
// Insert a label to mark the start of the object section. // Insert a label to mark the start of the object section.
// In the future, this might use a special directive like `.section object`
yield return new SectionDirective("object"); yield return new SectionDirective("object");
while (reader.CurrentOffset < reader.Size) while (reader.CurrentOffset < reader.Size)