Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Adora Lynch committed Nov 27, 2024
1 parent f030158 commit c7e3959
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions Sources/Yams/AliasDereferencingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@
/// distinct anchors in the YAML document). In some scenarios this may significantly reduce the memory footprint of
/// the decoded type.
public protocol AliasDereferencingStrategy: AnyObject {

typealias Value = (any Decodable)
/// get and set cached references, keyed bo an Anchor
subscript(_ key: Anchor) -> Any? { get set }
subscript(_ key: Anchor) -> Value? { get set }
}

/// A AliasDereferencingStrategy which caches all values (even value-type values) in a Dictionary, keyed by their Anchor.
/// A AliasDereferencingStrategy which caches all values (even value-type values) in a Dictionary,
/// keyed by their Anchor.
/// For reference types, this strategy achieves reference coalescing
/// For value types, this strategy achieves short-cutting the decoding process when dereferencing aliases.
/// if the aliased structure is large, this may result in a time savings
public class BasicAliasDereferencingStrategy: AliasDereferencingStrategy {
/// Create a new BasicAliasDereferencingStrategy
public init() {}

private var map: [Anchor: Any] = .init()
private var map: [Anchor: Value] = .init()

/// get and set cached references, keyed bo an Anchor
public subscript(_ key: Anchor) -> Any? {
public subscript(_ key: Anchor) -> Value? {
get { map[key] }
set { map[key] = newValue }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Yams/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ extension _Decoder: SingleValueDecodingContainer {
return existing
}

private func recordAnchor<T>(_ constructed: T) {
private func recordAnchor<T: Decodable>(_ constructed: T) {
guard let anchor = self.node.anchor else {
return
}
Expand Down

0 comments on commit c7e3959

Please sign in to comment.