1
0
mirror of https://github.com/fumiama/orbyte.git synced 2026-06-12 14:10:53 +08:00

fix(pbuf): involve or parse judgement on slice

This commit is contained in:
源文雨
2025-02-26 00:05:52 +09:00
parent 717b07486e
commit 190281785c
2 changed files with 17 additions and 3 deletions

View File

@@ -58,6 +58,11 @@ func (b *Item[T]) Trans() (tb *Item[T]) {
return tb 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. // IsTrans whether this item has been marked as trans.
func (b *Item[T]) IsTrans() bool { func (b *Item[T]) IsTrans() bool {
return b.stat.isintrans() return b.stat.isintrans()

View File

@@ -87,7 +87,10 @@ func (b Bytes) Copy() (cb Bytes) {
// SliceFrom dat[from:] with Ref. // SliceFrom dat[from:] with Ref.
func (b Bytes) SliceFrom(from int) Bytes { func (b Bytes) SliceFrom(from int) Bytes {
if b.buf.IsTrans() { 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() nb := b.Ref()
skip(nb.buf.Pointer(), from) skip(nb.buf.Pointer(), from)
@@ -98,7 +101,10 @@ func (b Bytes) SliceFrom(from int) Bytes {
// SliceTo dat[:to] with Ref. // SliceTo dat[:to] with Ref.
func (b Bytes) SliceTo(to int) Bytes { func (b Bytes) SliceTo(to int) Bytes {
if b.buf.IsTrans() { 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 := b.Ref()
nb.buf.Pointer().Truncate(to) nb.buf.Pointer().Truncate(to)
@@ -109,7 +115,10 @@ func (b Bytes) SliceTo(to int) Bytes {
// Slice dat[from:to] with Ref. // Slice dat[from:to] with Ref.
func (b Bytes) Slice(from, to int) Bytes { func (b Bytes) Slice(from, to int) Bytes {
if b.buf.IsTrans() { 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() nb := b.Ref()
buf := nb.buf.Pointer() buf := nb.buf.Pointer()