| 1 |
// Copyright 2023 Huan Du. All rights reserved. |
| 2 |
// Licensed under the MIT license that can be found in the LICENSE file. |
| 3 |
|
| 4 |
package clone |
| 5 |
|
| 6 |
// Cloner implements clone API with given allocator. |
| 7 |
type Cloner struct { |
| 8 |
allocator *Allocator |
| 9 |
} |
| 10 |
|
| 11 |
// MakeCloner creates a cloner with given allocator. |
| 12 |
func MakeCloner(allocator *Allocator) Cloner { |
| 13 |
return Cloner{ |
| 14 |
allocator: allocator, |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
// Clone clones v with given allocator. |
| 19 |
func (c Cloner) Clone(v interface{}) interface{} { |
| 20 |
return clone(c.allocator, v) |
| 21 |
} |
| 22 |
|
| 23 |
// CloneSlowly clones v with given allocator. |
| 24 |
// It can clone v with cycle pointer. |
| 25 |
func (c Cloner) CloneSlowly(v interface{}) interface{} { |
| 26 |
return cloneSlowly(c.allocator, v) |
| 27 |
} |