Clone creates a copy-on-write clone of b. The underlying chunks are shared until they are written to.
()
| 410 | // Clone creates a copy-on-write clone of b. The underlying chunks are shared |
| 411 | // until they are written to. |
| 412 | func (b *Buffer) Clone() Buffer { |
| 413 | other := Buffer{ |
| 414 | size: b.size, |
| 415 | } |
| 416 | for v := b.data.Front(); v != nil; v = v.Next() { |
| 417 | newView := v.Clone() |
| 418 | other.data.PushBack(newView) |
| 419 | } |
| 420 | return other |
| 421 | } |
| 422 | |
| 423 | // DeepClone creates a deep clone of b, copying data such that no bytes are |
| 424 | // shared with any other Buffers. |