summaryrefslogtreecommitdiffhomepage
path: root/pkg/buffer/view.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/buffer/view.go')
-rw-r--r--pkg/buffer/view.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/buffer/view.go b/pkg/buffer/view.go
index 7bcfcd543..a4610f977 100644
--- a/pkg/buffer/view.go
+++ b/pkg/buffer/view.go
@@ -378,6 +378,20 @@ func (v *View) Copy() (other View) {
return
}
+// Clone makes a more shallow copy compared to Copy. The underlying payload
+// slice (buffer.data) is shared but the buffers themselves are copied.
+func (v *View) Clone() *View {
+ other := &View{
+ size: v.size,
+ }
+ for buf := v.data.Front(); buf != nil; buf = buf.Next() {
+ newBuf := other.pool.getNoInit()
+ *newBuf = *buf
+ other.data.PushBack(newBuf)
+ }
+ return other
+}
+
// Apply applies the given function across all valid data.
func (v *View) Apply(fn func([]byte)) {
for buf := v.data.Front(); buf != nil; buf = buf.Next() {