mirror of
https://github.com/fumiama/orbyte.git
synced 2026-06-07 11:10:28 +08:00
fix(pbuf): bytes slice trans
This commit is contained in:
@@ -94,6 +94,9 @@ func (b Bytes) Copy() (cb Bytes) {
|
||||
|
||||
// SliceFrom dat[from:] with Ref.
|
||||
func (b Bytes) SliceFrom(from int) Bytes {
|
||||
if b.buf.IsTrans() {
|
||||
return InvolveBytes(b.dat[from:]...)
|
||||
}
|
||||
nb := b.Ref()
|
||||
nb.dat = b.dat[from:]
|
||||
return nb
|
||||
@@ -101,6 +104,9 @@ func (b Bytes) SliceFrom(from int) Bytes {
|
||||
|
||||
// SliceTo dat[:to] with Ref.
|
||||
func (b Bytes) SliceTo(to int) Bytes {
|
||||
if b.buf.IsTrans() {
|
||||
return InvolveBytes(b.dat[:to]...)
|
||||
}
|
||||
nb := b.Ref()
|
||||
nb.dat = b.dat[:to]
|
||||
return nb
|
||||
@@ -108,6 +114,9 @@ func (b Bytes) SliceTo(to int) Bytes {
|
||||
|
||||
// Slice dat[from:to] with Ref.
|
||||
func (b Bytes) Slice(from, to int) Bytes {
|
||||
if b.buf.IsTrans() {
|
||||
return InvolveBytes(b.dat[from:to]...)
|
||||
}
|
||||
nb := b.Ref()
|
||||
nb.dat = b.dat[from:to]
|
||||
return nb
|
||||
|
||||
@@ -10,7 +10,7 @@ func TestBytes(t *testing.T) {
|
||||
for i := 0; i < 4096; i++ {
|
||||
b := NewBytes(i)
|
||||
rand.Read(b.Bytes())
|
||||
b.Destroy()
|
||||
b.Trans().SliceFrom(0).SliceTo(i).Destroy()
|
||||
}
|
||||
runtime.GC()
|
||||
out, in := bufferPool.p.CountItems()
|
||||
|
||||
Reference in New Issue
Block a user