mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-08-07 05:26:05 +00:00
The frozen dictionary is interesting, but not used enough in this code to justify the extra complexity.
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
namespace Symbols
|
namespace Symbols
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Frozen;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -17,8 +16,7 @@
|
|||||||
|
|
||||||
// Section -> Unique ID list of dictionary entries
|
// Section -> Unique ID list of dictionary entries
|
||||||
// Being sorted allows us to verify IDs as they arrive
|
// Being sorted allows us to verify IDs as they arrive
|
||||||
private readonly Dictionary<string, SortedDictionary<int, FrozenDictionary<string, string>>> _parsed_intermediate = [];
|
private readonly Dictionary<string, SortedDictionary<int, Dictionary<string, string>>> _parsed = [];
|
||||||
private FrozenDictionary<string, FrozenDictionary<int, FrozenDictionary<string, string>>>? _parsed;
|
|
||||||
|
|
||||||
private Version? _version;
|
private Version? _version;
|
||||||
private Information? _information;
|
private Information? _information;
|
||||||
@@ -308,12 +306,6 @@
|
|||||||
{
|
{
|
||||||
await this.ParseLinesAsync(reader);
|
await this.ParseLinesAsync(reader);
|
||||||
|
|
||||||
this.FreezeParsedData();
|
|
||||||
|
|
||||||
// Intermediate data no longer needed
|
|
||||||
// Only "frozen" parsed data is needed.
|
|
||||||
this._parsed_intermediate.Clear();
|
|
||||||
|
|
||||||
this.ExtractFiles();
|
this.ExtractFiles();
|
||||||
this.ExtractLines();
|
this.ExtractLines();
|
||||||
this.ExtractModules();
|
this.ExtractModules();
|
||||||
@@ -323,8 +315,8 @@
|
|||||||
this.ExtractSymbols();
|
this.ExtractSymbols();
|
||||||
this.ExtractTypes();
|
this.ExtractTypes();
|
||||||
|
|
||||||
// Frozen parsed data is no longer needed
|
// Parsed dictionary is no longer needed
|
||||||
this._parsed = null;
|
this._parsed.Clear();
|
||||||
|
|
||||||
// We are now mostly parsed
|
// We are now mostly parsed
|
||||||
this.Parsed = true;
|
this.Parsed = true;
|
||||||
@@ -347,16 +339,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FreezeParsedData()
|
|
||||||
{
|
|
||||||
var intermediateSections = new Dictionary<string, FrozenDictionary<int, FrozenDictionary<string, string>>>(this._parsed_intermediate.Count);
|
|
||||||
foreach (var (name, entries) in this._parsed_intermediate)
|
|
||||||
{
|
|
||||||
intermediateSections.Add(name, FrozenDictionary.ToFrozenDictionary(entries));
|
|
||||||
}
|
|
||||||
this._parsed = FrozenDictionary.ToFrozenDictionary(intermediateSections);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void BuildAddressableScopes()
|
private void BuildAddressableScopes()
|
||||||
{
|
{
|
||||||
if (!this.Parsed)
|
if (!this.Parsed)
|
||||||
@@ -393,10 +375,10 @@
|
|||||||
|
|
||||||
private void Parse(string key, string[] parts)
|
private void Parse(string key, string[] parts)
|
||||||
{
|
{
|
||||||
if (!this._parsed_intermediate.TryGetValue(key, out var section))
|
if (!this._parsed.TryGetValue(key, out var section))
|
||||||
{
|
{
|
||||||
this._parsed_intermediate[key] = [];
|
this._parsed[key] = [];
|
||||||
section = this._parsed_intermediate[key];
|
section = this._parsed[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
var dictionary = BuildDictionary(parts);
|
var dictionary = BuildDictionary(parts);
|
||||||
@@ -406,10 +388,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var identifier = int.Parse(id);
|
var identifier = int.Parse(id);
|
||||||
if (section.ContainsKey(identifier))
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"Invalid symbol file format (definition id ({identifier}) has clashed)");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._information == null)
|
if (this._information == null)
|
||||||
{
|
{
|
||||||
@@ -422,10 +400,13 @@
|
|||||||
throw new InvalidOperationException($"Invalid symbol file format (No count information available for {section})");
|
throw new InvalidOperationException($"Invalid symbol file format (No count information available for {section})");
|
||||||
}
|
}
|
||||||
|
|
||||||
section.Add(identifier, dictionary);
|
if (!section.TryAdd(identifier, dictionary))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Invalid symbol file format (definition id ({identifier}) has clashed)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FrozenDictionary<string, string> BuildDictionary(string[] parts)
|
private static Dictionary<string, string> BuildDictionary(string[] parts)
|
||||||
{
|
{
|
||||||
var dictionary = new Dictionary<string, string>(parts.Length);
|
var dictionary = new Dictionary<string, string>(parts.Length);
|
||||||
foreach (var part in parts)
|
foreach (var part in parts)
|
||||||
@@ -441,7 +422,7 @@
|
|||||||
dictionary[key] = value;
|
dictionary[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FrozenDictionary.ToFrozenDictionary(dictionary);
|
return dictionary;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user