@@ -18,6 +18,15 @@ import Foundation
18
18
/// exposed to clients.
19
19
typealias NodeIdentifier = [ Int ]
20
20
21
+ /// Box a value type into a reference type
22
+ fileprivate class Box < T> {
23
+ let value : T
24
+
25
+ init ( _ value: T ) {
26
+ self . value = value
27
+ }
28
+ }
29
+
21
30
/// SyntaxData is the underlying storage for each Syntax node.
22
31
/// It's modelled as an array that stores and caches a SyntaxData for each raw
23
32
/// syntax node in its layout. It is up to the specific Syntax nodes to maintain
@@ -38,7 +47,7 @@ final class SyntaxData: Equatable {
38
47
39
48
let childCaches : [ AtomicCache < SyntaxData > ]
40
49
41
- let positionCache : AtomicCache < AbsolutePosition >
50
+ private let positionCache : AtomicCache < Box < AbsolutePosition > >
42
51
43
52
fileprivate func calculatePosition( ) -> AbsolutePosition {
44
53
guard let parent = parent else {
@@ -62,7 +71,7 @@ final class SyntaxData: Equatable {
62
71
63
72
/// The position of the start of this node's leading trivia
64
73
var position : AbsolutePosition {
65
- return positionCache. value { return calculatePosition ( ) }
74
+ return positionCache. value ( { return Box ( calculatePosition ( ) ) } ) . value
66
75
}
67
76
68
77
/// The position of the start of this node's content, skipping its trivia
@@ -93,7 +102,7 @@ final class SyntaxData: Equatable {
93
102
self . indexInParent = indexInParent
94
103
self . parent = parent
95
104
self . childCaches = raw. layout. map { _ in AtomicCache < SyntaxData > ( ) }
96
- self . positionCache = AtomicCache < AbsolutePosition > ( )
105
+ self . positionCache = AtomicCache < Box < AbsolutePosition > > ( )
97
106
}
98
107
99
108
/// The index path from this node to the root. This can be used to uniquely
0 commit comments