mirror of
https://github.com/fumiama/orbyte.git
synced 2026-06-05 02:00:30 +08:00
fix(pbuf): involve or parse judgement on slice
This commit is contained in:
5
item.go
5
item.go
@@ -58,6 +58,11 @@ func (b *Item[T]) Trans() (tb *Item[T]) {
|
||||
return tb
|
||||
}
|
||||
|
||||
// HasInvolved whether this item is buffered.
|
||||
func (b *Item[T]) HasInvolved() bool {
|
||||
return b.stat.isbuffered()
|
||||
}
|
||||
|
||||
// IsTrans whether this item has been marked as trans.
|
||||
func (b *Item[T]) IsTrans() bool {
|
||||
return b.stat.isintrans()
|
||||
|
||||
@@ -87,7 +87,10 @@ 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:]...)
|
||||
if b.buf.HasInvolved() {
|
||||
return InvolveBytes(b.dat[from:]...)
|
||||
}
|
||||
return ParseBytes(b.dat[from:]...)
|
||||
}
|
||||
nb := b.Ref()
|
||||
skip(nb.buf.Pointer(), from)
|
||||
@@ -98,7 +101,10 @@ 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]...)
|
||||
if b.buf.HasInvolved() {
|
||||
return InvolveBytes(b.dat[:to]...)
|
||||
}
|
||||
return ParseBytes(b.dat[:to]...)
|
||||
}
|
||||
nb := b.Ref()
|
||||
nb.buf.Pointer().Truncate(to)
|
||||
@@ -109,7 +115,10 @@ 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]...)
|
||||
if b.buf.HasInvolved() {
|
||||
return InvolveBytes(b.dat[from:to]...)
|
||||
}
|
||||
return ParseBytes(b.dat[from:to]...)
|
||||
}
|
||||
nb := b.Ref()
|
||||
buf := nb.buf.Pointer()
|
||||
|
||||
Reference in New Issue
Block a user