@@ -65,6 +65,13 @@ func NewSchemaProxy(schema *low.NodeReference[*base.SchemaProxy]) *SchemaProxy {
65
65
return & SchemaProxy {schema : schema , lock : & sync.Mutex {}}
66
66
}
67
67
68
+ // copySchemaWithParentProxy creates a shallow copy of a schema and sets the ParentProxy
69
+ func (sp * SchemaProxy ) copySchemaWithParentProxy (schema * Schema ) * Schema {
70
+ schemaCopy := * schema
71
+ schemaCopy .ParentProxy = sp
72
+ return & schemaCopy
73
+ }
74
+
68
75
// CreateSchemaProxy will create a new high-level SchemaProxy from a high-level Schema, this acts the same
69
76
// as if the SchemaProxy is pre-rendered.
70
77
func CreateSchemaProxy (schema * Schema ) * SchemaProxy {
@@ -116,11 +123,7 @@ func (sp *SchemaProxy) Schema() *Schema {
116
123
loc := fmt .Sprintf ("%s:%d:%d" , idx .GetSpecAbsolutePath (), sp .schema .GetValueNode ().Line , sp .schema .GetValueNode ().Column )
117
124
if seen , ok := idx .GetHighCache ().Load (loc ); ok {
118
125
idx .HighCacheHit ()
119
- // Create a copy of the cached schema with the correct ParentProxy
120
- cachedSchema := seen .(* Schema )
121
- schemaCopy := * cachedSchema // shallow copy
122
- schemaCopy .ParentProxy = sp
123
- return & schemaCopy
126
+ return sp .copySchemaWithParentProxy (seen .(* Schema ))
124
127
} else {
125
128
idx .HighCacheMiss ()
126
129
}
@@ -148,11 +151,8 @@ func (sp *SchemaProxy) Schema() *Schema {
148
151
}
149
152
}
150
153
151
- // Create a copy of the schema to avoid race conditions when setting ParentProxy
152
- schemaCopy := * sch // shallow copy
153
- schemaCopy .ParentProxy = sp
154
- sp .rendered = & schemaCopy
155
- return & schemaCopy
154
+ sp .rendered = sp .copySchemaWithParentProxy (sch )
155
+ return sp .rendered
156
156
}
157
157
158
158
// IsReference returns true if the SchemaProxy is a reference to another Schema.
0 commit comments