From f10d0c8c2d826c136ea787c16cf016dab1aac4c2 Mon Sep 17 00:00:00 2001 From: xiezhengyao Date: Wed, 8 Jan 2025 16:14:27 +0800 Subject: [PATCH] perf: reduce make error cost of LinkBuffer.Until function --- nocopy_linkbuffer.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nocopy_linkbuffer.go b/nocopy_linkbuffer.go index a8c89755..89b13eb9 100644 --- a/nocopy_linkbuffer.go +++ b/nocopy_linkbuffer.go @@ -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{} @@ -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) }