Skip to content

Commit 0a32e3e

Browse files
committed
Slice creates Buffer with minimal internal byte slice.
1 parent 7cd54d2 commit 0a32e3e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

buffer_slice.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ func (buf *Buffer) Slice(start, end int) *Buffer {
2727
return &Buffer{}
2828
}
2929
off := buf.off + start
30-
return &Buffer{b: buf.b[off>>3:], nBits: end - start, off: off & 7}
30+
return &Buffer{
31+
b: buf.b[off>>3 : (buf.off+end+7)>>3],
32+
nBits: end - start,
33+
off: off & 7,
34+
}
3135
}
3236

3337
// SliceToEnd is shorthand for Slice(start, buf.Len()) and returns the subpart

0 commit comments

Comments
 (0)