Skip to content

Commit 5f6d4fe

Browse files
authored
Merge pull request #56 from Basekick-Labs/perf/hasnilcode-inline
perf(decode): inline hasNilCode for byte-slice reader
2 parents ba9f557 + 7d8f420 commit 5f6d4fe

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

decode.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ func (d *Decoder) ReadFull(buf []byte) error {
624624
}
625625

626626
func (d *Decoder) hasNilCode() bool {
627+
// Fast path: when decoding from a byte slice, peek directly
628+
// to avoid two interface method calls (ReadByte + UnreadByte).
629+
if d.s == &d.bsr {
630+
return d.bsr.pos < len(d.bsr.data) && d.bsr.data[d.bsr.pos] == msgpcode.Nil
631+
}
627632
code, err := d.PeekCode()
628633
return err == nil && code == msgpcode.Nil
629634
}

0 commit comments

Comments
 (0)