Skip to content

Commit c26273c

Browse files
Alexander Zielenskialexzielenski
authored andcommitted
add CopyInto method to schema.Schema
1 parent 73412af commit c26273c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

schema/elements.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,25 @@ func (s *Schema) Resolve(tr TypeRef) (Atom, bool) {
259259
}
260260
return tr.Inlined, true
261261
}
262+
263+
// Clones this instance of Schema into the other
264+
// If other is nil this method does nothing.
265+
// If other is already initialized, overwrites it with this instance
266+
// Warning: Not thread safe
267+
func (s Schema) CopyInto(dst *Schema) {
268+
if dst == nil {
269+
return
270+
}
271+
272+
// Schema type is considered immutable so sharing references
273+
dst.Types = s.Types
274+
275+
if s.m != nil {
276+
// If cache is non-nil then the once token had been consumed.
277+
// Must reset token and use it again to ensure same semantics.
278+
dst.once = sync.Once{}
279+
dst.once.Do(func() {
280+
dst.m = s.m
281+
})
282+
}
283+
}

0 commit comments

Comments
 (0)