Skip to content

Commit

Permalink
perf: reduce make error cost of LinkBuffer.Until function (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie authored Jan 8, 2025
1 parent 3aac0cb commit 53e3080
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nocopy_linkbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const BinaryInplaceThreshold = block4k
// LinkBufferCap that can be modified marks the minimum value of each node of LinkBuffer.
var LinkBufferCap = block4k

var untilErr = errors.New("link buffer read slice cannot find delim")

var (
_ Reader = &LinkBuffer{}
_ Writer = &LinkBuffer{}
Expand Down Expand Up @@ -309,7 +311,7 @@ func (b *UnsafeLinkBuffer) ReadByte() (p byte, err error) {
func (b *UnsafeLinkBuffer) Until(delim byte) (line []byte, err error) {
n := b.indexByte(delim, 0)
if n < 0 {
return nil, fmt.Errorf("link buffer read slice cannot find: '%b'", delim)
return nil, untilErr
}
return b.Next(n + 1)
}
Expand Down

0 comments on commit 53e3080

Please sign in to comment.