MCPcopy Create free account
hub / github.com/cloudwego/netpoll / indexByte

Method indexByte

nocopy_linkbuffer.go:752–781  ·  view source on GitHub ↗

indexByte returns the index of the first instance of c in buffer, or -1 if c is not present in buffer.

(c byte, skip int)

Source from the content-addressed store, hash-verified

750
751// indexByte returns the index of the first instance of c in buffer, or -1 if c is not present in buffer.
752func (b *UnsafeLinkBuffer) indexByte(c byte, skip int) int {
753 size := b.Len()
754 if skip >= size {
755 return -1
756 }
757 var unread, n, l int
758 node := b.read
759 for unread = size; unread > 0; unread -= n {
760 l = node.Len()
761 if l >= unread { // last node
762 n = unread
763 } else { // read full node
764 n = l
765 }
766
767 // skip current node
768 if skip >= n {
769 skip -= n
770 node = node.next
771 continue
772 }
773 i := bytes.IndexByte(node.Peek(n)[skip:], c)
774 if i >= 0 {
775 return (size - unread) + skip + i // past_read + skip_read + index
776 }
777 skip = 0 // no skip bytes
778 node = node.next
779 }
780 return -1
781}
782
783// ------------------------------------------ private function ------------------------------------------
784

Callers 3

UntilMethod · 0.95
TestLinkBufferIndexByteFunction · 0.45
UntilMethod · 0.45

Calls 3

LenMethod · 0.95
LenMethod · 0.65
PeekMethod · 0.65

Tested by 1

TestLinkBufferIndexByteFunction · 0.36