Skip to content

Commit

Permalink
Fix writing the same node (by ref)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jan 21, 2024
1 parent 17f3cf9 commit aa1ffaf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/BymlLibrary/Writers/BymlNodeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public class BymlNodeCache

public int this[Byml node] {
set {
if (_hashes.ContainsKey(node)) {
// If the node address already exists
// then it will match the cached node
return;
}

if (!_storage.TryGetValue(node.Type, out var buckets)) {
_storage[node.Type] = buckets = [
new() {
Expand All @@ -25,11 +31,11 @@ public int this[Byml node] {
// If the colliding node matches
// leave it as is
if (Byml.ValueEqualityComparer.Default.Equals(node, buckets[index][value].Node)) {
goto Update;
goto Inject;
}
}

Update:
Inject:
_hashes.Add(node, (value, index));
}
}
Expand Down

0 comments on commit aa1ffaf

Please sign in to comment.