@@ -124,13 +124,6 @@ final class RawSyntax {
124
124
}
125
125
} ) . value
126
126
}
127
-
128
- /// Creates a copy of `other`.
129
- init ( _ other: RawSyntax ) {
130
- self . data = other. data
131
- self . presence = other. presence
132
- self . id = other. id
133
- }
134
127
135
128
init ( kind: SyntaxKind , layout: [ RawSyntax ? ] , presence: SourcePresence ,
136
129
id: SyntaxNodeId ? = nil ) {
@@ -341,7 +334,17 @@ extension RawSyntax {
341
334
}
342
335
}
343
336
344
- extension RawSyntax : Codable {
337
+ // This is needed purely to have a self assignment initializer for
338
+ // RawSyntax.init(from:Decoder) so we can reuse omitted nodes, instead of
339
+ // copying them.
340
+ private protocol _RawSyntaxFactory { }
341
+ extension _RawSyntaxFactory {
342
+ init ( _instance: Self ) {
343
+ self = _instance
344
+ }
345
+ }
346
+
347
+ extension RawSyntax : Codable , _RawSyntaxFactory {
345
348
/// Creates a RawSyntax from the provided Foundation Decoder.
346
349
convenience init ( from decoder: Decoder ) throws {
347
350
let container = try decoder. container ( keyedBy: CodingKeys . self)
@@ -359,7 +362,7 @@ extension RawSyntax: Codable {
359
362
guard let lookupNode = lookupFunc ( id) else {
360
363
throw IncrementalDecodingError . nodeLookupFailed ( id)
361
364
}
362
- self . init ( lookupNode)
365
+ self . init ( _instance : lookupNode)
363
366
return
364
367
}
365
368
0 commit comments