From 34fb59eea053cdf0a65f67b1b1f755aa64b37477 Mon Sep 17 00:00:00 2001 From: Adrian Conlon <98398945+AdrianConlon@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:32:58 +0100 Subject: [PATCH] Simplify addresable scope building --- M6502/M6502.Symbols/Parser.cs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/M6502/M6502.Symbols/Parser.cs b/M6502/M6502.Symbols/Parser.cs index dd62ee9..dcf1c76 100644 --- a/M6502/M6502.Symbols/Parser.cs +++ b/M6502/M6502.Symbols/Parser.cs @@ -37,27 +37,13 @@ public List Types = []; + // Symbol sub-types public IEnumerable Labels => this.SelectSymbolsByType("lab"); public IEnumerable Equates => this.SelectSymbolsByType("equ"); // Scope clarification - private List? _addressableScopes; - - public List AddressableScopes - { - get - { - if (_addressableScopes == null) - { - var scopes = from scope in this.Scopes where scope.Symbol != null select scope; - this._addressableScopes = []; - this._addressableScopes.AddRange(scopes); - } - - return this._addressableScopes; - } - } + public List AddressableScopes = []; // Scope cache for precomputed ranges private readonly int?[] _scopeAddressCache = new int?[0x10000]; @@ -295,8 +281,6 @@ #endregion - #region Reference extractors - private void ExtractReferences() { foreach (var entry in this.SectionEntries) @@ -306,7 +290,11 @@ } } - #endregion + private void BuildAddressableScopes() + { + var scopes = from scope in this.Scopes where scope.Symbol != null select scope; + this.AddressableScopes.AddRange(scopes); + } #region Parser driver @@ -322,6 +310,7 @@ this.ExtractSections(); this.ExtractReferences(); + this.BuildAddressableScopes(); } private async Task ParseAsync(StreamReader reader)